registers: how can I place a command around the whole of the page numbers of an index term?
Hello list, i'd like moving the page numbers in my index to the right, with a \wordright. \setupregister[index][n=1,alternative=A] \starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \placeindex \stoptext The index is at page 4. I want to move the numbers "1,3" and "2" to the right. The parameter pagecommand is for the single page number, i want to put a command (\wordright) around the whole block of page numbers. How can i do that? Greetings, Massi
There is no option to apply a command to all page numbers but you can add something after the register entry with the textcommand key. Be aware this solution isn’t perfect because in the worst case (narrow columns for the register or long entries) page numbers can be split on multiple lines. \setupregister [index] [n=1, alternative=A, textcommand=\groupedcommand{}{\hfill\quad}] Wolfgang
MF mailto:massifr@fastwebnet.it 9. Mai 2018 um 17:09 Hello list, i'd like moving the page numbers in my index to the right, with a \wordright.
\setupregister[index][n=1,alternative=A]
\starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \placeindex \stoptext
The index is at page 4. I want to move the numbers "1,3" and "2" to the right. The parameter pagecommand is for the single page number, i want to put a command (\wordright) around the whole block of page numbers. How can i do that?
Greetings, Massi
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Thanks Wolfgang and sorry if i reply to my mail, since i've downloaded yours on another PC. I've found these macros in strc-reg.mkiv, that are called right before and after the page numbers: \unexpanded\def\startregisterpages {\begingroup \dostarttagged\t!registerpages\empty \useregisterstyleandcolor\c!pagestyle\c!pagecolor} \unexpanded\def\stopregisterpages {\dostoptagged \endgroup} And this seems to work: \let\origstartregisterpages=\startregisterpages% \let\origstopregisterpages=\stopregisterpages% \unexpanded\def\startregisterpages{\origstartregisterpages\wordright\bg roup } \unexpanded\def\stopregisterpages{\egroup\origstopregisterpages} \setupregister[index][n=1,alternative=A] \starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \placeindex \stoptext I've also learned about \groupedcommand, which i did not know. Again, thanks for you help. Best wishes, Massi
This is a more polite version, that lets you restore the original macros. \let\origstartregisterpages=\startregisterpages% \let\origstopregisterpages=\stopregisterpages% \def\setupregisterpagescommand#1{% \unexpanded\def\startregisterpages{\origstartregisterpages#1\bgroup } \unexpanded\def\stopregisterpages{\egroup\origstopregisterpages}} \def\resetregisterpagescommand{% \let\startregisterpages=\origstartregisterpages% \let\stopregisterpages=\origstopregisterpages} \setupregister[index][n=1,alternative=A] \starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \setupregisterpagescommand{\wordright} \placeindex \page \resetregisterpagescommand \placeindex \stoptext btw, Hans, are you going to add an option to \setupregister? :)
The following solution which adds two additional keys (pageleft and pageright) is cleaner because it doesn’t have to overload commands. \unprotect \unexpanded\def\startregisterpages {\begingroup \dostarttagged\t!registerpages\empty \useregisterstyleandcolor\c!pagestyle\c!pagecolor \registerparameter\c!pageleft} \unexpanded\def\stopregisterpages {\registerparameter\c!pageright \dostoptagged \endgroup} \protect \setupregister [index] [n=1, alternative=A, distance=0pt, pageleft=\wordright\bgroup, pageright=\egroup] \starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \placeindex \stoptext Wolfgang
MF mailto:massifr@fastwebnet.it 10. Mai 2018 um 12:35 This is a more polite version, that lets you restore the original macros.
\let\origstartregisterpages=\startregisterpages% \let\origstopregisterpages=\stopregisterpages% \def\setupregisterpagescommand#1{% \unexpanded\def\startregisterpages{\origstartregisterpages#1\bgroup } \unexpanded\def\stopregisterpages{\egroup\origstopregisterpages}} \def\resetregisterpagescommand{% \let\startregisterpages=\origstartregisterpages% \let\stopregisterpages=\origstopregisterpages}
\setupregister[index][n=1,alternative=A]
\starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \setupregisterpagescommand{\wordright} \placeindex \page \resetregisterpagescommand \placeindex \stoptext
btw, Hans, are you going to add an option to \setupregister? :) ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
\wordright is ok until the numbers don't exceed the text width. It manages these two cases right: Index term, and some text 21, 34, 45, 72 Index term, and some text 21, 34, 45, 72, 89 When the numbers exceed the text width, it fails: Index term, and some text 21, 34, 45, 72, 89, 101, 103, 109 It fails because it uses a hbox, that can't do nothing but running beyond the right margin. This would be a solution: Index term, and some text 21, 34, 45, 72, 89, 101, 103, 109 where the rule is: when the numbers exceed the text width, close the paragraph, then start a new, right aligned one. So i wrote this: --------------------------------------------------- \def\wordorparagraphright#1{\let\scratchWidth\relax \setbox\scratchbox=\hbox{#1}\newdimen\scratchWidth \scratchWidth=\wd\scratchbox \ifdim\scratchWidth < 0.9\textwidth \wordright{#1}% \else \par \startalignment[flushright]#1\stopalignment \fi} \starttext \input sapolsky \wordorparagraphright{\it other text} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time longer} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time much much much much much much much much much much much much much much much much much much much much much much longer} \par \stoptext --------------------------------------------------- But it doesn't work with --------------------------------------------------- \unprotect \unexpanded\def\startregisterpages {\begingroup \dostarttagged\t!registerpages\empty \useregisterstyleandcolor\c!pagestyle\c!pagecolor \registerparameter\c!pageleft} \unexpanded\def\stopregisterpages {\registerparameter\c!pageright \dostoptagged \endgroup} \protect \def\wordorparagraphright#1{\let\scratchWidth\relax \setbox\scratchbox=\hbox{#1}\newdimen\scratchWidth \scratchWidth=\wd\scratchbox \ifdim\scratchWidth < 0.9\textwidth \w ordright{#1}% \else \par \startalignment[flushright]#1\stopalign ment \fi} \setupregister [index] [n=1, alternative=A, distance=0pt, pageleft=\wordorparagraphright\bgroup, pageright=\egroup] \starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \placeindex \stoptext --------------------------------------------------- I suppose it's related to the problem that \groupedcommand solves. Is there a solution? An even better solution would be: Index term, and some text 21, 34, 45, 72, 89, 101, 103, 109 where the rule is: put the text until it fills the current line, than proceed flushing the remainder of the paragraph lines to the right. Here i tried changing \leftskip in the middle of a paragraph, but it works globally. I think this is even harder to implement, at least in the middle of the register macros.
This would be a solution:
Index term, and some text 21, 34, 45, 72, 89, 101, 103, 109
where the rule is: when the numbers exceed the text width, close the paragraph, then start a new, right aligned one.
So i wrote this:
--------------------------------------------------- \def\wordorparagraphright#1{\let\scratchWidth\relax \setbox\scratchbox=\hbox{#1}\newdimen\scratchWidth \scratchWidth=\wd\scratchbox \ifdim\scratchWidth < 0.9\textwidth \wordright{#1}% \else \par \startalignment[flushright]#1\stopalignment \fi}
\starttext \input sapolsky \wordorparagraphright{\it other text} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time longer} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time much much much much much much much much much much much much much much much much much much much much much much longer} \par \stoptext ---------------------------------------------------
This, instead, works also with registers: ------------------------------------------------- -- \unexpanded\def\wordorparagraphright{\dosingleempty\WordOrParagraphRigh t} \def\WordOrParagraphRight[#1]{\groupedcommand{\setbox0\hbox\bgroup} {\egroup\newdimen\myBoxWd\myBoxWd=\wd0 \ifdim\myBoxWd < .7\hsize \wordright{\box0}% \else \startalignment[flushright]\leftskip=.3\hsize plus 1fil\unhbox0 \stopalignment \fi}} \starttext \input sapolsky \wordorparagraphright{\it other text} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time longer} \par \blank \input sapolsky \wordorparagraphright{\it other text, this time much much much much much much much much much much much much much much much much much much much much much much longer} \par \stoptext --------------------------------------------------- A doubt: i'm using box0, is it dangerous? I tried with scratchbox, but it doesn't work, then i moved to box0, and it seems to work, even with a big file (with a big register too) of mine.
On 5/10/2018 12:35 PM, MF wrote:
This is a more polite version, that lets you restore the original macros.
\let\origstartregisterpages=\startregisterpages% \let\origstopregisterpages=\stopregisterpages% \def\setupregisterpagescommand#1{% \unexpanded\def\startregisterpages{\origstartregisterpages#1\bgroup } \unexpanded\def\stopregisterpages{\egroup\origstopregisterpages}} \def\resetregisterpagescommand{% \let\startregisterpages=\origstartregisterpages% \let\stopregisterpages=\origstopregisterpages}
\setupregister[index][n=1,alternative=A]
\starttext \CONTEXT\index{\ConTeXt} \page \LATEX\index{\LaTeX} \page \CONTEXT\index{\ConTeXt} \page \setupregisterpagescommand{\wordright} \placeindex \page \resetregisterpagescommand \placeindex \stoptext
btw, Hans, are you going to add an option to \setupregister? :) knowing that wolfgang looked into it i just wait till he cooks up something
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 -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
MF
-
Wolfgang Schuster