如何在 Verbatim 環境中轉義 TeX 指令?

如何在 Verbatim 環境中轉義 TeX 指令?

我正在嘗試這個:

\documentclass{article}
\usepackage{fancyvrb}
\fvset{commandchars=\|}
\begin{document}
\begin{Verbatim}
Hello, |\textbf{world}|!
\end{Verbatim}
\end{document}

但是,我得到這個:

! Improper alphabetic constant.
<to be read again>
                   \relax
l.5 \begin{Verbatim}

我需要能夠將任何 TeX 語法放入|...|轉義符中。這樣做的正確方法是什麼?

答案1

密鑰commandchars需要三個令牌作為值;第一個表示轉義字符,另外兩個表示開始和結束參數分隔符。

\documentclass{article}
\usepackage{fancyvrb}

\fvset{commandchars=\|\{\}}

\begin{document}

\begin{Verbatim}
Hello, |textit{world}!
\end{Verbatim}

\end{document}

請注意,您不使用|before 和 after,但它替換了反斜線。

在此輸入影像描述

據我所知, or中沒有任何escapeinside功能。fancyvrbfvextra

相關內容