Pablo Rodriguez via ntg-context schrieb am 04.03.2024 um 20:00:
On 2/28/24 19:28, Wolfgang Schuster wrote:
[...] \def\beforequadruplenumber#1% {\ifcase\numexpr#1+1;4\relax \number\numexpr#1+4\relax \else \number\numexpr#1+3-#1;4\relax \fi}
Sorry for not having answered before, Wolfgang.
I’m afraid I don’t get how \ifcase is deployed with as conditional (being \ifcase used to give numbers for weekdays or months).
The \ifcase command is the TeX version of a switch statement from other programming languages. The first case in \ifcase checks against zero which is shorter than writing "\ifnum ... = 0".
The semicolon is also mysterious to me, I don’t know what it does there in plain language.
The semicolon is a undocumented extension (I noticed it in the definition of \page[quadruple]) of \numexpr in Luametatex for the modulus operator.
Sorry, I know it has to be simple, but the syntax is too cryptic for me.
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.
Sorry for asking that. I’m afraid this would be the only way I could get what \ifcase is doing there.
As was mentioned above I used it as a check when the remainder was 0. %%%% begin example \startluacode --~ interfaces.implement { --~ name = "beforequadruplenumber", --~ arguments = "integer", --~ actions = function(n) --~ if n % 4 == 0 then --~ context(n + 3) --~ elseif n % 4 == 1 then --~ context(n + 2) --~ elseif n % 4 == 2 then --~ context(n + 1) --~ elseif n % 4 == 3 then --~ context(n + 4) --~ end --~ end --~ } --~ interfaces.implement { --~ name = "beforequadruplenumber", --~ arguments = "integer", --~ actions = function(n) --~ if (n + 1) % 4 == 0 then --~ context(n + 4) --~ else --~ context(n + 3 - n % 4) --~ end --~ end --~ } interfaces.implement { name = "beforequadruplenumber", arguments = "integer", actions = function(n) context(n + (((n + 1) % 4 == 0) and 4 or (3 - n % 4))) end } --~ interfaces.implement { --~ name = "afterquadruplenumber", --~ arguments = "integer", --~ actions = function(n) --~ if n % 4 == 0 then --~ context(n + 1) --~ elseif n % 4 == 1 then --~ context(n + 4) --~ elseif n % 4 == 2 then --~ context(n + 3) --~ elseif n % 4 == 3 then --~ context(n + 2) --~ end --~ end --~ } --~ interfaces.implement { --~ name = "afterquadruplenumber", --~ arguments = "integer", --~ actions = function(n) --~ if n % 4 == 0 then --~ context(n + 1) --~ else --~ context(n + 5 - n % 4) --~ end --~ end --~ } interfaces.implement { name = "afterquadruplenumber", arguments = "integer", actions = function(n) context(n + ((n % 4 == 0) and 1 or (5 - n % 4))) end } \stopluacode \unprotect \def\beforequadruplenumber#1{\clf_beforequadruplenumber\numexpr#1\relax} \def\afterquadruplenumber #1{\clf_afterquadruplenumber \numexpr#1\relax} \protect \starttext \dorecurse{20}{\recurselevel\space = \beforequadruplenumber{\recurselevel}\par}\page \dorecurse{20}{\recurselevel\space = \afterquadruplenumber {\recurselevel}\par} \stoptext %%%% end example Wolfgang