0

I'm using the soul package to highlight fragments of text, using the \hl command. However, this package has problems if you have a command within the \hl command. They can usually be solved by putting the command within \mbox{}, but the problem is that if what we want to protect is a \cite command then the text inside is not breakable in multiple lines if needed, which is a problem.

My minimum working example that fails:

\documentclass[preprint,12pt,authoryear]{elsarticle}

\usepackage{color,soul}

\begin{document}
\hl{A statement \citep{ref1,ref2,ref3,ref4,ref5,ref6}}.

\bibliographystyle{elsarticle-harv} 
\bibliography{references.bib}

\end{document}

It can be partially solved by replacing \citep{...} with \mbox{\citep{...}}:

\documentclass[preprint,12pt,authoryear]{elsarticle}

\usepackage{color,soul}

\begin{document}
\hl{A statement \mbox{\citep{ref1,ref2,ref3,ref4,ref5,ref6}}}.

\bibliographystyle{elsarticle-harv} 
\bibliography{references.bib}

\end{document}

But in that case the citation text is not breakable and therefore I get the text getting out of the margin.

Another approach that I tried was to put the \citep command within {...}:

\documentclass[preprint,12pt,authoryear]{elsarticle}

\usepackage{color,soul}

\begin{document}
\hl{A statement {{\citep{ref1,ref2,ref3,ref4,ref5,ref6}}}.

\bibliographystyle{elsarticle-harv} 
\bibliography{references.bib}

\end{document}

This last one approach leads to the error "Package soul Error: Reconstruction failed".

Any idea about how to solve this? I'm really lost here...

4
  • 1
    use lualatex and the lua-ul package. With soul it won't work. Commented Sep 10, 2023 at 18:28
  • Thank you very much, this works well. However, I found 2 problems: 1) text within "{\em ...}" is not shown in italics (it is shown correctly if I compile with latex instead of lualatex; and 2) hypenation rules with "\hyphenation{...}" does not seem to work and some text exceeds the margin (this problem does not occur with latex). Any ideas about how this could be solved?
    – user173026
    Commented Sep 20, 2023 at 9:08
  • 1
    if you have a new question ask a new question. I'm not your personal support that you can ping in comments. Commented Sep 20, 2023 at 9:46
  • Use \soulregister\citep7 in the preamble
    – yannisl
    Commented Feb 8 at 3:52

1 Answer 1

0

Try this:

\documentclass[preprint,12pt,authoryear]{elsarticle}
\usepackage[many]{tcolorbox}
\newtcolorbox{mybox}[1][]{%
#1}
\begin{document}
    
    \begin{mybox}[colback=yellow, halign =left]
        A statement \citep{ref1,ref2,ref3,ref4,ref5,ref6}.
        
        \bibliographystyle{elsarticle-harv} 
        \bibliography{references.bib}
        
    \end{mybox} 
    
\end{document}
1
  • Thank you for the suggestion. This does not work for me because it creates a new paragraph with the highlighted content put within a box. Sometimes I just need to highlight a sentence or even just a word, and therefore breaking the text like with a new paragraph is not convenient.
    – user173026
    Commented Sep 18, 2023 at 12:06

You must log in to answer this question.

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