tcblisting 显然不是一个逐字环境

tcblisting 显然不是一个逐字环境

平均能量损失

% arara: pdflatex
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{listing options={language=ruby}}
"hello #{world}"
\end{tcblisting}
\end{document}

上面的代码将崩溃#并出现熟悉的错误(就像您在正常正文中使用它一样)。(实际上,我使用的是mintedTypeScript 突出显示`hello ${world}` - 错误类似。)转义字符可让代码编译,但完整的转义序列会进入输出(有趣的是)。


搜索引擎索引的错误文本:

当您包含以下内容时会发生此错误#

ERROR: You can't use `macro parameter character #' in horizontal mode.

--- TeX said ---
l.1 "hello #
            {world}"
--- HELP ---
The special character # has appeared in ordinary text. You probably
meant to type \#.

当您包含以下内容时会发生此错误$

ERROR: Missing $ inserted.

--- TeX said ---
<inserted text> 
                $
l.8 \end{tcblisting}

--- HELP ---
TeX probably found a command that can be used only in math mode when
it wasn't in math mode.  Remember that unless stated otherwise, all
all the commands of Section 3.3 in LaTeX Book (Lamport) can be used
only in math mode. TeX is not in math mode when it begins processing
the argument of a box-making command, even if that command is inside a
math environment. This error also occurs if TeX encounters a blank
line when it is in math mode.

答案1

您缺少listing only。否则,它会尝试排版内容(在下部将其评估为 TeX)。

% arara: pdflatex: { shell: yes }
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{listing only, listing options={language=ruby}}
"hello #{world}"
\end{tcblisting}
\end{document}

相关内容