考虑一下这个 MWE
\documentclass{article}
\usepackage{graphicx,etoolbox}
\PassOptionsToPackage{final}{listings}
\usepackage[%
skins
,listings
,breakable
,xparse
,documentation
]{tcolorbox}
\NewDocumentCommand\MySmallFigure{o m m m m}{%
\begin{figure}[#2]%
\parbox[b][][b]{78mm}{#3}%
\hspace{6mm}%
\begin{minipage}[b]{\dimexpr\linewidth-78mm-6mm\relax}%
\caption[#1]{#4}%
\label{#5}%
\end{minipage}%
\end{figure}%
}
\AtBeginDocument{%
\newtcblisting[%
auto counter,
blend into=listings
]{codetext}[2][]{%
label = #2,
listing and text,
#1,
}}
\begin{document}
% This works
\MySmallFigure%
[anyone]%
{tb}%
{\includegraphics[width=\linewidth]{example-image-a}}%
{An image ....}%
{example-image-a}
% This doesn’t, since its a figure environment inside a tcolorbox.
\begin{codetext}{figure}
\MySmallFigure%
[anyone]%
{tb}%
{\includegraphics[width=\linewidth]{example-image-a}}%
{An image ....}%
{example-image-a}
\end{codetext}
\end{document}
我想显示该命令的用法,然后显示/\MySmallFigure
内该命令的结果。tcolorbox
tcblisting
但 ...
./tcbfigure.listing:1: LaTeX 错误:不在外部模式。
...显然,我忽略了一些东西。