tcblisting 的新环境定义问题

tcblisting 的新环境定义问题

我有以下用于新环境定义的代码:

\newenvironment{VList}
{
\makeatletter
\begin{tcblisting}
\bgroup
  enhanced,oversize,lower separated=false,
  colframe=red!50!black,colback=yellow!10!white,
  interior style=\bgroup 
  top color=yellow!5!white,bottom color=yellow!20!white
  \egroup ,
  listing side comment,sidebyside gap=5mm,
  listing options=\bgroup 
  style=tcblatex,texcsstyle=*\color\bgroup
  red!70!black\egroup
  \egroup,
\egroup\makeatother
}
{
\makeatletter\end{tcblisting}\makeatother
}

但是,当我在LaTeXframe中输入以下代码时,会出现以下问题:beamer

\begin{frame}[fragile]{Sample GNUPLOT code}{A {\tt gnuplot} and \LaTeX{} combo}
Start {\tt gnuplot}, and write the following codes:
\begin{VList}
set term tikz color solid size 4in,3in
set output "sin.tex"
set xr [-2*pi:2*pi]
plot sin(x) with lines
exit
\end{VList}
\end{frame}

答案1

\bgroup首先, /对似乎存在一些问题\egroup。由于我目前无法理解的原因,它们在逐字上下文中的行为有所不同。将它们替换为{and后},会出现'普通的'错误可以通过用相应的宏替换\begin{tcblisting}和来解决\end{tcblisting}。以下编译:

\documentclass{beamer}

\usepackage[most]{tcolorbox}

\newenvironment{VList}
{\tcblisting{
  enhanced,oversize,lower separated=false,
  colframe=red!50!black,colback=yellow!10!white,
  interior style={top color=yellow!5!white,bottom color=yellow!20!white},
  listing side comment,sidebyside gap=5mm,
  listing options={style=tcblatex,texcsstyle=*\color{red!70!black}}%
}
}{%
\endtcblisting%
}

\begin{document}

\begin{frame}[fragile]{Sample GNUPLOT code}{A {\tt gnuplot} and \LaTeX{} combo}
Start {\tt gnuplot}, and write the following codes:
\begin{VList}
set term tikz color solid size 4in,3in
set output "sin.tex"
set xr [-2*pi:2*pi]
plot sin(x) with lines
exit
\end{VList}
\end{frame}

\end{document}

但是,我建议使用环境生成程序来\newtcblisting处理一切:

\documentclass{beamer}

\usepackage[most]{tcolorbox}

\newtcblisting{VList}{
  enhanced,oversize,lower separated=false,
  colframe=red!50!black,colback=yellow!10!white,
  interior style={top color=yellow!5!white,bottom color=yellow!20!white},
  listing side comment,sidebyside gap=5mm,
  listing options={style=tcblatex,texcsstyle=*\color{red!70!black}}%
}

\begin{document}

\begin{frame}[fragile]{Sample GNUPLOT code}{A {\tt gnuplot} and \LaTeX{} combo}
Start {\tt gnuplot}, and write the following codes:
\begin{VList}
set term tikz color solid size 4in,3in
set output "sin.tex"
set xr [-2*pi:2*pi]
plot sin(x) with lines
exit
\end{VList}
\end{frame}

\end{document}

相关内容