1

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.

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

1 Answer 1

3

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}
3
  • Thank you very much. Why I don't have a problem with i, ö, ğ and ü then?
    – sonat
    Commented Jun 17, 2015 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
    Commented Jun 17, 2015 at 12:18
  • @user2955390 It depends, how these letters are implemented with the current input encoding. Some are robust inside \edef, some not. Commented Jun 17, 2015 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .