[texhax] FW: Re: Inserting space after each char in a string

Uwe Lueck uwe.lueck at web.de
Thu Dec 2 10:57:06 CET 2010


Sorry for not having signed (below), too impatient. 

I also haven't dealt with interword spaces as in the example, 
but the example doesn't give any hint what do do at spaces. 

 (i) The macros work reasonably when you enclose spaces in braces.
(ii) The main macro could be modified so it reads blank spaces as 
     "other"; then they are dealt with just like characters.

And I haven't reasoned about UTF-8 that Reinhard mentioned. 
The macros should work when you put non-ASCII characters 
in braces (only then?)

Cheers, 

    Uwe. 


-----Ursprüngliche Nachricht-----
Von: "Uwe Lueck" 
Gesendet: 02.12.2010 10:39:02
An: "Uwe Ziegenhagen" <ziegenhagen at gmail.com>, reinhard.kotucha at web.de
Betreff: Re: [texhax] Inserting space after each char in a string

"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