我正在为编程入门课程创建参考文档。作为其中的一部分,我将提供语法定义和语法示例。
为了编写此代码,我希望使用如下的 LaTeX 语法:
\begin{myenv}
% syntax-highlighted syntax definitions
<stuff> <here> <type> <name>(<args>) { <body> }
\tcblower % or better yet, some marker \StartExamples.
% Escaping with @...@ would obviously be ok here.
% syntax-highlighted examples of syntax being defined.
public static void Main(string[] args) { ... }
\end{myenv}
这将给我一个可爱的两部分 tcolorbox,其中虚线穿过框将抽象定义与具体示例分开。语法当然是解决方案的次要部分……
遗憾的是,如果我实际上\tcblower
在上面使用(在里面转义@@
),我会得到一个吨錯誤數字:
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error LaTeX Error: \begin{Verbatim} on input line 1 ended by \end{tcb@savebox}.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Missing } inserted.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
_minted-mwe/5C20B662D879F... 5 Error Extra }, or forgotten \endgroup.
mwe.tex 32 Error File ended while scanning use of \FancyVerbGetLine.
mwe.tex 32 Error FancyVerb Error:
生成的文件位于_minted-mwe/5C...
:
\begin{Verbatim}[commandchars=\\\{\},codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}]
\PYG{esc}{\csparam{access modifiers}} \PYG{esc}{\csparam{type}} \PYG{esc}{\csparam{name}}\PYG{p}{(}\PYG{esc}{\csparam{parameter definitions\dots}}\PYG{p}{)} \PYG{p}{\PYGZob{}}
\PYG{esc}{\csparam{method body}}
\PYG{p}{\PYGZcb{}}
\PYG{esc}{\tcblower}
\PYG{k}{public} \PYG{k}{void} \PYG{n+nf}{SayHello}\PYG{p}{(}\PYG{k+kt}{string} \PYG{n}{name}\PYG{p}{)} \PYG{p}{\PYGZob{}}
\PYG{n}{Console}\PYG{p}{.}\PYG{n}{WriteLine}\PYG{p}{(}\PYG{l+s}{\PYGZdq{}Hello, \PYGZdq{}} \PYG{p}{+} \PYG{n}{name}\PYG{p}{)}\PYG{p}{;}
\PYG{p}{\PYGZcb{}}
\end{Verbatim}
我怀疑这里的问题也出在群体层面(参考) 假设\tcblower
最终位于 内\PYG{esc}{\tcblower}
。我以前知道\PYG
最终位于何处,但如果有人说它在扩展后不是“裸露的”,我会相信它,因为 tcolorbox 可能正在期待。
如果我不转义对 的调用\tcolorbox
,它将被解释为 C# 代码并显示一个红色方框,表示语法错误。因此,转义它是非常必要的。
平均能量损失
% arara: lualatex: { shell: yes }
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{minted}
\tcbuselibrary{minted,xparse}
\NewTCBListing{cssyntax}{O{}m}{
minted language={csharp},
adjusted title={Syntax Reference: #2},
float,
#1
}
\setminted{
escapeinside=@@,
}
% the real one is more sophisticated, but for MWE's sake
\newcommand\csparam[1]{$\langle\textit{#1}\rangle$}
\begin{document}
\begin{cssyntax}{Method Use}
@\csparam{access modifiers}@ @\csparam{type}@ @\csparam{name}@(@\csparam{parameter definitions\dots}@) {
@\csparam{method body}@
}
@\tcblower@ % - - - - - - - - - - - - - - - - - - - -
public void SayHello(string name) {
Console.WriteLine("Hello, " + name);
}
\end{cssyntax}
\end{document}