4

Here's the MWE:

\documentclass{article}

\usepackage{soul}
\usepackage{pdfcomment}

\begin{document}

\section*{\hl{Fine}}

\section{\hl{Error}}

\end{document}

which gives the following error message:

! Use of \SOUL@n doesn't match its definition.
\SOUL@ulunderline #1->{\setbox \z@ \hbox {#1}
                                             \dimen@ =\wd \z@ \dimen@i =\SOU...
l.10 \section{\hl{Error}}

?

The unnumbered section works fine. Also, when I remove the package pdfcomment, everything works.

4 Answers 4

5

pdfcomment loads hyperref, and hyperref has no idea what to do with \hl in the bookmarks and then errors. Use e.g. \texorpdfstring to provide an alternate text for the bookmarks:

\documentclass{article}

\usepackage{soul}

\usepackage{hyperref}


\begin{document}

\section*{\hl{Fine}}

%\section{\hl{Error}}

\section{\texorpdfstring{\hl{Fine}}{Fine}}

\end{document}

As an alternative you can make \hl protected

\usepackage{etoolbox}
\AtBeginDocument{\robustify\hl}

Then hyperref will drop the command at the cost of a warning:

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `\hl' on input line 74.
5

The problem is due to the bookmarks. Make \hl to just return its argument when making the bookmark.

\documentclass{article}

\usepackage{soul}
\usepackage{pdfcomment}
%\usepackage{hyperref}

\makeatletter
\pdfstringdefDisableCommands{\let\hl\@firstofone}
\makeatother


\begin{document}

\section*{\hl{Fine}}

\section{\hl{Fine as well}}

\end{document}

enter image description here

1

A quick look at pdfcomment documentation shows that it loads soulpos, which in turns loads soulutf8, which is a soul replacement. So you should check whether you're still missing some feature with just loading pdfcomment.

1

pdfcomment redefines commands in a way that are incompatible with soul. If you are able to use LuaLaTeX, here's a possible solution (using lua-ul instead):

\documentclass{article}

\usepackage{xcolor,luacolor,lua-ul}
\LuaULSetHighLightColor{yellow}
\usepackage{pdfcomment}

\begin{document}

\section*{\highLight{Fine}}
\section{\highLight{Error}}

\end{document}

Note how I had to change \hl to \highLight in the code, as the soul compatibility mode also failed.

2
  • no it has nothing to do with redefinitions of pdfcomment. Jul 17, 2022 at 8:47
  • My wording might have been imprecise. There is, at any rate, a conflict over \hl.
    – Ingmar
    Jul 17, 2022 at 8:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .