[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
Sun Jan 9 16:03:54 CET 2022


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?
> 
> Here is a minimum working example, pretending that `\previousvalue` is 
> equal to #1 from the last time the 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.

\let\previousmymacro\empty

\define[1]\mymacro
   {\edef\currentmymacro{#1}%
    \ifx\previousmymacro\currentmymacro
      same as last time
    \else
      it is different from last time
    \fi
    \let\previousmymacro\currentmymacro}

\starttext

\startlines
cat: \mymacro{cat}
cat: \mymacro{cat}
mouse: \mymacro{mouse}
mouse: \mymacro{mouse}
cat: \mymacro{cat}
\stoplines

\stoptext

Wolfgang



More information about the ntg-context mailing list