我可以在 \lstinline 的參數中使用管道字元嗎?

我可以在 \lstinline 的參數中使用管道字元嗎?

我正在使用 Listings 包,我想詢問是否可以|\lstinline命令中使用管道字符,因為它使用管道作為開始和結束字符。

\documentclass[]{article}
\usepackage{listings}
\begin{document}
Here's some text and an if-statement: \lstinline|if(a == 5 || b == 3)|. %Not working as lstinline stops after the first character of the 'or'-sign |
\end{document}

謝謝你的幫忙!

答案1

來自listings 文件(部分4.2 清單排版):

\lstinline[<key=value list>]<character><source code><same character>

工作方式類似於\verb但尊重活躍的語言和風格。除非可選參數中另有要求,否則這些清單使用靈活的列,並且不支援框架或背景顏色。你可以寫 \lstinline!var i:integer;!並獲取var i:integer;。由於該命令首先查找可選參數,因此如果您想使用[as ,則必須至少提供一個空參數<character>

所以,只要使用就<character>必須使用<same character>來關閉內聯列表(實驗性的{...}用法除外)。選擇與您的內聯用法不衝突的字元:

在此輸入影像描述

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
Here's some text and an if-statement: \lstinline!if(a == 5 || b == 3)!.

Or there is \lstinline+if(a != 3 && b !=3 || c != 4)+.
\end{document}

相關內容