
在 LaTeX 中,有諸如 、 之類的指令\textit{}
,\textbf{}
可以將文字片段設為斜體或粗體。我們可以使用不同的顏色、字體、斜體/粗體/底線修飾符來製作這樣的自訂命令嗎?例如:
\code{}
將使文字等寬,例如:「我們的程式實現了類別\code{Transformer}
」。\term{}
為了突顯定義:a term{tree} is an undirected graph in which any two vertices are connected by exactly one path
如果沒有這種可能性,最接近的模擬是什麼?
答案1
邏輯標記始終可以使用 a\newcommand{...}[1]{...}
和 using 分組來防止字體聲明或顏色設定洩漏到程式碼的其餘部分。
對於更複雜的方法,我建議使用適合相關目的的適當的套件。對於代碼標記,有minted
,listings
和tcolorbox
(及其listings
功能)
\documentclass{article}
\usepackage[x11names]{xcolor}
\newcommand{\code}[1]{{\color{blue}\texttt{#1}}}
\begin{document}
\code{int main}
\end{document}