ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] imposition: getting to the last page of a booklet
@ 2024-02-23  9:07 Michael Guravage
  2024-02-24 13:30 ` [NTG-context] " Wolfgang Schuster
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Guravage @ 2024-02-23  9:07 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 365 bytes --]

Greetings,

I would like to use the nextquadruple and beforequadruple pagebreakhandlers
described at the bottom of the wiki's imposition page. However, the
examples complain of an error invoking the  \installpagebreakhandler
command.

The wiki page was last updated nearly four years ago. Is anyone using
updated versions of these?

-- 
With kind regards,

Michael

[-- Attachment #1.2: Type: text/html, Size: 659 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-23  9:07 [NTG-context] imposition: getting to the last page of a booklet Michael Guravage
@ 2024-02-24 13:30 ` Wolfgang Schuster
  2024-02-27 10:13   ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 13+ messages in thread
From: Wolfgang Schuster @ 2024-02-24 13:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Michael Guravage

Michael Guravage schrieb am 23.02.2024 um 10:07:
> Greetings,
>
> I would like to use the nextquadruple and beforequadruple 
> pagebreakhandlers described at the bottom of the wiki's imposition 
> page. However, the examples complain of an error invoking the 
> \installpagebreakhandler command.
>
> The wiki page was last updated nearly four years ago. Is anyone using 
> updated versions of these?

You can use quadruple out of the box.

\setuppagenumbering[alternative={singlesided,doublesided}]

\starttext

\samplefile{lorem}

\page[quadruple]

\samplefile{lorem}

\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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-24 13:30 ` [NTG-context] " Wolfgang Schuster
@ 2024-02-27 10:13   ` Pablo Rodriguez via ntg-context
  2024-02-28 10:56     ` Bruce Horrocks
  0 siblings, 1 reply; 13+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-27 10:13 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 2/24/24 14:30, Wolfgang Schuster wrote:
> Michael Guravage schrieb am 23.02.2024 um 10:07:
>> Greetings,
>>
>> I would like to use the nextquadruple and beforequadruple
>> pagebreakhandlers described at the bottom of the wiki's imposition
>> page. However, the examples complain of an error invoking the
>> \installpagebreakhandler command.
>>
>> The wiki page was last updated nearly four years ago. Is anyone using
>> updated versions of these?
>
> You can use quadruple out of the box.

Hi Wolfgang,

I’m also interested a solution for this.

I’m afraid I cannot make your sample work:

  \setuppapersize[A5][A4, landscape]
  \setuparranging[2UP]
  \setuppagenumbering[alternative={singlesided,doublesided}]

  \starttext
  \samplefile{lorem}
  \page[quadruple]
  page before the quadruple (must be 3, not 4)
  \page[yes, quadruple]
  page before the quadruple (must be 7, not 8)
  \stoptext

I haven’t tested what
"\setuppagenumbering[alternative={singlesided,doublesided}]" would cause
in my documents.

In any case, I get real quadruple, not before the quadruple.

What am I missing here?

Many thanks for your help,

Pablo
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-27 10:13   ` Pablo Rodriguez via ntg-context
@ 2024-02-28 10:56     ` Bruce Horrocks
  2024-02-28 11:24       ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 13+ messages in thread
From: Bruce Horrocks @ 2024-02-28 10:56 UTC (permalink / raw)
  To: ntg-context mailing list; +Cc: Pablo Rodriguez



> On 27 Feb 2024, at 10:13, Pablo Rodriguez via ntg-context <ntg-context@ntg.nl> wrote:
> 
> I’m afraid I cannot make your sample work:


The sample works for me if you set plain A4 and doublesided, thus:

 \setuppagenumbering[alternative={doublesided}]
 \starttext
 \samplefile{lorem}
 \page[quadruple]
 page before the quadruple (must be 3, not 4)
 \page[yes, quadruple]
 page before the quadruple (must be 7, not 8)
 \stoptext

This puts the "page before quadruple" text on page 4 which is the last side of the first four sides, if that makes sense.

Switching to singlesided seems to confuse it - issuing only two sides in total so maybe that was part of the problem since both are specified in your original example?

—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-28 10:56     ` Bruce Horrocks
@ 2024-02-28 11:24       ` Pablo Rodriguez via ntg-context
  2024-02-28 18:02         ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 13+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-28 11:24 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 2/28/24 11:56, Bruce Horrocks wrote:
> [...]
> The sample works for me if you set plain A4 and doublesided, thus:
>
>  \setuppagenumbering[alternative={doublesided}]
>  \starttext
>  \samplefile{lorem}
>  \page[quadruple]
>  page before the quadruple (must be 3, not 4)
>  \page[yes, quadruple]
>  page before the quadruple (must be 7, not 8)
>  \stoptext
>
> This puts the "page before quadruple" text on page 4 which is the
> last side of the first four sides, if that makes sense.

Many thanks for your reply, Bruce.

\page[quadruple] works fine putting content on realpage numbers that can
be divided by 4 (with modulo 0).

As far as I get, Michael was looking to place content on realpage
numbers get modulo 3 when divided by 4.

At least, this is what would fit my needs to place the imprint on the
(excuse the Latin adjective [before the last]) penultima page of a booklet.

This is why beforequadruple would make sense. I guess some Lua magic
could do that, computing x to the follwing page that "x % 4 = 3" (and
then \page[x]).

I will try to find a trick for that, but not now.

Many thanks for your help,

Pablo
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-28 11:24       ` Pablo Rodriguez via ntg-context
@ 2024-02-28 18:02         ` Pablo Rodriguez via ntg-context
  2024-02-28 18:28           ` Wolfgang Schuster
  0 siblings, 1 reply; 13+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-02-28 18:02 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 2/28/24 12:24, Pablo Rodriguez via ntg-context wrote:
> [...]
> This is why beforequadruple would make sense. I guess some Lua magic
> could do that, computing x to the follwing page that "x % 4 = 3" (and
> then \page[x]).
>
> I will try to find a trick for that, but not now.

Replying to myself, this is a command to compute next numbers before and
after quadruples (with application to \realpageno):

 \starttext
  \def\beforequadruplenumber#1%
    {\ifnum\modulonumber{4}{#1} = 1
       \the\numexpr #1 + 2
     \orelse\ifnum\modulonumber{4}{#1} = 2
       \the\numexpr #1 + 1
     \orelse\ifnum\modulonumber{4}{#1} = 3
       \the\numexpr #1 + 4
      \else
       \the\numexpr #1 + 3
     \fi}

  \def\afterquadruplenumber#1%
    {\ifnum\modulonumber{4}{#1} = 1
       \the\numexpr #1 + 4
     \orelse\ifnum\modulonumber{4}{#1} = 2
       \the\numexpr #1 + 3
     \orelse\ifnum\modulonumber{4}{#1} = 3
       \the\numexpr #1 + 2
      \else
       \the\numexpr #1 +1
     \fi}

  \dorecurse{25}{\recurselevel: \beforequadruplenumber{\recurselevel}\\}
  \dorecurse{25}{\recurselevel: \afterquadruplenumber{\recurselevel}\\}

  %\page[123]
  %\null
  \page[\beforequadruplenumber{\realpageno}]
  before quadruple
  \page[\afterquadruplenumber{\realpageno}]
  afterquadruple
  \stoptext

Michael, if this fits your needs, please add it to the wiki.

I hope it helps,

Pablo
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-28 18:02         ` Pablo Rodriguez via ntg-context
@ 2024-02-28 18:28           ` Wolfgang Schuster
  2024-03-04 19:00             ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 13+ messages in thread
From: Wolfgang Schuster @ 2024-02-28 18:28 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez via ntg-context
  Cc: Pablo Rodriguez

Pablo Rodriguez via ntg-context schrieb am 28.02.2024 um 19:02:
> On 2/28/24 12:24, Pablo Rodriguez via ntg-context wrote:
>> [...]
>> This is why beforequadruple would make sense. I guess some Lua magic
>> could do that, computing x to the follwing page that "x % 4 = 3" (and
>> then \page[x]).
>>
>> I will try to find a trick for that, but not now.
> 
> Replying to myself, this is a command to compute next numbers before and
> after quadruples (with application to \realpageno):
> 
>   \starttext
>    \def\beforequadruplenumber#1%
>      {\ifnum\modulonumber{4}{#1} = 1
>         \the\numexpr #1 + 2
>       \orelse\ifnum\modulonumber{4}{#1} = 2
>         \the\numexpr #1 + 1
>       \orelse\ifnum\modulonumber{4}{#1} = 3
>         \the\numexpr #1 + 4
>        \else
>         \the\numexpr #1 + 3
>       \fi}

\def\beforequadruplenumber#1%
   {\ifcase\numexpr#1+1;4\relax
      \number\numexpr#1+4\relax
    \else
      \number\numexpr#1+3-#1;4\relax
    \fi}

>    \def\afterquadruplenumber#1%
>      {\ifnum\modulonumber{4}{#1} = 1
>         \the\numexpr #1 + 4
>       \orelse\ifnum\modulonumber{4}{#1} = 2
>         \the\numexpr #1 + 3
>       \orelse\ifnum\modulonumber{4}{#1} = 3
>         \the\numexpr #1 + 2
>        \else
>         \the\numexpr #1 +1
>       \fi}

\def\afterquadruplenumber#1%
   {\ifcase\numexpr#1;4\relax
      \number\numexpr#1+1\relax
    \else
      \number\numexpr#1+5-#1;4\relax
    \fi}

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-02-28 18:28           ` Wolfgang Schuster
@ 2024-03-04 19:00             ` Pablo Rodriguez via ntg-context
  2024-03-06 18:50               ` Wolfgang Schuster
  0 siblings, 1 reply; 13+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-03-04 19:00 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

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 semicolon is also mysterious to me, I don’t know what it does there
in plain language.

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?

Sorry for asking that. I’m afraid this would be the only way I could get
what \ifcase is doing there.

BTW, neither your command, nor mine work in my real world document. But
this would be another issue.

Many thanks for your help,

Pablo
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-03-04 19:00             ` Pablo Rodriguez via ntg-context
@ 2024-03-06 18:50               ` Wolfgang Schuster
  2024-03-06 19:17                 ` Pablo Rodriguez via ntg-context
  2024-03-06 20:38                 ` Hans Hagen
  0 siblings, 2 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2024-03-06 18:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez via ntg-context
  Cc: Pablo Rodriguez

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

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-03-06 18:50               ` Wolfgang Schuster
@ 2024-03-06 19:17                 ` Pablo Rodriguez via ntg-context
  2024-03-07 15:36                   ` Wolfgang Schuster
  2024-03-06 20:38                 ` Hans Hagen
  1 sibling, 1 reply; 13+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-03-06 19:17 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

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.

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

Many thanks for your help,

Pablo

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-03-06 18:50               ` Wolfgang Schuster
  2024-03-06 19:17                 ` Pablo Rodriguez via ntg-context
@ 2024-03-06 20:38                 ` Hans Hagen
  2024-03-06 21:06                   ` Wolfgang Schuster
  1 sibling, 1 reply; 13+ messages in thread
From: Hans Hagen @ 2024-03-06 20:38 UTC (permalink / raw)
  To: ntg-context

On 3/6/2024 7:50 PM, Wolfgang Schuster wrote:

> The semicolon is a undocumented extension (I noticed it in the 
> definition of \page[quadruple]) of \numexpr in Luametatex for the 
> modulus operator.

One of these days I have to write the pending section in th elow level 
manual and also explain this:

\starttext
     \ifnum  10  = 11 wrong \else okay  \fi
     \ifnum  10 != 11 okay  \else wrong \fi
     \ifnum  10 !> 11 okay  \else wrong \fi
     \ifnum  10 !< 11 wrong \else okay  \fi
     \ifnum  10 ≤  11 okay  \else wrong \fi
     \ifnum  10 ≥  11 wrong \else okay  \fi
     \ifnum  10 ≰  11 okay  \else wrong \fi
     \ifnum  10 ≱  11 wrong \else okay  \fi
     \ifnum "F0 ∈ "F0 okay  \else wrong \fi
     \ifnum "F0 ∉ "F0 wrong \else okay  \fi
\stoptext

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-03-06 20:38                 ` Hans Hagen
@ 2024-03-06 21:06                   ` Wolfgang Schuster
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2024-03-06 21:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hans Hagen schrieb am 06.03.2024 um 21:38:
> On 3/6/2024 7:50 PM, Wolfgang Schuster wrote:
>
>> The semicolon is a undocumented extension (I noticed it in the 
>> definition of \page[quadruple]) of \numexpr in Luametatex for the 
>> modulus operator.
>
> One of these days I have to write the pending section in th elow level 
> manual and also explain this:
>
> \starttext
>     \ifnum  10  = 11 wrong \else okay  \fi
>     \ifnum  10 != 11 okay  \else wrong \fi
>     \ifnum  10 !> 11 okay  \else wrong \fi
>     \ifnum  10 !< 11 wrong \else okay  \fi
>     \ifnum  10 ≤  11 okay  \else wrong \fi
>     \ifnum  10 ≥  11 wrong \else okay  \fi
>     \ifnum  10 ≰  11 okay  \else wrong \fi
>     \ifnum  10 ≱  11 wrong \else okay  \fi
>     \ifnum "F0 ∈ "F0 okay  \else wrong \fi
>     \ifnum "F0 ∉ "F0 wrong \else okay  \fi
> \stoptext

These new features are mentioned in the Luametatex manual but not the 
additions to \numexpr (I checked and : is mentioned but ; is missing).

\starttext

\startlines
\number\numexpr 5 + 2 \relax
\number\numexpr 5 - 2 \relax
\number\numexpr 5 * 2 \relax
\number\numexpr 5 / 2 \relax
\number\numexpr 5 : 2 \relax % new!
\number\numexpr 5 ; 2 \relax % new!
\stoplines

\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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [NTG-context] Re: imposition: getting to the last page of a booklet
  2024-03-06 19:17                 ` Pablo Rodriguez via ntg-context
@ 2024-03-07 15:36                   ` Wolfgang Schuster
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Schuster @ 2024-03-07 15:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez via ntg-context
  Cc: Pablo Rodriguez

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-07 15:39 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23  9:07 [NTG-context] imposition: getting to the last page of a booklet Michael Guravage
2024-02-24 13:30 ` [NTG-context] " Wolfgang Schuster
2024-02-27 10:13   ` Pablo Rodriguez via ntg-context
2024-02-28 10:56     ` Bruce Horrocks
2024-02-28 11:24       ` Pablo Rodriguez via ntg-context
2024-02-28 18:02         ` Pablo Rodriguez via ntg-context
2024-02-28 18:28           ` Wolfgang Schuster
2024-03-04 19:00             ` Pablo Rodriguez via ntg-context
2024-03-06 18:50               ` Wolfgang Schuster
2024-03-06 19:17                 ` Pablo Rodriguez via ntg-context
2024-03-07 15:36                   ` Wolfgang Schuster
2024-03-06 20:38                 ` Hans Hagen
2024-03-06 21:06                   ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).