Hi Hans, what’s your opinion to redefine the leaders command to take a optional name which loads a predefined setup? <code> % use \doifsymbolelse for the symbol key? \unprotect \installcorenamespace{leaders} \installcorenamespace{leadersalternative} \installdefinehandler \??leaders {leaders} \??leaders \installparameterhandler \??leaders {leaders} \installsetuphandler \??leaders {leaders} \def\leaders {\doifnextoptionalelse\leaders_indeed\normalleaders} \def\leaders_indeed[#1]% {\def\currentleaders{#1}% \expandcheckedcsname\??leadersalternative{\leadersparameter\c!alternative}\s!default} \setvalue{\??leadersalternative\s!default}% {\leadersparameter\c!left \normalleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right} \setvalue{\??leadersalternative\s!default}% {\leadersparameter\c!left \normalleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right} \setvalue{\??leadersalternative\v!global}% {\leadersparameter\c!left \normalgleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right} \setupleaders [\c!width=1em, \c!symbol=., \c!alternative=\s!default] \protect \defineleaders[test]%[symbol=x] \starttext text\leaders\hbox to 1em{\hss .\hss}\hfill text text\leaders[test]text \stoptext </code> This method would be cleaner for user defined list layouts where one want to change the filler between the text and the page number because a setup like this isn’t something for a normal user. <code source="strc-lst.mkvi"> \definelistalternative [c] [\c!distance=5em, \c!width=0pt, \c!stretch=10em, \c!filler=\hskip.5em\gleaders\hbox to .5em{\hss.\hss}\hfill\hskip.5em\relax, \c!renderingsetup=\??listrenderings:abc] </code> Wolfgang
On 1/13/2013 7:06 PM, Wolfgang Schuster wrote:
what’s your opinion to redefine the leaders command to take a optional name which loads a predefined setup?
We should avoid redefining a primitive (esp one that is used in math).
<code> % use \doifsymbolelse for the symbol key?
\unprotect
\installcorenamespace{leaders} \installcorenamespace{leadersalternative}
\installdefinehandler \??leaders {leaders} \??leaders \installparameterhandler \??leaders {leaders} \installsetuphandler \??leaders {leaders}
\def\leaders {\doifnextoptionalelse\leaders_indeed\normalleaders}
\def\leaders_indeed[#1]% {\def\currentleaders{#1}% \expandcheckedcsname\??leadersalternative{\leadersparameter\c!alternative}\s!default}
\setvalue{\??leadersalternative\s!default}% {\leadersparameter\c!left \normalleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right}
\setvalue{\??leadersalternative\s!default}% {\leadersparameter\c!left \normalleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right}
\setvalue{\??leadersalternative\v!global}% {\leadersparameter\c!left \normalgleaders\hbox to \leadersparameter\c!width{\hss\leadersparameter\c!symbol\hss}\hfill \leadersparameter\c!right}
\setupleaders [\c!width=1em, \c!symbol=., \c!alternative=\s!default]
\protect
\defineleaders[test]%[symbol=x]
\starttext
text\leaders\hbox to 1em{\hss .\hss}\hfill text
text\leaders[test]text
\stoptext </code>
This method would be cleaner for user defined list layouts where one want to change the filler between the text and the page number because a setup like this isn’t something for a normal user.
As we have a few more leader primitives, I generalized your code a bit and also made the box alignment configurable: \installcorenamespace{fillers} \installcorenamespace{fillersalternative} \installcommandhandler \??fillers {fillers} \??fillers \unexpanded\def\fillers {\dosingleempty\spac_fillers_indeed} \def\spac_fillers_indeed[#1]% {\begingroup \edef\currentleaders{#1}% \fillersparameter\c!left \expandcheckedcsname\??fillersalternative{\fillersparameter\c!alternative}\v!local \simplealignedbox {\fillersparameter\c!width}% {\fillersparameter\c!align}% {\fillersparameter\c!symbol}% \hfill \fillersparameter\c!right \endgroup} \letvalue{\??fillersalternative\s!local }\normalleaders % overflow ends up inbetween (current box) \letvalue{\??fillersalternative\v!global }\normalgleaders % overflow ends up inbetween (outermost box) \letvalue{\??fillersalternative\v!middle }\normalcleaders % overflow ends up before, after (current box) \letvalue{\??fillersalternative\v!broad }\normalxleaders % overflow ends up before, inbetween, after (current box) \setupfillers [\c!width=\emwidth, \c!symbol=., \c!align=\v!middle, \c!alternative=\s!local] \protect \definefillers[test][symbol=!] \starttext text\leaders\hbox to 1em{\hss .\hss}\hfill text text\fillers[test]text \stoptext
<code source="strc-lst.mkvi"> \definelistalternative [c] [\c!distance=5em, \c!width=0pt, \c!stretch=10em, \c!filler=\hskip.5em\gleaders\hbox to .5em{\hss.\hss}\hfill\hskip.5em\relax, \c!renderingsetup=\??listrenderings:abc] </code>
before we add this kind of code, how about a more extensive mechanism so that we can say filler=periods for this we need to generalize the above even more i.e. we could have: alternative=rule (height width depth) alternative=box (the leaders) alternative=stretch (hfill and then methods, for leaders, so now we get: \unprotect \installcorenamespace{fillers} \installcorenamespace{fillersalternative} \installcorenamespace{fillersleadermethod} \installcommandhandler \??fillers {fillers} \??fillers \unexpanded\def\fillers {\dosingleempty\spac_fillers_indeed} \def\spac_fillers_indeed[#1]% {\begingroup \edef\currentfillers{#1}% \scratchdimen\fillersparameter\c!leftmargin\relax \ifdim\scratchdimen=\zeropoint\else \hskip\scratchdimen \fi \fillersparameter\c!left\relax \getvalue{\??fillersalternative\fillersparameter\c!alternative}\relax \fillersparameter\c!right\relax \scratchdimen\fillersparameter\c!rightmargin\relax \ifdim\scratchdimen=\zeropoint\else \hskip\scratchdimen \fi \endgroup} \setvalue{\??fillersalternative\s!box}% {\expandcheckedcsname\??fillersleadermethod{\fillersparameter\c!method}\v!local \simplealignedbox {\fillersparameter\c!width}% {\fillersparameter\c!align}% {\fillersparameter\c!symbol}% \hfill} \setvalue{\??fillersalternative\c!stretch}% {\hfill} \setvalue{\??fillersalternative\c!rule}% {\expandcheckedcsname\??fillersleadermethod{\fillersparameter\c!method}\v!local \hrule \!!height\fillersparameter\c!height \!!depth \fillersparameter\c!depth \hfill} \letvalue{\??fillersleadermethod\s!local }\normalleaders % overflow ends up inbetween (current box) \letvalue{\??fillersleadermethod\v!global}\normalgleaders % overflow ends up inbetween (outermost box) \letvalue{\??fillersleadermethod\v!middle}\normalcleaders % overflow ends up before, after (current box) \letvalue{\??fillersleadermethod\v!broad }\normalxleaders % overflow ends up before, inbetween, after (current box) \setupfillers [\c!width=\emwidth, \c!symbol=., \c!align=\v!middle, \c!height=.1\exheight, \c!depth=\zeropoint, \c!leftmargin=\zeropoint, \c!rightmargin=\zeropoint, \c!alternative=\s!box, \c!method=\s!local] % maybe box -> symbol \protect \definefillers[test-a][alternative=stretch] \definefillers[test-b][alternative=box,symbol=!] \definefillers[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em] \starttext text\leaders\hbox to 1em{\hss .\hss}\hfill text text\fillers[test-a]text text\fillers[test-b]text text\fillers[test-c]text \stoptext maybe box should be symbol (no \v!symbol yet) maybe some more tricks can be added Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 13.01.2013 um 20:43 schrieb Hans Hagen
On 1/13/2013 7:06 PM, Wolfgang Schuster wrote:
what’s your opinion to redefine the leaders command to take a optional name which loads a predefined setup?
We should avoid redefining a primitive (esp one that is used in math).
No problem.
[…]
before we add this kind of code, how about a more extensive mechanism so that we can say filler=periods
for this we need to generalize the above even more i.e. we could have:
alternative=rule (height width depth) alternative=box (the leaders) alternative=stretch (hfill
and then methods, for leaders, so now we get:
\unprotect
\installcorenamespace{fillers} \installcorenamespace{fillersalternative} \installcorenamespace{fillersleadermethod}
\installcommandhandler \??fillers {fillers} \??fillers
\unexpanded\def\fillers {\dosingleempty\spac_fillers_indeed}
\def\spac_fillers_indeed[#1]% {\begingroup \edef\currentfillers{#1}% \scratchdimen\fillersparameter\c!leftmargin\relax \ifdim\scratchdimen=\zeropoint\else \hskip\scratchdimen \fi \fillersparameter\c!left\relax \getvalue{\??fillersalternative\fillersparameter\c!alternative}\relax \fillersparameter\c!right\relax \scratchdimen\fillersparameter\c!rightmargin\relax \ifdim\scratchdimen=\zeropoint\else \hskip\scratchdimen \fi \endgroup}
\setvalue{\??fillersalternative\s!box}% {\expandcheckedcsname\??fillersleadermethod{\fillersparameter\c!method}\v!local \simplealignedbox {\fillersparameter\c!width}% {\fillersparameter\c!align}% {\fillersparameter\c!symbol}% \hfill}
\setvalue{\??fillersalternative\c!stretch}% {\hfill}
\setvalue{\??fillersalternative\c!rule}% {\expandcheckedcsname\??fillersleadermethod{\fillersparameter\c!method}\v!local \hrule \!!height\fillersparameter\c!height \!!depth \fillersparameter\c!depth \hfill}
\letvalue{\??fillersleadermethod\s!local }\normalleaders % overflow ends up inbetween (current box) \letvalue{\??fillersleadermethod\v!global}\normalgleaders % overflow ends up inbetween (outermost box) \letvalue{\??fillersleadermethod\v!middle}\normalcleaders % overflow ends up before, after (current box) \letvalue{\??fillersleadermethod\v!broad }\normalxleaders % overflow ends up before, inbetween, after (current box)
\setupfillers [\c!width=\emwidth, \c!symbol=., \c!align=\v!middle, \c!height=.1\exheight, \c!depth=\zeropoint, \c!leftmargin=\zeropoint, \c!rightmargin=\zeropoint, \c!alternative=\s!box, \c!method=\s!local]
% maybe box -> symbol
\protect
\definefillers[test-a][alternative=stretch] \definefillers[test-b][alternative=box,symbol=!] \definefillers[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em]
\starttext
text\leaders\hbox to 1em{\hss .\hss}\hfill text
text\fillers[test-a]text
text\fillers[test-b]text
text\fillers[test-c]text
\stoptext
maybe box should be symbol (no \v!symbol yet)
maybe some more tricks can be added
That version is even better, maybe remove spaces before/after the command to avoid unwanted spaces. Even though the \fillers command is slower than direct use of leaders it’s in my opinion more user friendly. Wolfgang
On 1/13/2013 9:34 PM, Wolfgang Schuster wrote:
That version is even better, maybe remove spaces before/after the command to avoid unwanted spaces.
Ok, added (spac-flt.mkiv).
Even though the \fillers command is slower than direct use of leaders it’s in my opinion more user friendly.
I've added it to the beta (ftp): \setupbodyfont[dejavu] \definefiller[test-a][alternative=stretch] \definefiller[test-b][alternative=symbol,symbol=!] \definefiller[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em] \starttext text\filler[test-a]text \par text\filler[test-b]text \par text\filler[test-c]text \par text\checkedfiller{<nothing>}text \par \stoptext Up to you to suggest list replacements. Concerning speed: \setupbodyfont[dejavu] \definefiller[test][alternative=symbol,symbol=!] \starttext dummy \page \testfeatureonce{1000} { % 0.19 | 0.60 % \setbox0 \hbox to \hsize {text \removeunwantedspaces\leaders\hbox to 1em{\hss !\hss}\hfill\ignorespaces text} } \page \testfeatureonce{1000} { % 0.27 | 0.65 % \setbox0 \hbox to \hsize {text \filler[test] text} } \stoptext so it's neglectable on a document (most documents don't have 1000 such fillers): 0.0008 seconds per filler and that's an old machine. The performance of the commandhandler code is quite ok given what it does. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 13.01.2013 um 22:00 schrieb Hans Hagen
On 1/13/2013 9:34 PM, Wolfgang Schuster wrote:
That version is even better, maybe remove spaces before/after the command to avoid unwanted spaces.
Ok, added (spac-flt.mkiv).
Even though the \fillers command is slower than direct use of leaders it’s in my opinion more user friendly.
I've added it to the beta (ftp):
\setupbodyfont[dejavu]
\definefiller[test-a][alternative=stretch] \definefiller[test-b][alternative=symbol,symbol=!] \definefiller[test-c][alternative=rule,height=.1ex,leftmargin=.5em,rightmargin=.25em]
\starttext
text\filler[test-a]text \par text\filler[test-b]text \par text\filler[test-c]text \par text\checkedfiller{<nothing>}text \par
\stoptext
The colon after #1 is missing. \unexpanded\def\checkedfiller#1% - {\ifcsname\??filler#1\s!parent\endcsname + {\ifcsname\namedfillerhash{#1}\s!parent\endcsname \spac_fillers_indeed[#1]% \expandafter\gobbleoneargument \else \expandafter\firstofoneargument \fi{#1}}
Up to you to suggest list replacements. Concerning speed:
\setupbodyfont[dejavu]
Is there a reason why you always use DejaVu in your example? Wolfgang
On 1/13/2013 10:23 PM, Wolfgang Schuster wrote:
The colon after #1 is missing.
\unexpanded\def\checkedfiller#1% - {\ifcsname\??filler#1\s!parent\endcsname + {\ifcsname\namedfillerhash{#1}\s!parent\endcsname
yes, i was lazy
Up to you to suggest list replacements. Concerning speed:
\setupbodyfont[dejavu]
Is there a reason why you always use DejaVu in your example?
there was: fonts load .2 sec faster when we didn't have real lm math yet (and in timing / testing i want as less overhead as possible) to some extend there still is: looks slightly better on my high res monitors (lm is somewhat spiny) in the editor and on the console i use dejavu mono as it supports many characters (lm mono is also ok but has less coverage) so for manuals dejavu mono is better when more than latin is involved Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Wolfgang Schuster
-
Wolfgang Schuster