
我想在一個鑄造的文字框中包含一些文字/最小的 HTML 程式碼。 HTML(一對夫婦<br>
,<a href='link'>
對我來說並不重要,所以我選擇使用 minted 中的語言文字選項。但是,我想強調紅色文字中的一些不是 HTML 元素的內容。例如:
Go to this link <a href="domain.com/upload/[UPLOAD_ID]"> to find your upload.
我希望[UPLOAD_ID]
是紅色的。有什麼辦法可以做到這一點嗎?謝謝!
答案1
產生的文件有一種突出顯示文字的方法,如下所示:
據我了解,它是透過逃離minted環境並執行命令來實現的\colorbox
。可以使用該\textcolor
指令,如 user187803 所示,而不是\colorbox
使其與 minted 一起使用。
例子:
\begin{minted}[escapeinside=||]{py}
def f(x):
y = x|\textcolor{red}{**}|2
return y
\end{minted}
結果:
將其應用到您的範例中,[UPLOAD_ID]
需要使用反斜線轉義下劃線[UPLOAD\_ID]
。這是必要的,因為下劃線通常用於索引字元。但在這種情況下,下劃線應列印為下劃線,而不應解釋為從 中建立索引ID
。如果我們在這裡不使用反斜杠,將會導致錯誤。
提供的範例:
\begin{minted}[escapeinside=||]{text}
Go to this link <a href="domain.com/upload/|\textcolor{red}{[UPLOAD\_ID]}|"> to find your upload
\end{minted}
答案2
如果您不堅持使用minted
,則可以使用以下方法:
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{xcolor}
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
Go to this link <a href="domain.com/upload/\textcolor{red}{[UPLOAD_ID]}"> to find your upload.
\end{Verbatim}
\fvset{commandchars=\\\{\}}
Go to this link \Verb|<a href="domain.com/upload/\textcolor{red}{[UPLOAD_ID]}">| to find your upload.
\end{document}