[texhax] getting to global scope from within a group (latex/ifthen)

bnb at ams.org bnb at ams.org
Sat Nov 15 16:44:48 CET 2014


    I'm trying to define a macro that behaves differently the first time its used compared to later uses.  But I tend to use the macro inside of blocks, and so the changes I make don't last until the next time I invoke the macro.

    How can I get around this?

    I know \outer works for plain TeX definitions, but I'm updating some symbol buried inside latex macros, in this case the \setboolean macro is resetting something.

\setboolean is defined in the ifthen package.
making a setting global (you've identified
the need for this in the subject line) is
what is required.

there's no reference to "global" in the
documentation for ifthen (texdoc ifthen,
if you're using a distribution based on
tex live), but the author is david carlisle,
who should be sympathetic to a request for
such en enhancement to the package.

since his address doesn't appear in the
documentation, and i don't know whether
he follows this list, i'll forward the
suggestion to him, because i think it's
a good idea.

    Here's a little example.  Because the first \testit is inside a group, the second \testit acts as if it is being invoked for the first time.  My actual useage is buried in several layers of macros and environments.
    
    \documentclass{article}
    \usepackage{ifthen}
    
    \newcommand{\testit}{Random text.
    \ifthenelse{\boolean{blahblah}}{I have already spoken.}{I speak at length.\setboolean{blahblah}{true}}}
    
    \begin{document}
    \newboolean{blahblah}
    \begingroup
    \testit
    \endgroup
    
    \testit
    
    \testit
    \end{document}
    
    Thanks.
    Ross Boylan
    
    P.S. I'm using \begingroup so I can issue \centering to center a table within a float.  Is there a better way to center the table?  The beginning and end of the table are produced by different macros.

\centering is better here than
\begin{center} ... \end{center}.
						-- bb



More information about the texhax mailing list