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

文章目录

普通文本高亮章节标题高亮公式高亮

普通文本高亮

效果是这样的:

首先在开头使用:

\usepackage{soul, color, xcolor}

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

\hl{文本}

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

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

\sethlcolor{颜色}

\hl{文本}

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

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

\soulregister{\cite}7 % 注册\cite命令

\soulregister{\citep}7 % 注册\citep命令

\soulregister{\citet}7 % 注册\citet命令

\soulregister{\ref}7 % 注册\ref命令

\soulregister{\pageref}7 % 注册\pageref命令

章节标题高亮

章节标题使用:

\sethlcolor{yellow}

\section{\texorpdfstring{\hl{xxx}}{xxx}}

公式高亮

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

另一种高亮方法

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

2025-11-05 17:59:00
完蛋!逆水寒要直接免费了,整个端游圈都疯了
揭秘2023年最受欢迎的5款时时彩计划软件评测