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}
safex
  • 145

1 Answers1

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

Bernard
  • 271,350