1

I already read the discussions about this error, but nothing helpfull. My MWE

\documentclass{minimal}
\usepackage{xcolor}
\usepackage{soul}
%\soulregister{\cl}{7} irrelevant
%\soulregister{\sethlcolor}{7}
\definecolor{inlineBG}{HTML}{F1F1F1}
\newcommand{\cl}[2]{\textcolor[HTML]{#1}{#2}}

\newcommand{\codeinline}[1]{%
  \sethlcolor{inlineBG}{%
  \texttt{\hl{#1}}}%
}

\begin{document}

% ok :
\codeinline{ {\cl{FF0000}{Hello}} }

% Package soul Error: Reconstruction failed.
\codeinline{ {\cl{FF0000}{Hellooooooooooooooooooooooooooooooooooooooooo}} }

\codeinline{ {\cl{FF0000}{Hello World}} }

\end{document}

the first \codeinline works fine, not the others. How can i fix it ?

  • See my answer here for a possible solution: tex.stackexchange.com/a/404905/31729. Don't use the minimal class! – user31729 Jan 19 '18 at 19:31
  • I've already try \soulregister{\sethlcolor}{7} same issue. – nikopol Jan 19 '18 at 19:35
  • @nikopol: Your code does not reveal that you used \soulregister – user31729 Jan 19 '18 at 19:37
  • @ChristianHupfer \soulregister isn't relevant in my mwe because the issue is the same with or without it – nikopol Jan 20 '18 at 13:57
  • @nikopol: It would have been nice to add it to the question such that others do not have to suggest \soulregister again ... but it's your question of course. – user31729 Jan 20 '18 at 17:37
4

In a similar situation, I found the help text provided by the soul package quite useful. It suggests to wrap the text inside an mbox. Indeed, if you change your definition to

\newcommand{\codelinline}[1]{%
  \sethlcolor{inlineBG}{%
  \texttt{\hl{\mbox{#1}}}}%
}

your MWE works for me. There might be issues with hyphenation if the text inside \codeline is long. (Seems to be a limitation of soul generally.)

  • hyphenation will not work not because a limitation of soul but because there is never a line break (and so hyphenation) in a \mbox{}. – Ulrike Fischer Feb 2 '18 at 10:23
  • @Ulrike: You're right. What I meant was: with the \mbox, hyphenation will not work, but without the \mbox the soul package has problems. Actually, the help text printed by soul for the OP's error says: "I came across hyphenatable material enclosed in group braces, which I can't handle". It's explained in §8 and §9 in section 2.1 of the soul manual. – ThV Feb 2 '18 at 10:37
1
+50

It won't work. The word-/syllable analyzer of soul is rather fragile and a complicated command like \textcolor throws it out of the track. If you want to color the text, you should call the color before the \hl. Small bit of colors can be hidden in a \mbox:

\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}

\definecolor{inlineBG}{HTML}{F1F1F1}
\definecolor{inlineFG}   {HTML}{FF0000}
\newcommand{\codeinline}[1]{{%
  \sethlcolor{inlineBG}%
  \color{inlineFG}%
  \ttfamily
  \hl{#1}%
}}

\begin{document}

% ok :
\codeinline{Hello}

\codeinline{Hellooooooooooooooooooooooooooooooooooooooooo}

\codeinline{Helloooooooooo\mbox{\textcolor{green}{oooo}}ooooooooooooooooooooooooooo}
\end{document}

enter image description here

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.