3

I have found that highlighting mathematical formulas with soul package does not work if the nag package is used with l2tabu option. A minimal (not) working example is:

\documentclass{book}

\RequirePackage[l2tabu, orthodox]{nag}
\usepackage{soul}

\begin{document}
\hl{$0.47\pm0.06$}
\end{document}

However, if l2tabu option is omitted, everything works fine. Note that if not highlighting math, but normal text, my minimal example will work. The question is why such behavior and how can this be improved?

1

Short answer: soul is not compatible with nag.

Preferred answer: avoid nag, it does nothing that can't be obtained by using correct style to begin with; avoid soul, too.

Longer answer: if you really need both packages

\RequirePackage[l2tabu, orthodox]{nag}
\documentclass{book}

\usepackage{soul}
\usepackage{etoolbox}
%\usepackage{hyperref} % try with and without it

\makeatletter
\@ifpackageloaded{nag}{%
\patchcmd{\SOUL@eval}
  {\ifcat$\noexpand\SOUL@@}% old test
  {\ifx\nag@maybedispmath\SOUL@@}% new test
  {}{}

% the argument of \SOUL@addmath must be delimited by active $
\begingroup\lccode`\~=`\$
\lowercase{\endgroup\def\SOUL@addmath~#1~}{%
    {\let\protect\noexpand
    \edef\x{\global\SOUL@word={\the\SOUL@word{{\hbox{$#1$}}}}}\x}%
    \SOUL@scan
}
}{}% end of \@ifpackageloaded
\makeatother

\begin{document}

\hl{$0.47\pm0.06$}
\end{document}

Remember that nag must be loaded before \documentclass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.