[NTG-context] registers: how can I place a command around the whole of the page numbers of an index term?

MF massifr at fastwebnet.it
Thu May 10 17:16:04 CEST 2018


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



More information about the ntg-context mailing list