# \nvrightarrow causes an error when it is used in the title of a definition and is referenced from another file

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?

Your label create in the aux:

\newlabel{mylabel}{{1}{1}{$\nvrightarrow$}{definition.1}{}}


\nvrightarrow is defined by unicode-math, but only at begin document. So you either should provide a definition for the command in your other document or should load unicode-math there too, and then should load the external file after begin document.

\documentclass{scrartcl}
\usepackage{unicode-math}
\usepackage{xr-hyper,hyperref,cleveref}

\begin{document}
\externaldocument{test}[test.pdf]
Hello, world!

\end{document}


Looks like unicode-math is responsible for the trouble? I updated test.tex as follows

\documentclass{scrartcl}

\usepackage{stix}
\usepackage{xr-hyper,hyperref,cleveref}
%\usepackage{unicode-math,xr-hyper,hyperref,cleveref}
\newtheorem{definition}{Definition}

\begin{document}
\begin{definition}[{$\nvrightarrow$}]\label{mylabel}
Hello, world!
\end{definition}
\end{document}


and updated test2.tex as follows

\documentclass{scrartcl}
\usepackage{stix}
\usepackage{xr-hyper,hyperref,cleveref}
\externaldocument{test}[test.pdf]
\begin{document}
Hello, world!
\end{document}


The generated pdf files (using lualatex) look like the following:

• Thanks. The problem is that the minimal example that I gave is a substitute for a much larger file that may have other dependencies on unicode-math. Replacing unicode-math by stix is very risky for me, and I'd rather avoid it if possible. Jul 11, 2021 at 15:11
• @EvanAad, in that case, perhaps you can add \usepackage{stix} to test2.tex to avoid that undefined error of \nvrightarrow. I gave it a try and it seemed to be OK. Jul 11, 2021 at 16:35