The issue of breakable highlighting was addressed in Cool Text Highlighting in LaTeX
But how, in latex, do I highlight text involving math, something like
which, right now, I do with a succession of \texthl and \colorbox.
The issue of breakable highlighting was addressed in Cool Text Highlighting in LaTeX
But how, in latex, do I highlight text involving math, something like
which, right now, I do with a succession of \texthl and \colorbox.
Is this what you intended?
\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}
\newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}}
\begin{document}
For inline math, one can simply do \hl{colored $a=b$ math}. For display math, the following works:
\begin{equation}
\mathcolorbox{red}{y=\frac{x^2}{q}}+z
\end{equation}
\end{document}
[** EDIT **]
Ok, see \hlfancy below
\documentclass{article}
\usepackage{xcolor}
\usepackage{soul}
\newcommand{\mathcolorbox}[2]{\colorbox{#1}{$\displaystyle #2$}}
\newcommand{\hlfancy}[2]{\sethlcolor{#1}\hl{#2}}
\begin{document}
For inline math, one can simply do \hl{colored $a=b$ math}. For display math, the following works:
\begin{equation}
\mathcolorbox{red}{y=\frac{x^2}{q}}+z
\end{equation}
And for the fancy version: \hlfancy{orange}{colored $a=b$ math}. Now, \hlfancy{green}{colored $a=b$ math}.
\end{document}
\hl command provided by the soul package then you can use e.g. \sethlcolor{green} but note the fragility issues mentioned in http://tex.stackexchange.com/questions/260566/how-to-reliably-switch-the-highlighting-color-with-soul
– JPi
Jul 12 '16 at 01:13
\hl in which the color is an option, namely something like inlinecolorbox{<color>}{<text with math>} As for creating a robust command, that's even more beyond me . By the way, the reason \hl had not worked for me is that instead of using $ $ to delimit math, I was using \( \) which soul does not seem to recognize.
– schremmer
Jul 12 '16 at 18:16
\hlfancy works like magic. I wish I could take the time to understand LaTeX instead of sponging. Well, thanks very much for your patience.
– schremmer
Jul 12 '16 at 21:02
$\mathcolorbox{red}{x^{2}}$ works, \colorbox cannot be replaced by \mathcolorbox in `$f(x)=\underset{\text{\textbf{code}}}{\underbrace{\colorbox{red}{$x^{2}$}}}$'
– schremmer
Jul 15 '16 at 17:30
You can also use \colorbox instead of \mathcolorbox. Here's an example:
\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\begin{document}
Here is an equation:
\begin{equation}
\colorbox{yellow}{$E = mc^2$}
\end{equation}
\end{document}
In this example, the \colorbox command is used to highlight the equation with a yellow background. The equation is enclosed in $ symbols to put it in math mode, which is required for equations. You can replace yellow with any other color that you prefer.
empheqpackage – JPi Jul 11 '16 at 21:47