The following code is saved in test.tex
:
\documentclass{scrartcl}
\usepackage{unicode-math,xr-hyper,hyperref,cleveref}
\newtheorem{definition}{Definition}
\begin{document}
\begin{definition}[$\nvrightarrow$]\label{mylabel}
Hello, world!
\end{definition}
\end{document}
test.tex
compiles successfully with LuaLaTeX.
The following code is saved in test2.tex
:
\documentclass{scrartcl}
\usepackage{xr-hyper,hyperref,cleveref}
\externaldocument{test}[test.pdf]
\begin{document}
Hello, world!
\end{document}
This code fails to compile with LuaLaTeX. The following error message appears in test2.log
:
! Undefined control sequence.
<argument> $\nvrightarrow
$
l.5 \externaldocument{test}[test.pdf]
?
! Emergency stop.
<argument> $\nvrightarrow
$
l.5 \externaldocument{test}[test.pdf]
However, if the body of test.tex
is changed as follows (the title and the body of the definition are switched):
\begin{definition}[Hello, world!]\label{mylabel}
$\nvrightarrow$
\end{definition}
or as follows (the label is deleted):
\begin{definition}[$\nvrightarrow$]
Hello, world!
\end{definition}
then both files compile successfully.
What causes the error in the first example, and how can it be fixed?