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.
\def\beforequadruplenumber#1%
{\ifcase\numexpr#1;4\relax
\the\numexpr#1+3\relax % remainder = 0
\or
\the\numexpr#1+2\relax % remainder = 1
\or
\the\numexpr#1+1\relax % remainder = 2
\or
\the\numexpr#1+4\relax % remainder = 3
\fi}
\def\afterquadruplenumber#1%
{\ifcase\numexpr#1;4\relax
\the\numexpr#1+1\relax % remainder = 0
\or
\the\numexpr#1+4\relax % remainder = 1
\or
\the\numexpr#1+3\relax % remainder = 2
\or
\the\numexpr#1+2\relax % remainder = 3
\fi}
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.
\starttext
\def\testone#1{\the\numexpr #1 + 1 }
\testone{1} + 1
\def\testtwo#1{\the\numexpr #1 + 1 \relax}
\testtwo{1} + 1
\stoptext
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________