[NTG-context] How to let a macro check the previous value of #1 the last time the same macro was called?
Wolfgang Schuster
wolfgang.schuster.lists at gmail.com
Mon Jan 10 20:21:54 CET 2022
Henning Hraban Ramm via ntg-context schrieb am 10.01.2022 um 09:52:
> Am 09.01.22 um 16:03 schrieb Wolfgang Schuster via ntg-context:
>> Joel via ntg-context schrieb am 09.01.2022 um 15:16:
>>> Is there a way for a macro to check the previous value of #1, the
>>> last time that same macro was called?
>>
>> To check is the current value differs from the last one you need a
>> temp macro where you store the current value at the end of your
>> command to check it in the next call.
>
> Would it make more sense, or would it be “cleaner” to use a variable?
You can get rid of the temp variable before the command definition but
now you have to access it with a different method in \mymacro, below is
one way (LMTX only) but \setvariable and \getvariable work as well.
\define[1]\mymacro
{\iftok{#1}{\getvalue{previousmymacro}}%
same as last time
\else
it is different from last time
\fi
\setvalue{previousmymacro}{#1}}
Wolfgang
More information about the ntg-context
mailing list