1

Foreword: I'm aware that I'm doing unusual stuff with LaTeX :P

I noticed that when I use \edef in something that contains an unicode (non-ASCII) character, TeX not only expands the macros, but also expands said unicode character (an ó, for example).

I also learned that LaTeX does some trickery with these characters when writing the auxiliary files.

But these two facts don't add up Ç_Ç.

For example, the following code will throw an error when compiled for the second time to add the \listoftables.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\edef\WeirdWayOfInsertingACaption{Fósforo}

\begin{document}

\listoftables

\begin{table} \caption{\WeirdWayOfInsertingACaption} \begin{tabular}{cccc} Can & I & Haz & LOT? \end{tabular} \end{table}

\end{document}

It will break beacuse \edef somehow expands the ó in such a way that LaTeX fails to spot it and write the \IeC{\'o} to the .toc file. Instead it writes a plain ó, and when the \listoftables command tries to write the List of Tables, we get this error:

! Package inputenc Error: Unicode char �sfo (U+14B)

(inputenc) not set up for use with LaTeX.

Is it possible to make the above code work keeping the \edef?

0 Answers0