Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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