[texhax] A macro programming question

Paul Isambert zappathustra at free.fr
Sun Apr 11 10:30:05 CEST 2010


A little hack on Wolfgang's solution to allow space after the box 
specification:

\def\dohboxR
  {\ifx\next\bgroup
     \expandafter\dodohboxR
   \else
     \ifcat\noexpand\next\spacechar
       \expandafter\expandafter\expandafter\removespace
     \else
       \expandafter\expandafter\expandafter\nodohboxR
     \fi
   \fi}
{\def\:{\global\let\spacechar= }\: }
% There's already such an implicit space in all formats, I believe, but 
let's play safe.
\def\removespace{%
  \afterassignment\getchar\let\killspace=
% The previous line doesn't end with % on purpose!
  }
\def\getchar{\futurelet\next\dohboxR}

Wolfgang's code for the box material is troublesome if \endR has to 
retrieve values locally set in that material; however I can't see 
another solution. We can't use a \toks to store the material, since it 
should be closed by an explicit "}", whereas  the box can be closed by 
\egroup. Looping over the material and adding it character by character 
in a macro or token list until we find an \egroup or "}" won't do if for 
instance we stumble upon "\def\foo{...}", because we won't be able to 
add the braces... unless we use e-TeX, whose "default-engine-ness" 
should probably be taken for granted now, but that's another matter.

I can't understand why you make everything happen inside a group, 
Wolfgang. Is that because you use \toks0 as a scratch? Then wouldn't it 
simpler to use our own token list and remove the group?

Best,
Paul

Wolfgang Schuster a écrit :
> Am 10.04.10 18:41, schrieb Vafa Khalighi:
>>
>> Is not there a way that this \hboxR can accept \bgroup and \egroup? 
>> i.e. \hboxR\bgroup This is a test\egroup
> \def\beginR{B}
> \def\endR  {E}
>
> \def\hboxR{\bgroup\toks0={}\futurelet\next\dohboxR}
>
> \def\dohboxR
>   {\ifx\next\bgroup
>      \expandafter\dodohboxR
>    \else
>      \expandafter\nodohboxR
>    \fi}
>
> \def\dodohboxR
>   
> {\hbox\the\toks0\bgroup\beginR\bgroup\aftergroup\endR\aftergroup\egroup\aftergroup\egroup\let\next=} 
>
>
> \def\nodohboxR#1%
>   {\toks0=\expandafter{\the\toks0 #1}%
>    \futurelet\next\dohboxR}
>
> \hboxR{a}
> \hboxR to 4cm{a}
> \hboxR spread 1cm{a}
>
> \hboxR\bgroup a\egroup
> \hboxR to 4cm\bgroup a\egroup
> \hboxR spread 1cm\bgroup a\egroup
>
> \bye
>
> Spaces after the value (e.g. \hboxR to 3cm {...}) are not allowed in 
> this solution.
>
> Wolfgang
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org



More information about the texhax mailing list