用黄色突出显示句子,以表示特定命令,例如斜体

用黄色突出显示句子,以表示特定命令,例如斜体

目的

使用该命令来更改出现斜体单词的句子的背景颜色\textit{}

最小工作示例(MWE)

\documentclass[12pt]{report}
\usepackage{ragged2e}
\usepackage{soul}
\usepackage{xcolor}

\begin{document}

This is an example of a sentence that I DO NOT want to highlight. This is an example of a \textit{sentence} that I want to highlight. This is an example of a sentence that I DO NOT want to highlight.

\end{document}

首选结果

使斜体句子以黄色突出显示。

答案1

请尝试以下操作:

\documentclass[12pt]{report}
\usepackage{ragged2e}
\usepackage{soul}
\usepackage{xcolor}

\let\oldtextit\textit                           % <---
\renewcommand{\textit}[1]{\oldtextit{\hl{#1}}}  % <---


\begin{document}

This is an example of a sentence that I DO NOT want to highlight. This is an example of a \textit{sentence} that I want to highlight. This is an example of a sentence that I DO NOT want to highlight.

\end{document}

在此处输入图片描述

这是您在评论中问我的吗?

相关内容