Generalsetting variables inside of \rlap

LaTeX specific issues not fitting into one of the other forums of this category.
Locked
steve6390
Posts: 16
Joined: Sat Nov 29, 2008 6:36 am

setting variables inside of \rlap

Post by steve6390 »

Hello!

Two questions about this code:
Why does rlap prevent me from setting a variable?
I need to set a variable from within rlap that is visible outside rlap, but how?

Code: Select all

\documentclass{article}
\newif\ifmycheck
\begin{document}
\rlap{\mychecktrue}
% \mychecktrue
\ifmycheck
Check 1 True!
\else
Check 1 False!   % always takes this path!
\fi
\end{document}
Thanks for any clues.
Regards,
-steve

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

setting variables inside of \rlap

Post by sommerfee »

Crosspost!

Matthew Leingang wrote there:

Changes within a group stay inside that group, and \rlap puts its argument inside an \hbox, therefore within its own group. So if you did:

Code: Select all

\rlap{\mychecktrue % group is still open!
% \mychecktrue
\ifmycheck
Check True!
\else
Check False!  
\fi}
You will get :"Check True!"

So you see that you did set the variable inside \rlap.

You want the changes to persist outside the group. So use the prefix \global:

Code: Select all

\rlap{\global\mychecktrue}
% \mychecktrue
\ifmycheck
Check True!
\else
Check False!  
\fi
That will result again in: "Check True!"
Last edited by Stefan Kottwitz on Fri Jan 08, 2016 12:39 pm, edited 1 time in total.
Locked