3

I am french and I would like to manage accented characters when using Stringstrings commands.

Here is a LaTeX Minimal Example to show you my issue :

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{stringstrings}

\begin{document}

\edef\str{Ô opiniâtre salubrité}

1 -- \str

2 -- \substring{\str}{1}{$}

\end{document}

When I compile, I get this :

enter image description here

I have tried several things, including this one :

\encodetoken{\str}

It works and then, I get : "Ô opiniâtre salubrité" but I can't intervene on the chain and modify it. The string seems frozen. For example, using a statement like this :

\Treatments{}{}{}{}{}{0} \substring{\str}{1}{$}

do not delete spaces at all.

Is there a way out of this?

Thank you very much !

2 Answers2

2

As the long-ago author of stringstrings, I can say that the package has many limitations and is not well written. However, to address your current situation, I would say these: the package does not handle unicode characters, but only those constructed as \^O opini\^atre salubrit\'e. Secondly, the argument to the package macros, such as \substring can not be a macro, but must be text. If you have it in a macro form, you must pre-expand it, as I do in case 3 below.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{stringstrings}

\begin{document}

\edef\str{Ô opiniâtre salubrité}

1 -- \str

\def\strB{^O opini^atre salubrit'e}

2 -- \substring{^O opini^atre salubrit'e}{1}{$}

3 -- \expandafter\substring\expandafter{\strB}{1}{$}

\end{document}

enter image description here

1

Your code mostly works if you use \newcommand instead of \edef. Note that you should probably use \newcommand most of the time anyway, since it checks to make sure the command isn't already defined. Since \str is a fairly common 3-letter name, it seems possible that it might be defined by some package, which \def would overwrite.

I say mostly works because this is my output:

enter image description here

stringstrings doesn't seem to like the é character.

On the other hand, the package xstring has no issues with accented characters:

enter image description here

The commands are different. xstring uses \StrMid instead of \substring, and xstring (as far as I know) has no $ shortcut. But you can use any number that's longer than the length of the string. xstring has much of the same functionality of stringstrings so it's likely you can switch. Package documentation is available in French as well as English: https://www.ctan.org/pkg/xstring

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
%\usepackage{stringstrings}
\usepackage{xstring}

\newcommand{\str}{Ô opiniâtre salubrité}

\begin{document}

1 -- \str

2 -- \StrMid{\str}{1}{40}

\end{document}

Sandy G
  • 42,558