以下示例中,实现内联方程的彩色背景的最简单方法是什么:
\documentclass{article}
\begin{document}
Completely unimportant text
$ABC_{1234} = ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234}$
Some more text.
\end{document}
因此结果将如下所示:
答案1
您需要运行两次
\documentclass{article}
\usepackage{color}
\makeatletter
\def\savepos#1{\leavevmode\pdfsavepos\write\@auxout{%
\gdef\string\save@#1{{\the\pdflastxpos sp }{\the\pdflastypos sp }}}}
\def\xx#1{\expandafter\expandafter\expandafter\@firstoftwo\csname save@#1\endcsname}
\def\yy#1{\expandafter\expandafter\expandafter\@secondoftwo\csname save@#1\endcsname}
\def\hl#1#2{%
\ifx\save@a\@undefined
\else
\leavevmode\smash{\rlap{\vtop{%
\parindent\z@\parskip\z@
\leavevmode\color{yellow}\endgraf
\vskip-\baselineskip
\dimen@\xx{#1}%
\@tempdima\yy{#1}%
\@tempdimb\yy{#2}%
\loop
\ifdim\@tempdima>\@tempdimb
\leavevmode
\kern\dimexpr\dimen@-\xx{#1}\relax
\vrule width \dimexpr\xx{b}-\dimen@\relax height\ht\strutbox depth\dp\strutbox\endgraf
\dimen@\xx{a}%
\advance\@tempdima-\baselineskip
\repeat
\ifdim\@tempdima=\@tempdimb
\leavevmode
\kern\dimexpr\dimen@-\xx{#1}\relax
\vrule width \dimexpr\xx{#2}-\dimen@\relax height\ht\strutbox depth\dp\strutbox\endgraf
\fi
}}}%
\fi}
\makeatother
\begin{document}
\noindent\savepos{a}\hfill\savepos{b}
Completely unimportant text
\hl{c}{d}\savepos{c}$ABC_{1234} = ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234}$\savepos{d}
Some more text.
\end{document}