4

It seems that IfSubStringInString has a problem if the sub string contains umlauts or other non-ASCII characters, as is illustrated by the following example:

\usepackage[utf8]{inputenc}
\usepackage{substr}
\begin{document}

\IfSubStringInString{Muller}{Müller}{Müller}{no Müller}

\IfSubStringInString{ller}{Müller}{Müller}{no Müller}

\IfSubStringInString{Müller}{Müller}{Müller}{no Müller}
\end{document}

Which produces the following output:

no Müller
Müller
ller2
üüllerMüllerMüllerno Müller

Apparently the first two calls to IfSubStringInString work, the third fails.

Is there a way to work around this?

2

Yes. Use xstring:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xstring}
\begin{document}

\IfSubStr{Muller}{Müller}{Müller}{no Müller}

\IfSubStr{ller}{Müller}{Müller}{no Müller}

\IfSubStr{Müller}{Müller}{Müller}{no Müller}

\end{document}
0

When you input ü under the utf8 option, LaTeX transforms it into \IeC{\"u}. The substr package uses \protected@edef to store the string and the substring to look for, but later on it uses \edef and neither \IeC nor \" can be used there.

A possible strategy is to “detokenize” the token lists obtained at this point, that represent anyway the strings we have to deal with. Well, in with this strategy Müller and M\IeC{\"u}ller would be considered the same, but this doesn't seem to be a problem as \IeC should never be directly used in a document.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{substr}

\makeatletter % fix the strings so \edef makes no harm later on
\renewcommand\su@ExpandTwoArgs[3]{%
  \protected@edef\su@SubString{#1}%
  \protected@edef\su@String{#2}%
  % ADDITION: detokenize the strings
  \edef\su@SubString{\detokenize\expandafter{\su@SubString}}%
  \edef\su@String{\detokenize\expandafter{\su@String}}%
  % END OF ADDITION
  \expandafter\expandafter\expandafter#3%
  \expandafter\expandafter\expandafter{%
    \expandafter\su@SubString\expandafter
  }\expandafter{\su@String}%
}
\makeatother

\begin{document}

\IfSubStringInString{Muller}{Müller}{Müller}{no Müller}

\IfSubStringInString{ller}{Müller}{Müller}{no Müller}

\IfSubStringInString{Müller}{Müller}{Müller}{no Müller}

\end{document}

enter image description here

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.