I'm having trouble with some macros and the § symbol. I can get things working with xelatex/lualatex, but not with pdflatex.
Here's my code:
\documentclass{article}
\usepackage{fontspec} % <- xelatex/lualatex works
%\usepackage[utf8]{inputenc} % <- pdflatex fails
\usepackage{etoolbox}
\makeatletter
\def\instring#1#2{TT\fi\begingroup
\edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@}
\makeatletter
\begin{document}
\def\A{§ 2|1:3}
Spilt ``\A{}'' at ``|'':
\DeclareListParser{\dopipedlist}{|}
\edef\B{{\A}}
\renewcommand*{\do}[1]{\item #1}
\begin{itemize}
\expandafter\dopipedlist\B
\end{itemize}
Searching for §:
\if\instring{§}{\A}
Found.
\else
Not found.
\fi
\end{document}
Ideally, I want to be able to define \A
with §
or \textsection
or \S
and have it work regardless of which flavour of *latex is used. (I know § won't work without fontspec/inputenc.)
I've had some success with \textsection
by using \noexpand\textsection
and moving to the more robust InSubStr
from the xstring package, but this is not as neat as I want. \A
is user provided and it seems unreasonable for an end user to have to decipher TeX's error message and know they need to add \noexpand
.
Is there any solution that “just works”? It doesn't matter if the back end code is messy. I'm more concerned that \A
is simple.
Finally, \A
could potentially contain anything, though the only strange character I want to check for with instring
is §.
\edef\B{{\A}}
is your problem\edef
should never be used on general text strings, in pdftex § is multiple characters set up to parse and decode utf8 encoding and then multiple font specific code to typeset a § none of that will do the right thing inside\edef
(also the\edef\x
) – David Carlisle Jan 20 '16 at 11:23