[texhax] Inserting space after each char in a string

Uwe Lueck uwe.lueck at web.de
Thu Dec 2 10:39:04 CET 2010


"Reinhard Kotucha" <reinhard.kotucha at web.de>, 02.12.2010 09:33:06:
>On 2 December 2010 Uwe Ziegenhagen wrote:
> > I need a command which allows me to insert a certain space after each
> > character of the string given as argument, but don't know how to accomplish.
> > 
> > I am looking for something like this
> > 
> > \textspace{\quad}{some long word} which produces then
> > 
> > s\quad o\quad m\quad e\quad etc..
> > 
> > Any ideas?
>
> There is a macro \@tfor in the LaTeX kernel.  It's described in
> source/latex/base/ltcntrl.dtx .  Don't know whether it works with
> UTF-8 properly.

But \@tfor isn't expandable, uses \def. Therefore I spent an hour with this:

\ProvidesFile{LESSPACK.TEX}[2010/12/02 general letterspacing]
\documentclass[12pt]{article}
\nofiles
\makeatletter
 \newcommand*{\lesserspacking}[2]{%
 %% #1 conditional insertion
 %% #2 "string"
 \@lesser at spacking{#1}{\@leffer at fpacking{#1}}#2\@nnil}
 \newcommand*{\@lesser at spacking}[2]{\IfLesserSpacking{}{#1}{#2}}
 %% #1 conditional insertion     #2 conditional next command
 \newcommand*{\IfLesserSpacking}[4]{%
 %% #1 conditional insertion
 %% #2 general insertion
 %% #3 conditional next command
 %% #4 token/group ahead
 \ifx#4\@nnil     \expandafter\@gobble
 \else        #1#4\expandafter\@firstofone
 \fi          {#3}} 
 \newcommand*{\@leffer at fpacking}[1]{%
 \IfLesserSpacking{#1}{#1}{\@leffer at fpacking{#1}}}
\makeatother
\begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
\edef\test{%
 \lesserspacking{\noexpand\quad}{YES} ---
 \lesserspacking{no}{YES} ---
 \lesserspacking{ . }{{NO}{NO}{NO}}%
}
\show\test
\test
\end{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


More information about the texhax mailing list