latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
126 stars 34 forks source link

\shorthandoff*{^} is not revertible #126

Closed wehro closed 3 years ago

wehro commented 3 years ago

An active ^ character (as defined by babel-esperanto and some other languages) may cause problems under certain circumstances. To turn this shorthand off, the babel manual advises to use \shorthandoff*{^} (starred form) instead of \shorthandoff{^} aiming to keep ^ intact in math mode. However, when using the starred form, it seems not to be possible to turn ^ on again with \shorthandon{^}. I ran into this issue when experimenting with babel-latin, which I am revising at the moment, but for the sake of simplicity, let me demonstrate with Esperanto:

\documentclass{article}
\usepackage[esperanto]{babel}

\begin{document}
\shorthandoff*{^}
^^51 % the letter Q
$a^2+b^2=c^2$

\shorthandon{^}
^c
$a^2+b^2=c^2$
\end{document}

Error message:

! Undefined control sequence.
l.10 ^
      c
jbezos commented 3 years ago

Confirmed.

wehro commented 3 years ago

Thank you, @jbezos. \shorthandoff*{^} and \shorthandon{^} now work as expected.

But what is the reason the following code does not work?

\documentclass{article}
\usepackage[esperanto]{babel}

\def\Off{\shorthandoff*{^}}
\def\On{\shorthandon{^}}

\begin{document}
\Off
^^51 % the letter Q
$a^2+b^2=c^2$

\On
^c
$a^2+b^2=c^2$
\end{document}

Error message:

! Missing $ inserted.
<inserted text> 
                $
l.13 ^
      c
jbezos commented 3 years ago

Fixed (so I hope).

wehro commented 3 years ago

Both examples above now run without errors, but here is the next one which does not. :(

\documentclass{article}
\usepackage[esperanto,english]{babel}

\begin{document}
\shorthandoff*{^}
^^51 % the letter Q
$a^2+b^2=c^2$

\selectlanguage{esperanto}
\shorthandon{^}
^c
$a^2+b^2=c^2$
\end{document}

Error message:

! Missing $ inserted.
<inserted text> 
                $
l.11 ^
      c
jbezos commented 3 years ago

Fixed. (Have I finally managed to do it? 🙂.)

wehro commented 3 years ago

Fixed. (Have I finally managed to do it? slightly_smiling_face.)

Yes, everything seems to work now. Thanks.