# Xstring Problem with Ş

I want to use xstring version 1.7. However ş and ç cause problems. For instance

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

\begin{document}

\StrSubstitute{ş}{a}{b}

\end{document}


creates a long list of errors like this one:

! Illegal parameter number in definition of \@xs@arg@ii.


I am using the encoding package with the utf8 option and other characters like ö, ü and ğ are fine.

Edit: Here is the mwe spelled out in full.

• Please show us an MWE. We need this in order to help you. Thanks. – LaRiFaRi Jun 17 '15 at 11:30
• This is a problem with pdflatex, but works fine with the utf8 engine lualatex. Can you switch to that instead? – Andrew Swann Jun 17 '15 at 12:01

## 1 Answer

Package xstring uses \edef to expand the arguments by default, then commands can break like the UTF8 character.

The expansion mode can be changed, e.g. \noexpandargs to prevent expansion at all. It can be used inside a group or the expansion mode can be saved and restored afterwards:

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

\begin{document}

\saveexpandmode
\noexpandarg
\StrSubstitute{ş}{a}{b}
\restoreexpandmode

\end{document}

• Thank you very much. Why I don't have a problem with i, ö, ğ and ü then? – sonat Jun 17 '15 at 12:10
• @user2955390 - With utf8, many glyphs use 1 byte (8 bits) for encoding, whereas others need 2, 3, or even 4 bytes. You're "discovering" that i, ö, ğ and ü need just 1 byte, whereas ş and ç need more. – Mico Jun 17 '15 at 12:18
• @user2955390 It depends, how these letters are implemented with the current input encoding. Some are robust inside \edef, some not. – Heiko Oberdiek Jun 17 '15 at 12:21