how do I get the correct page numbers and do the calculations with it?
Thank to all who answered my questions before. As the title suggests, how do I get the correct page numbers? For example, in the example below, the first line on the 2nd page, but the page number showed is 1, In the meantime, I tried using \definepagestate, but it didn't seem to work either. What I can think of is to use citations to get the correct page number. But it seems that what is obtained is not a pure number, and it cannot do the calculations. so ,how do I get the correct page numbers and do the calculations with it? thanks. %%%%%% start example \starttext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% try page state \definepagestate[test][delay=yes] \newcount\test \let\testfloatrealpage\realpageno \def\testsavedata {\setpagestate[test][\number\test]} \def\testloaddata % precedes save ! {\global\advance\test\plusone \xdef\testfloatrealpage{\pagestaterealpage{test}{\number\test}} \ifx\testfloatrealpage\empty \glet\testfloatrealpage\realpageno \fi} \testsavedata% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \dorecurse{10}{% \testloaddata% \input knuth \pagereference[XX:#1] {\ssd\color[red]{\the\pageno}}% on page 2 and show page 1 {\ssd\color[red]{\the\testfloatrealpage}}%on page 2 and show page 1 {\ssd\color[red]{\ref[page][XX:#1]}}% on page 2 and show page 2 } \stoptext % stop example Muyik
ai2472206007@yeah.net schrieb am 09.09.2024 um 09:57:
Thank to all who answered my questions before. As the title suggests, how do I get the correct page numbers? For example, in the example below, the first line on the 2nd page, but the page number showed is 1, In the meantime, I tried using \definepagestate, but it didn't seem to work either. What I can think of is to use citations to get the correct page number. But it seems that what is obtained is not a pure number, and it cannot do the calculations.
so ,how do I get the correct page numbers and do the calculations with it?
1. You save only 1 pagestate with index 0 but you try to access the data of the pagestates with index 1 to 10. 2. What do you try to achieve here? Wolfgang
1. The usage of the command "\definepagestate " is what I searched for in previous posts and source files. I don't know exactly how he used it. (╥﹏╥) 2. I've devised a command that needs to get the current page number to determine if it's an odd or even page. This is then used to get a certain width to determine the width of the command on that line. Below I designed the command. The code related to this issue is mainly %%% code related to this issue \rest@linewidth=\dimexpr% \ifdoublesided% if singlesided restlinewidth = oddpos - xpos \ifodd\pageno% if doublesided \oddpos@warichu% and if odd restlinewidth = oddpos - xpos \else\evenpos@warichu\fi% and if even restlinewidth = evenpos - xpos \else\oddpos@warichu \fi% -\MPx\xpos@warichu\relax% %%% %%%% main code \unprotect \installnamespace {warichu} \installsimplecommandhandler \????warichu {warichu} \????warichu \setupwarichu[style=\ssxx, voffset=-1.5pt, distance=\hskip1pt\relax, left={},right={}, reference=,] \newcount\cnt@warichu \newdimen\rest@linewidth \newdimen\oddpos@warichu \newdimen\evenpos@warichu \oddpos@warichu =\dimexpr\backspace+\textwidth\relax \evenpos@warichu=\dimexpr\paperwidth-\cutspace\relax \def\get@split@box#1{% \setbox\scratchboxone\hbox{% \hsplit\scratchbox % to #1% shrinkcriterium 10000% \par\allowbreak}% \box\scratchboxone} \def\warichu{\dosingleempty\warichu@indeed} \def\warichu@indeed[#1]#2{\begingroup% \global\advance\cnt@warichu by 1\relax% \iffirstargument\setupwarichu[#1]\fi% \warichuparameter{distance}% \warichuparameter{left}% \pagereference[warichu:\number\cnt@warichu]% may be useful \textreference[\warichuparameter{reference}]{\warichuparameter{reference}}% \xypos{warichu:\number\cnt@warichu}% \edef\xpos@warichu{warichu:\number\cnt@warichu}% \rest@linewidth=\dimexpr% \ifdoublesided% if singlesided restlinewidth = oddpos - xpos \ifodd\pageno% if doublesided \oddpos@warichu% and if odd restlinewidth = oddpos - xpos \else\evenpos@warichu\fi% and if even restlinewidth = evenpos - xpos \else\oddpos@warichu \fi% -\MPx\xpos@warichu\relax% \setbox\scratchbox\hbox{\usewarichustyleandcolor\c!style\c!color #2\relax}% \raise\warichuparameter{voffset}\relax% \vbox{\offinterlineskip% \get@split@box{\the\rest@linewidth}% \get@split@box{\the\rest@linewidth}}\allowbreak% \doloop{% \ifdim\wd\scratchbox>\dimexpr\textwidth*2\relax% \raise\warichuparameter{voffset}% \vbox{\offinterlineskip% \get@split@box{\the\textwidth}% \get@split@box{\the\textwidth}}\allowbreak% \else% \raise\warichuparameter{voffset}% \vbox{\offinterlineskip% \get@split@box{\dimexpr\wd\scratchbox/2+1pt\relax}% \get@split@box{\dimexpr\wd\scratchbox+1pt\relax}}\allowbreak% \exitloop% \fi}% \warichuparameter{right}% \warichuparameter{distance}\endgroup} \protect \starttext \section{} \input darwin \warichu[reference=warichu:44]{\input darwin \input knuth } \input knuthmath \warichu{\input knuth } \input knuth \stoptext %%%%
ai2472206007@yeah.net schrieb am 10.09.2024 um 06:05:
1. The usage of the command "\definepagestate " is what I searched for in previous posts and source files. I don't know exactly how he used it. (╥﹏╥)
2. I've devised a command that needs to get the current page number to determine if it's an odd or even page. This is then used to get a certain width to determine the width of the command on that line. Below I designed the command. The code related to this issue is mainly
You have to differentiate between odd and even and right hand and left hand pages. When you want to check whether you have an right hand or left hand page you can use the following method. To get the correct result ensure you start a paragraph before you set the flag with \signalrightpage. %%%% begin example %\setuppagenumbering[alternative=doublesided] %\setuppagenumbering[alternative={singlesided,doublesided}] \starttext \dorecurse{20} {\dontleavehmode\signalrightpage\doifelserightpage{\bold{Right page}}{\bold{Left page}} \samplefile{lorem}} \stoptext %%%% end example To have a check which works for odd and even pages you have to use the pagestate mechanism. Even in this case it is important to start a paragraph before save the current state, afterwards you can check the stored pagenumber. %%%% begin example \definepagestate[warichu] \starttext \dorecurse{20} {\dontleavehmode\autosetpagestate{warichu}% \ifodd0\autopagestaterealpage{warichu}% \bold{Odd page} \else \bold{Even page} \fi \samplefile{lorem}} \stoptext %%%% end example Wolfgang
ai2472206007@yeah.net schrieb am 10.09.2024 um 06:05:
1. The usage of the command "\definepagestate " is what I searched for in previous posts and source files. I don't know exactly how he used it. (╥﹏╥)
2. I've devised a command that needs to get the current page number to determine if it's an odd or even page. This is then used to get a certain width to determine the width of the command on that line. Below I designed the command. The code related to this issue is mainly
%%% code related to this issue \rest@linewidth=\dimexpr% \ifdoublesided% if singlesided restlinewidth = oddpos - xpos \ifodd\pageno% if doublesided \oddpos@warichu% and if odd restlinewidth = oddpos - xpos \else\evenpos@warichu\fi% and if even restlinewidth = evenpos - xpos \else\oddpos@warichu \fi% -\MPx\xpos@warichu\relax% %%%
%%%% main code \unprotect \installnamespace {warichu} \installsimplecommandhandler \????warichu {warichu} \????warichu \setupwarichu[style=\ssxx, voffset=-1.5pt, distance=\hskip1pt\relax, left={},right={}, reference=,]
There is no need to set empty default values \warichuparameter checks if there is value.
\newcount\cnt@warichu \newdimen\rest@linewidth \newdimen\oddpos@warichu \newdimen\evenpos@warichu
The current naming system for count and dimen register is - \c_xxx (e.g. \c_warichu_n) for counters and - \d_... (e.g. \d_warichu_odd) for dimensions. We also use underbar instead of @ to create internal commands names.
\oddpos@warichu =\dimexpr\backspace+\textwidth\relax \evenpos@warichu=\dimexpr\paperwidth-\cutspace\relax
You have to do these assignment in your \warichu command because now you use the current values for \textwidth etc. which is a problem when you create a module for your command. When you load the module the register for the odd and even values use whather was set for \textwidth etc. when you loaded the module. This means you have to always change the layout of the document before you load the module, otherwise the text width of the document can be different from the one used in your module to calculate both values.
\def\get@split@box#1{% \setbox\scratchboxone\hbox{% \hsplit\scratchbox % to #1% shrinkcriterium 10000% \par\allowbreak}% \box\scratchboxone} \def\warichu{\dosingleempty\warichu@indeed} \def\warichu@indeed[#1]#2{\begingroup%
You can drop the two-step definition for optional parameters when you use the \tolerant for the command definition. \tolerant\def\warichu[#1]#:#2% {...}
\global\advance\cnt@warichu by 1\relax%
You don't need % at the end when you end the line with a command (e.g. \relax).
\iffirstargument\setupwarichu[#1]\fi%
Change this to \ifparameter#1\or\setupwarichu[#1]\fi when you use \tolerant or drop the check for the optional parameter and just use \setupwarichu[#1]%
\warichuparameter{distance}%
I would change this to \hskip\warichuparameter\c!distance\relax and set the distance value as \setupwarichu[distance=1pt]
\warichuparameter{left}%
Can be changed to (no need for %) \warichuparameter\c!left
\pagereference[warichu:\number\cnt@warichu]% may be useful \textreference[\warichuparameter{reference}]{\warichuparameter{reference}}%
Do you need both references (what even is the purpose of \textreference here)? You should also add \dontleavehmode at the start of \warichu because references (and also the following \xypos) whould be part of a paragraph.
\xypos{warichu:\number\cnt@warichu}% \edef\xpos@warichu{warichu:\number\cnt@warichu}%
You can change the order of both lines: \edef\xpos@warichu{warichu:\number\c_warichu_n}% \xypos\xpos@warichu
\rest@linewidth=\dimexpr% \ifdoublesided% if singlesided restlinewidth = oddpos - xpos \ifodd\pageno% if doublesided \oddpos@warichu% and if odd restlinewidth = oddpos - xpos \else\evenpos@warichu\fi% and if even restlinewidth = evenpos - xpos \else\oddpos@warichu \fi% -\MPx\xpos@warichu\relax% \setbox\scratchbox\hbox{\usewarichustyleandcolor\c!style\c!color #2\relax}% \raise\warichuparameter{voffset}\relax% \vbox{\offinterlineskip% \get@split@box{\the\rest@linewidth}% \get@split@box{\the\rest@linewidth}}\allowbreak% \doloop{% \ifdim\wd\scratchbox>\dimexpr\textwidth*2\relax% \raise\warichuparameter{voffset}% \vbox{\offinterlineskip% \get@split@box{\the\textwidth}% \get@split@box{\the\textwidth}}\allowbreak% \else% \raise\warichuparameter{voffset}% \vbox{\offinterlineskip% \get@split@box{\dimexpr\wd\scratchbox/2+1pt\relax}% \get@split@box{\dimexpr\wd\scratchbox+1pt\relax}}\allowbreak% \exitloop% \fi}% \warichuparameter{right}% \warichuparameter{distance}\endgroup}
Wolfgang
Thank you for your careful and patient explanation. I'll check my code again. Because it's still very simple, and some situations haven't been taken into account. In particular, the condition judgment to split the part of the box. Regarding the part about referencing commands, I inadvertently forgot to delete it. I have a question about the command "\warichuparameter\c!XXX" : Why can we use "\warichuparameter\c!XXX" instead of "\warichuparameter{XXX}" in most cases, but in some cases, it says that the command is not defined? For example, \warichuparameter\c!pointstyle --> Control sequence expected instead of undefined I've used "\warichuparameter\c!XXX" before, but it causes the error because there are some keys that are specifically named. For the sake of stylistic consistency, I used "\warichuparameter{XXX}" for all command. Maybe it's because I didn't define it? Should I define the following in advance? %%% \def\c!pointstyle{pointstyle} %%%
ai2472206007@yeah.net schrieb am 11.09.2024 um 04:22:
Thank you for your careful and patient explanation. I'll check my code again. Because it's still very simple, and some situations haven't been taken into account. In particular, the condition judgment to split the part of the box.
I run your code and already found a few example where it fails, e.g. - when you have a very short text it is spread over the while line and you get a line break at the end - when you use it in the narrower environment you don't compensate the left/right indentations
Regarding the part about referencing commands, I inadvertently forgot to delete it.
I have a question about the command "\warichuparameter\c!XXX" : Why can we use "\warichuparameter\c!XXX" instead of "\warichuparameter{XXX}" in most cases, but in some cases, it says that the command is not defined? For example, \warichuparameter\c!pointstyle --> Control sequence expected instead of undefined
I've used "\warichuparameter\c!XXX" before, but it causes the error because there are some keys that are specifically named. For the sake of stylistic consistency, I used "\warichuparameter{XXX}" for all command.
Maybe it's because I didn't define it? Should I define the following in advance?
%%% \def\c!pointstyle{pointstyle} %%%
Yes, these constants are predefined to have language dependent keys in the setup command, e.g. \setupitemize[width=1cm] is written as \stelleaufzaehlungein[breite=1cm] with the german interface. To ensure you use the correct name for the key you use \c!width as argument for the \xxxparameter command. While you can use \def\c!...{...} to create a new constant the proper method is to use \setinterfaceconstant. You can run the following example to get a list with a predefined constant. When you uncomment the first three lines you see the new entry also appears in the list. %%%% begin example % \startinterface all % \setinterfaceconstant {pointstyle} {pointstyle} % \stopinterface \setuplayout[tight] \starttext \startluacode context.startcolumns({n=3}) for constant, _ in table.sortedpairs(interfaces.constants) do context.mono(constant) context.par() end context.stopcolumns() \stopluacode \stoptext %%%% end example Wolfgang
I changed the command, and now I get the correct page number with this command, \ but how should he do the calculation? \starttext \definepagestate[test][delay=yes] \dorecurse{10}{% \input knuth % {\ssd\color[red]{\setpagestate[test]\pagestaterealpage{test}{#1}}} } \stoptext Regards, --- Muyik
On 10/09/2024 06:32, ai2472206007@yeah.net wrote:
I changed the command, and now I get the correct page number with this command, \ but how should he do the calculation?
this gives an interesting result with a colorful mix of page numbers, although it is not obvious to me as why. \setupinterlinespace[18pt] \definepagestate[test][delay=yes] \starttext \dorecurse{15}{ {\ssd\color[red]{\setpagestate[test]\pagestaterealpage{test}{#1}}} \input knuth {\ssd\color[green]{\setpagestate[test]\pagestaterealpage{test}{#1}}} } \stoptext
On 9 Sep 2024, at 08:57, ai2472206007@yeah.net wrote:
As the title suggests, how do I get the correct page numbers?
There does seem to be an anomaly here. Simpler MWE: \starttext \dorecurse{15}{ \input knuth %{\ssd\color[red]{\pagenumber}} % not as expected {\color[red]{\pagenumber}} % as expected } \stoptext With the \ssd the first number at the top of the second and subsequent pages is one less than it should be. Without the \ssd then the numbers are as expected. @Muyik: Are you able to use \pagenumber without using \ssd or similar to change the size? That might be a work-around for you. There is also \userpagenumber. Regards, — Bruce Horrocks Hampshire, UK
this will go wrong as well: \starttext \dorecurse{15}{\ssd \input knuth {\color[red]{\pagenumber}} } \stoptext and this as well: \starttext \dorecurse{15}{\tfb \input knuth {\color[red]{\pagenumber}} % as expected } \stoptext and so does this: \setupinterlinespace[16pt] \starttext \dorecurse{15}{ \input knuth {\color[red]{\pagenumber}} % as expected } \stoptext (and there is probably a valid reason to it ;-) .F On 09/09/2024 23:27, Bruce Horrocks wrote:
On 9 Sep 2024, at 08:57,ai2472206007@yeah.net wrote:
As the title suggests, how do I get the correct page numbers?
There does seem to be an anomaly here. Simpler MWE:
\starttext \dorecurse{15}{ \input knuth %{\ssd\color[red]{\pagenumber}} % not as expected {\color[red]{\pagenumber}} % as expected } \stoptext
With the \ssd the first number at the top of the second and subsequent pages is one less than it should be. Without the \ssd then the numbers are as expected.
@Muyik: Are you able to use \pagenumber without using \ssd or similar to change the size? That might be a work-around for you. There is also \userpagenumber.
Regards, — 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 ___________________________________________________________________________________
That's true, but there seems to be a problem with all three examples, the first page number on the second page is all wrong with an output of 1. There must be some kind of mechanism that we don't know.
I used serif fonts and added color just to emphasize this page number. However, it is true that in some cases it is not possible to get the correct page correctly with these commands.
Bruce Horrocks schrieb am 09.09.2024 um 23:27:
On 9 Sep 2024, at 08:57, ai2472206007@yeah.net wrote:
As the title suggests, how do I get the correct page numbers?
There does seem to be an anomaly here. Simpler MWE:
\starttext \dorecurse{15}{ \input knuth %{\ssd\color[red]{\pagenumber}} % not as expected {\color[red]{\pagenumber}} % as expected } \stoptext
With the \ssd the first number at the top of the second and subsequent pages is one less than it should be. Without the \ssd then the numbers are as expected.
@Muyik: Are you able to use \pagenumber without using \ssd or similar to change the size? That might be a work-around for you. There is also \userpagenumber.
You can't use page counters in running text without problems because you're working against the way how TeX constructs pages. The only reliable way are multipass solutions like the pagestate or reference mechanism. Wolfgang
On 10 Sep 2024, at 19:47, Wolfgang Schuster
wrote: You can't use page counters in running text without problems because you're working against the way how TeX constructs pages.
The only reliable way are multipass solutions like the pagestate or reference mechanism.
If commands such as \pagenumber and \userpagenumber don’t work reliably then maybe the commands should be removed? Just a thought. — Bruce Horrocks Hampshire, UK
Bruce Horrocks schrieb am 11.09.2024 um 00:35:
On 10 Sep 2024, at 19:47, Wolfgang Schuster
wrote: You can't use page counters in running text without problems because you're working against the way how TeX constructs pages.
The only reliable way are multipass solutions like the pagestate or reference mechanism. If commands such as \pagenumber and \userpagenumber don’t work reliably then maybe the commands should be removed? Just a thought.
They work without problems when you use them to show the pagenumber in the header/footer because these elements are added when the page is finished and the values don't change anymore. What doesn't works is to use them to print the number of the current page within running text because TeX collects more text than it can fit on a single page which can result in the number of the previous page when the text is moved to the next one. Wolfgang
participants (4)
-
ai2472206007@yeah.net
-
Bruce Horrocks
-
vm
-
Wolfgang Schuster