![无法在 tcolorbox 环境列表选项中使用 moredelim](https://linux22.com/image/346897/%E6%97%A0%E6%B3%95%E5%9C%A8%20tcolorbox%20%E7%8E%AF%E5%A2%83%E5%88%97%E8%A1%A8%E9%80%89%E9%A1%B9%E4%B8%AD%E4%BD%BF%E7%94%A8%20moredelim.png)
我有一个tcolorbox
+listings
驱动的环境,例如终端会话 - 我想在用户输入前加上前缀,以将其(通过颜色/重量/等)与计算机输出区分开来。
用 定义分隔\lstset
符很好,但我不能在 中使用相同的定义listing options
。\newtcblisting
相反,TeX 突然决定它需要输入一个文件才能自我感觉良好。
平均能量损失
\documentclass{article}
\usepackage{listings}
\newif\ifbroken
\brokentrue % toggle me!
\ifbroken
\usepackage[most]{tcolorbox}
\newtcblisting{exampleoutput}{
listing options={
moredelim=[il][\bfseries]{>>},
}
}
\else % works just fine
\lstset{moredelim=[il][\bfseries]{>>}}
\fi
\begin{document}
\ifbroken
\begin{exampleoutput}
>>hello
\end{exampleoutput}
\else
\begin{lstlisting}
>>hello
\end{lstlisting}
\fi
\end{document}
ERROR: Package Listings Error: File `[(.tex)' not found.
--- TeX said ---
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)
Enter file name:
./mwe.tex:27: Emergency stop.
<read *>
l.27 \end{exampleoutput}^^M
--- HELP ---
From the .log file...
*** (cannot \read from terminal in nonstop modes)
答案1
必须将within选项括起来,以[...]
防止选项处理的脆弱性(即如何将此选项传输到环境及其可选参数。)moredelim
{...}
tcolorbox
listings
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\newif\ifbroken
\brokentrue % toggle me!
\ifbroken
\usepackage[most]{tcolorbox}
\newtcblisting{exampleoutput}{
listing options={{
moredelim=[il][\bfseries]{>>}},
}
}
\else % works just fine
\lstset{moredelim=[il][\bfseries]{>>}}
\fi
\begin{document}
\ifbroken
\begin{exampleoutput}
>>hello
\end{exampleoutput}
\else
\begin{lstlisting}
>>hello
\end{lstlisting}
\fi
\end{document}