1

I would like to highlight text including user-defined commands with linebreaks. I found a solution for linebreaks (Colorbox does not linebreak), but the \ctext{} command cannot treat other commands in its argument.

My MWE is as follows:

\documentclass{article}

\usepackage{lipsum} \usepackage{xcolor} \usepackage{soul} \usepackage{etoolbox} \usepackage{ifmtarg}

\newcommand{\red}[1]{{\color{red} #1}}

\newcommand{\ctext}[3][RGB]{% \begingroup \definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}% \hl{#3}% \endgroup }

%Frame of command '\spec' \newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}} \newrobustcmd{\spec}[1]{% \ifcsname spec@#1\endcsname% \csuse{spec@#1}% \else \GenericError{}{Undefined species `#1'}{}{} \fi }

\defineSpecies{h216o}{H$_2^{~16}$O}

\begin{document}

\ctext[RGB]{0,209,0}{\red{\spec{h216o}}}

\end{document}

TobiR
  • 584
  • 2
    If you're using LuaTeX use the lua-ul package instead of the soul package. Else the ulem package is more robust than the soul package, but inside of ulem you get no automatic hyphenation. – Skillmon Apr 18 '23 at 09:31
  • @Skillmon So the ctext command cannot be repaired? And what command do you think about in ulem? – TobiR Apr 18 '23 at 09:37
  • 1
    well, see soul's documentation, it states a list of stuff that doesn't work (not sure whether that list is exhaustive), in summary: soul is not stable and only works for simple stuff. I think ulem doesn't have a \hl-like command out of the box, but you can define it yourself (you should be able to find examples on this site). – Skillmon Apr 18 '23 at 10:59
  • 2
    As @Skillmon wrote: use lualatex and the lua-ul package. Everything else has shortcomings. – Ulrike Fischer Apr 18 '23 at 11:49
  • 1
    @TobiR Can you give some examples? The question is too generic to receive sensible answers. We now have \text_expand:n which might be what you want. – egreg Apr 18 '23 at 15:22
  • @egreg Thanks for dealing with this issue. I have updated my question, including an ifmtarg-based command. – TobiR Apr 18 '23 at 15:37

0 Answers0