2

When I use the soul package combined with the cite package to highlight some text that contains tilde and citation (e.g. \hl{Ref.~\cite{xyz}}, I get unwanted extra space between the word "Ref." and the citation number.

enter image description here

I put tilde here because I don't want LaTeX to interpret the dot as the end of the sentence.

Here is my MWE:

\documentclass{article}
\usepackage{xcolor,soul}
\soulregister\cite7
\usepackage{cite} % error disappears without this package


\begin{document}
\hl{Ref.~\cite{xyz}}

Ref.~\cite{xyz}
\end{document}

Here, I have used \soulregister\cite7 as suggested in How to make \hl (highlighting) to automatically place incompatible commands in \mbox?

I need the cite package to contract [1,2,3,4] to [1-4] (I don't have this in MWE, but I do in my actual document).

  • 3
    I get the same space with and without the \hl. Does your MWE really show the behaviour on your system? Is your system up-to-date? – Ulrike Fischer Jun 23 '15 at 7:43
  • @UlrikeFischer Yes you're right. Thanks. I forgot to add \usepackage{cite} in my MWE. Now it has been added. I need this package to contract [1,2,3,4] to [1-4]. – Indra Yudhistira Jun 24 '15 at 3:44
  • @LaRiFaRi Thanks for your suggestion. I've implemented in my MWE. – Indra Yudhistira Jun 24 '15 at 3:51
  • I shortened your MWE a bit, as the important part was not clearly visible. Also note, that you may delete everything about dot and tilde as well. Ref \cite{x} will result in the same error. – LaRiFaRi Jun 24 '15 at 7:22
2

The problem is not the tilde but the fact that the package cite seems to check for missing white space in front of the citation. With cite loaded, A \cite{x}, A~\cite{x}, and A\cite{x} result in the very same. All of them get one white space in front of your [<number>].

The error we are getting now, is that cite seems to have problems in finding leading white space inside the \hl{} command. It does not find any and adds it every time. Therefore, an easy workaround would be to put the \cite command always directly behind the word Ref.. This saves you from typing tildes as well.

% arara: pdflatex

\documentclass{article}
\usepackage{xcolor,soul}
\soulregister\cite7
\usepackage{cite}


\begin{document}
\hl{Ref.\cite{xyz}}

Ref.\cite{xyz} % cite adds the correct white space here

Ref. \cite{xyz} % cite converts the white space to a tilde

Ref.~\cite{xyz} % everything done manually
\end{document}

enter image description here

  • 2
    another possibility: load cite with the noadjust option to disable its handling of spaces before a cite – Robert Jun 24 '15 at 14:42
  • Hi @LaRiFaRi I see. Thanks for the explanation on how cite package handles white space before citation. – Indra Yudhistira Jun 28 '15 at 6:11

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.