In the following MWE both tests are true on pdflatex and inputenc but the second test fails on fontspec and luatex/xelatex. Any chance to get this engine agnostic (both true)?



ß in Maß: \IfSubStr{Maß}{ß}{TRUE}{FALSE}%
\ss{} in Maß: \IfSubStr{Maß}{\ss}{TRUE}{FALSE}%

  • 1
    ß is not an active char with luatex/xetex. You could change this, but why do you want to do it? – Ulrike Fischer May 14 '18 at 9:57
  • The idea was to restrict package code to us-ascii. – Archäopath May 14 '18 at 10:11

The fact that both tests with pdflatex return true is essentially a lucky coincidence.

The package xstring performs full expansion to the tokens in (some of) its arguments (see the package documentation); in the case of \IfSubStr the first and second arguments are fully expanded.

What happens to ß in pdflatex is:

  1. ß is actually two bytes in UTF-8;
  2. the first byte, 0xC3 makes TeX examine the next one, 0x9F and transform both according to an internal table to \ss (in utf8enc.dfu you find \DeclareUnicodeCharacter{00DF}{\ss});
  3. according to the current output encoding (here T1), \ss is transformed into \T1\ss (a quite strange token) which is internally defined through \chardef so it is unexpandable.

Thus you see that the same happens when you type \ss, just jumping over some of the above steps.

When lualatex is used, ß undergoes no expansion at all, because lualatex directly reads UTF-8 and internally transforms it into (abstract) Unicode. On the other hand, \ss becomes \TU\ss (similar to the above), which is essentially equivalent to type \char`ß (so it's not the same as typing ß).

Try \IfSubStr{Ș}{Ș}{TRUE}{FALSE} with pdflatex and you'll get a low level error

! Illegal parameter number in definition of \@xs@arg@ii.
<to be read again> 
l.15 \IfSubStr{Ș}{Ș}

No error with lualatex.

There's no guarantee of success when \IfSubStr is used for non ASCII characters.

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.