ai2472206...@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

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

Reply via email to