Pablo Rodriguez via ntg-context schrieb am 06.03.2024 um 20:17:
On 3/6/24 19:50, Wolfgang Schuster wrote:
Could you write the first line in plain language?

Look at the second example of the Lua code in the example below for each
command (the first example is your version), the third example is just a
condensed version of example 2.

Many thanks for your extended explanation, Wolfgang.

Here is another solution which uses \ifcase the select a different case dependent on the value of the remainder.

     \the\numexpr#1+3\relax % remainder = 0
     \the\numexpr#1+2\relax % remainder = 1
     \the\numexpr#1+1\relax % remainder = 2
     \the\numexpr#1+4\relax % remainder = 3

     \the\numexpr#1+1\relax % remainder = 0
     \the\numexpr#1+4\relax % remainder = 1
     \the\numexpr#1+3\relax % remainder = 2
     \the\numexpr#1+2\relax % remainder = 3

Now it is clearer to me (although I need some time to learn from it).

When you use \numexpr to perform arithmetic in TeX it is recommended to add a final \relax to stop the command from scanning to additional values, e.g. in the example below \testone takes value beyond the argument because \numexpr hasn't ended yet.


\def\testone#1{\the\numexpr #1 + 1 }

\testone{1} + 1

\def\testtwo#1{\the\numexpr #1 + 1 \relax}

\testtwo{1} + 1


If your question is of interest to others as well, please add an entry to the 

maillist : /
webpage  : / (mirror)
archive  :
wiki     :

Reply via email to