# Showkeys and Unicode-math conflict

I am using showkeys and unicode-math packages but got the following error

! Missing \$ inserted.


This is a minimal example:

\documentclass{article}
\usepackage{showkeys}
\usepackage{unicode-math}
%\setmathfont{texgyrepagella-math.otf}
\begin{document}
\begin{figure}
\caption{something}\label{fig}
\end{figure}
\ref{fig}
\end{document}


showkeys relies on the fact that \underbar can be used also in text, which is not true any more for \underbar as redefined by unicode-math.

Workaround: save the original meaning of \underbar and make showkeys use it instead of the redefined \underbar.

\documentclass{article}
\usepackage{showkeys,etoolbox}
\makeatletter
\let\latex@underbar\underbar
\patchcmd{\SK@@ref}{\underbar}{\latex@underbar}{}{}
\makeatother

\usepackage{unicode-math}
%\setmathfont{texgyrepagella-math.otf}
\begin{document}
\begin{figure}
\caption{something}\label{fig}
\end{figure}
\ref{fig}
\end{document}


Who's at fault? I point to showkeys that uses the undocumented \underbar command, which is present in the LaTeX kernel just because it is in Plain and in the olden times users frequently transferred documents from Plain TeX to LaTeX.

• Surely it must be the other guy's fault! (anyway showkeys is older than latex2e:-) – David Carlisle Oct 22 '14 at 12:07