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

Boylan, Ross Ross.Boylan at ucsf.edu
Sat Nov 15 03:59:59 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.

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.