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

Herbert Voss Herbert.Voss at FU-Berlin.DE
Sat Nov 15 19:32:03 CET 2014


Am 15.11.2014 um 03:59 schrieb Boylan, Ross:
> 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.

Us a  \newif instead:

\documentclass{article}
\newif\ifblahblah \blahblahfalse
\newcommand\testit{Random text.
  \ifblahblah
    I have already spoken.%
  \else
    I speak at length.\global\blahblahtrue
  \fi}

\begin{document}

\begingroup
\testit
\endgroup

\testit

\testit
\end{document}


Herbert


More information about the texhax mailing list