latex3 / babel

The multilingual framework to localize LaTeX, LuaLaTeX and XeLaTeX
https://latex3.github.io/babel/
LaTeX Project Public License v1.3c
130 stars 35 forks source link

\shorthandoff*{^} causes error for \section command #129

Closed wehro closed 3 years ago

wehro commented 3 years ago
\documentclass{article}
\usepackage[esperanto]{babel}

\begin{document}
\section{^c}
\shorthandoff*{^}
\end{document}

Error message:

! Undefined control sequence.
<write> ...ine {section}{\protect \numberline {1}^
                                                  c}{\thepage }{}\protected@...
l.7 \end{document}

It works without problems with the unstarred form \shorthandoff{^}, so I think it should also work with the starred form.

jbezos commented 3 years ago

This is more complicated, and I'm not sure if it's entirely ‘legal’, because these macros are for temporary changes. But the following is clearly legal and also fails:

\section{^c}
\shorthandoff*{^}
Blah
\newpage
\shorthandon{^}
Blah

I have to deal with the output routine, which is not always easy.

blefloch commented 3 years ago

I have no idea if this is useful, but perhaps you can use the fact that TeX is in "no mode" when TeX processes \write inside a shipped out page. (It is also in "no mode" inside \immediate\write.)

\ifmmode\else\ifhmode\else\ifvmode\else _we_are_now_inside_a_write \fi\fi\fi