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

Boylan, Ross Ross.Boylan at ucsf.edu
Sat Nov 15 23:56:01 CET 2014


I did a minimalist version of David's suggestion, relying on the fact that the internals of the ifthen package go through \ifX for boolean X, and this can be globally reset with \global\let.  

Would it have been better to use counters?  I just needed something global I could toggle.
A quick check shows that latex counters are also updated globally using, e.g. \stepcounter.

I suppose even more minimally I could have done
\let\ifblah\iffalse
\newcommand{\testit}{\ifblah later time \else first time\global\let\ifblah\iftrue\fi}

New version:
\documentclass{article}
\usepackage{ifthen}

\newcommand{\testit}{Random text.
\ifthenelse{\boolean{blahblah}}{I have already spoken.}{I speak at
  length.\global\let\ifblahblah \iftrue}}

\begin{document}
\newboolean{blahblah}
\begingroup
\testit
\endgroup

\testit

\testit
\end{document}

P.S. Since the tex input is generated programmatically, I suppose I could have given the macro an argument indicating whether it was the first invocation and supplied that from my program.  It seemed like something that would be easy to do in latex.



More information about the texhax mailing list