2

I have the following:

\documentclass{article}

\usepackage{amsmath} \usepackage{witharrows}

\begin{document}

\def\var{x}

[ \begin{WithArrows} \var\var&=\def\var{y}\var\var\ \var \end{WithArrows} ]

\end{document}

I wanted to change the \var value to y but it only works for the \var immediatly after the \def and on that line.

The result of the compilation is:

enter image description here

And I'm wondering why the \var on the second line is not affected by the instruction above.

Concept7
  • 645
  • What would be the reason for the redefinition? – egreg Jul 21 '20 at 17:14
  • @egreg I'm thinking about exercises where you need a change in variable (like solving limits) – Concept7 Jul 21 '20 at 20:21
  • So losing track of what is what? I'm not sure how this can be helpful. – egreg Jul 21 '20 at 20:40
  • @egreg it's understandable that you are not sure how it can be helpful but I am, that's good enough for me. Thank you. – Concept7 Jul 21 '20 at 21:02
  • @egreg I now see your point and you are correct! I made an exercise resolution and sent it to a friend in a .tex file and he had a lot of difficulties editing it because of commands I used... I still think the idea is good to send the finished product but if I plan on ever sending the .tex it would be problematic. Sorry for being harsh in my previous comment. – Concept7 Jul 22 '20 at 09:43

1 Answers1

2

Change \def to \gdef, to make the definition global. Inside the environment, each subline is its own group, so the \def does not carry over outside of it.

\documentclass{article}

\usepackage{amsmath} \usepackage{witharrows}

\begin{document}

\def\var{x}

[ \begin{WithArrows} \var\var&=\gdef\var{y}\var\var\ \var \end{WithArrows} ]

\end{document}

enter image description here