![我可以在 \lstinline 的參數中使用管道字元嗎?](https://rvso.com/image/305771/%E6%88%91%E5%8F%AF%E4%BB%A5%E5%9C%A8%20%5Clstinline%20%E7%9A%84%E5%8F%83%E6%95%B8%E4%B8%AD%E4%BD%BF%E7%94%A8%E7%AE%A1%E9%81%93%E5%AD%97%E5%85%83%E5%97%8E%EF%BC%9F.png)
我正在使用 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
\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}