【已解决】Latex高亮文本,简单有效

普通文本高亮

效果是这样的:

首先在开头使用:

usepackage{soul, color, xcolor}

之后在需要高亮的地方使用:

hl{文本}

(注意,如果应用了hl但是没有反应或者高亮有问题,多半是由于没有包含color和xcolor的缘故)

如果希望修改颜色,可以使用:

sethlcolor{颜色}
hl{文本}

注意,如果使用过sethlcolor{颜色},则后面的颜色都会沿用上一个设置的颜色,因此如果中间需要修改颜色要记得重新设置。

如果文本中有cite, ef这一类的句柄,会导致报错,此时要在文章开头加上:

soulregister{cite}7 % 注册cite命令
soulregister{citep}7 % 注册citep命令
soulregister{citet}7 % 注册citet命令
soulregister{
ef}7 % 注册
ef命令
soulregister{pageref}7 % 注册pageref命令

章节标题高亮

章节标题使用:

sethlcolor{yellow}
section{	exorpdfstring{hl{xxx}}{xxx}}

公式高亮

documentclass{article}


usepackage{xcolor}
usepackage{soul}

ewcommand{mathcolorbox}[2]{colorbox{#1}{$displaystyle #2$}}

egin{document}
For inline math, one can simply do hl{colored $a=b$ math}.  For display math, the following works:
egin{equation}
mathcolorbox{red}{y=frac{x^2}{q}}+z
end{equation}  
end{document}

另一种高亮方法

documentclass{article}


usepackage{xcolor}
usepackage{soul}

ewcommand{mathcolorbox}[2]{colorbox{#1}{$displaystyle #2$}}

ewcommand{hlfancy}[2]{sethlcolor{#1}hl{#2}}

egin{document}
For inline math, one can simply do hl{colored $a=b$ math}.  For display math, the following works:
egin{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}
经验分享 程序员 微信小程序 职场和发展