2

I want to highly text which contains math in shades of grey with allowing for linebreaks. Based on this excellent post, I tried:

\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}
\newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}}
\newcommand{\hlfancy}[2]{\sethlcolor{#1}\hl{#2}}

\begin{document}
This works: \hlfancy{gray}{colored $a=b$ math}.  
This does not:  \hlfancy{gray!60}{colored $a=b$ math}.  
\end{document}
4

Here is a solution:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{soul}

\newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}}
\newcommand{\hlfancy}[2]{\colorlet{hlcolor}{#1}\sethlcolor{hlcolor}\hl{#2}}

\begin{document}

This works: \hlfancy{gray}{colored $a=b$ math}.
This also works: \hlfancy{gray!30!Lavender}{colored $a=b$ math}.

\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.