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}
1

1 Answer 1

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

You must log in to answer this question.

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