6

I want to substitute some spaces with normal font \dots in between name parts typeset in \ttfamily.

Below example works except for the commented part which fails miserably with the error: TeX capacity exceeded, sorry [input stack size=5000] \StrSubstitute{\pxname}{ }{\normaldots}.

\documentclass{article}

\usepackage{xstring}

%normaldots
\newcommand{\normaldots}{{\fontfamily{\familydefault}\fontseries{\seriesdefault}\fontshape{\shapedefault}\selectfont\normalsize\dots}}

\newcommand{\pxlastname}{Van der Laak}
\newcommand{\pxfirstname}{Cor}
\newcommand{\pxname}{\pxlastname\normaldots\pxfirstname}

\begin{document}
{\ttfamily\scshape\Huge\MakeLowercase{\pxname\normaldots test}}
\newline
%\StrSubstitute{\pxname}{ }{\normaldots}[\pxoutput]
%{\ttfamily\scshape\Huge\MakeLowercase{\pxoutput\normaldots test}}
\end{document}
6

xstring, by default, does complete expansion on its arguments. The biggest problem is, therefore, the fact that also \normaldots gets expanded, which you don't want.

You can "robustify" the \normaldots command with etoolbox:

\documentclass{article}

\usepackage{xstring,etoolbox}

%normaldots
\newrobustcmd{\normaldots}{{\normalfont\normalsize\dots}}

\newcommand{\pxlastname}{Van der Laak}
\newcommand{\pxfirstname}{Cor}
\newcommand{\pxname}{\pxlastname\normaldots\pxfirstname}

\begin{document}
{\ttfamily\scshape\Huge\MakeLowercase{\pxname\normaldots test}}
\newline

\StrSubstitute{\pxname}{ }{\normaldots}[\pxoutput]
{\ttfamily\scshape\Huge\MakeLowercase{\pxoutput\normaldots test}}

\end{document}

In this way, \normaldots passes unexpanded through the \edef performed by xstring when doing \StrSubstitute.

Note also that \normaldots can be defined in a simpler way than yours.

enter image description here

|improve this answer|||||
0

Here's an alternate solution with stringstrings:

\documentclass{article}
\makeatletter
\let\protectededef\protected@edef
\makeatother

%\usepackage{xstring}
\usepackage{stringstrings}

\newcommand{\normaldots}{{\fontfamily{\familydefault}\fontseries{\seriesdefault}\fontshape{\shapedefault}\selectfont\normalsize\dots}}

\newcommand{\pxlastname}{Van der Laak}
\newcommand{\pxfirstname}{Cor}
\newcommand{\pxname}{\pxlastname\normaldots\pxfirstname}

\newcommand\pxoutput{\dpxlastname\normaldots\pxfirstname}

\begin{document}
{\ttfamily\scshape\Huge\MakeLowercase{\pxname\normaldots test}}
\newline
%\StrSubstitute{\pxname}{ }{\normaldots}[\pxoutput]

\encodetoken[1]{\normaldots}
\convertword[e]{\pxlastname}{~}{\normaldots}
\retokenize{\thestring}

\protectededef\dpxlastname{\thestring}
\decodetoken[1]{\normaldots}

{\ttfamily\scshape\Huge\MakeLowercase{\pxoutput\normaldots test}}
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.