reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
190 stars 51 forks source link

Polyglossia Latin breaks using `^` inside `\label{}`-like stored values #582

Closed thomwiggers closed 1 year ago

thomwiggers commented 1 year ago

I have a probably–over-complicated setup in my document, in which I do the following. I have a long proof in which there are many small steps. I use a bit of a hack to write out the values obtained in each step to the .aux file as labels, so that I can later retrieve them in any place of my document.

A MWE of this setup is:

\documentclass{article}

% Set up polyglossia
\usepackage[babelshorthands=false]{polyglossia}
\setdefaultlanguage[variant=american]{english}
\setotherlanguage[variant=classic,prosodicshorthands=false]{latin}

% for \customlabel
\usepackage{hyperref}

\makeatletter
\newcommand{\customlabel}[2]{%
   \protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }
   \hypertarget{#1}{}%
}
\makeatother

\begin{document}

\[
   \ref*{testlabel} \\
\]

\customlabel{testlabel}{\frac{n^2}{2}}

\end{document}

However, if I compile this document (lualatex test.tex; lualatex test.tex) I get the following error:

(./test.out)
! Undefined control sequence.
^->\active@prefix ^\@undefined 

l.25    \ref*{testlabel}
                       \\
? 

This has started failing for me when I got updated to TexLive 2023 this week.

thomwiggers commented 1 year ago

A workaround seems to be to put the following in the preamble, based on https://github.com/wehro/polyglossia/blob/839f9837ccdd3ed4befec0536141016d3f1ad322/tex/gloss-latin.ldf

\protected@write \@auxout { } { \shorthandoff {^} } 

But that's not exactly ideal. I don't really understand catcodes well enough to understand what's going on here, so I won't make a PR.

thomwiggers commented 1 year ago

Using \shorthandoff* like in @wehro's patch seems to work just like the not-starred version.

jspitz commented 1 year ago

Polyglossia 1.61 is on its way to CTAN.