Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Here is a minimal example showing the problem.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{color}
\usepackage{soul}
%\soulregister{\ref}{1}
\begin{document}

\section*{x}\label{x}

\section*{y}
\hl{ Some text.
  Section~\ref{x}.
}
\end{document}

I'm getting the error

LaTeX Warning: Reference `{x}' on page 0 undefined on input line 12.

! Argument of \ref has an extra }.

The problem is with \ref. Commenting out the line beginning with "Subsection" makes the error disappear. \soulregister is intended for font commands. I don't know if \ref is a font command, but I could not get \soulregister to fix the problem (see the commented line above).

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

Enclosing the \ref{x} in { } works. soul then takes it as one element instead of breaking it up, I guess. It seems to me that it reads both \ref and {x} in two steps and sets it together again while adding another set of braces, i.e. the result is \ref{{x}}. This doesn't matter much for font commands but \ref takes the inner braces as part of the label name. This causes the warning about the unknown label. The error is caused because \ref is then also expanded by soul inside a { } group, i.e. {\ref}. Don't ask me why.

Note that you can't label a \section* because it doesn't has a number.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{color}
\usepackage{soul}
%\soulregister{\ref}{1}
\begin{document}

\section{x}\label{x}

\section{y}
\hl{ Some text.
   Section~{\ref{x}}.
}
\end{document}
share|improve this answer
    
Indeed it does. Can you explain why my version failed, and why the extra brackets fix it? I take it \ref is not a font command then? –  Faheem Mitha Jul 17 '11 at 18:48
    
@Faheem: See my recent edit. \ref is not a font command. It doesn't change the font. –  Martin Scharrer Jul 17 '11 at 18:50
    
Thanks for the clarification. –  Faheem Mitha Jul 17 '11 at 18:51
    
Is it worth reporting this as a bug? –  Faheem Mitha Jul 17 '11 at 19:00
    
@FaheemMitha: I would check the documentation first if this is explicitly mentioned. –  Martin Scharrer Jul 17 '11 at 19:07
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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