Article View: comp.text.tex
Article #11041Re: wider macro
From: Daniel H. Luecking
Date: Thu, 07 Jan 1993 22:53
Date: Thu, 07 Jan 1993 22:53
53 lines
2491 bytes
2491 bytes
> From: wilcox@cmns.think.com
>
> I would like to write a TeX macro which inserts spaces after every letter in
> its argument. For example:
>
> WIDER -> W I D E R
>
> My attempt works, but causes lots of error messages:
>
> \def\wider#1{{\getwider#1\end}}
> \def\getwider#1{#1 \ifx#1\end \let\next=\relax \else \let\next=\getwider
\next}
>
> It also ignores spaces in the input, so all words get run together.
> Any suggestions?
>
Yes. In the TeXbook in Appendix D there is given a macro which
accepts a token list and reads each token one by one, and checks to see if
it is an asterix. You could modify the code to read each token,
check to see if it is \end and then, if not, replace the token
and emit a space. Part of the trick is to say
{...\let\next= }
^
The space is important since, in an assignment, at most one
space is ignored after the equal sign and so this procedure will
not ignore spaces. Here are two possibilities with apparently identical
effects (at least in the simple test), but different syntax.
\def\wider{\afterassignment\processthetoken\let\next= }
\def\processthetoken{\ifx\next\endwider\let\next=\relax % do nothing
\else\next\space % emit token+space
\let\next=\wider\fi %
\next} % repeat
Test it here:
\hbox{\wider WIDER and W I D E R and W \ I \ D \ E \ R \
\endwider :widened text}
\hbox{ WIDER and W I D E R and W \ I \ D \ E \ R \ :unwidened text}
Another try:
\def\wider#1{\getwider#1\endwider}
\def\getwider{\afterassignment\processthetoken\let\next= }
\def\processthetoken{\ifx\next\endwider\let\next=\relax % do nothing
\else\next\space % emit token+space
\let\next=\getwider\fi %
\next} % repeat
\hbox{\wider{WIDER and W I D E R and W \ I \ D \ E \ R \ }:widened text}
\hbox{ WIDER and W I D E R and W \ I \ D \ E \ R \ :unwidened text}
\bye
Technical Details
Message-ID:
<9984798@MVB.SAIC.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!usc!news.service.uci.edu!unogate!mvb.saic.com!info-texShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!usc!news.service.uci.edu!unogate!mvb.saic.com!info-tex From: "Daniel H. Luecking" <DL24794%UAFSYSB.BITNET@SHSU.edu> Newsgroups: comp.text.tex Subject: Re: wider macro Message-ID: <9984798@MVB.SAIC.COM> Date: Thu, 07 Jan 93 16:53:35 CST Organization: Info-Tex<==>Comp.Text.Tex Gateway X-Gateway-Source-Info: Mailing List Lines: 53