【已解决】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}
  • 31
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值