Latex高亮文本,简单有效——overleaf也可以用

https://blog.csdn.net/ShuqiaoS/article/details/118217508

普通文本高亮

效果是这样的:

首先在开头使用:
\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}

本文作者:我救自己万万次

本文链接:https://www.cnblogs.com/phdLi-accumulation/p/18578151

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   我救自己万万次  阅读(616)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.