我正在尝试使用 Metapost 中的 minipage 逐字逐句地输入文本。它似乎在 Metapost 之外有效,但在里面无效。任何帮助都将不胜感激。
\documentclass{article}
\usepackage{luamplib}
\usepackage{fancyvrb}
\begin{document}
\begin{minipage}[t]{20em}
\begin{Verbatim}
sample text 1
sample text 2
sample text 3
\end{Verbatim}
\end{minipage}
\begin{mplibcode}
beginfig(1);
draw (0,0)--(10,-10) ;
label(btex
\begin{minipage}[t]{20em}
\begin{Verbatim}
sample text 1
sample text 2
sample text 3
\end{Verbatim}
\end{minipage}
etex,(30,-30));
endfig;
\end{mplibcode}
\end{document}
------------------------- the 2nd question ------------------------------
to meet the policy of site, my previous message was relocated.
Thanks Henri
I tried to use \verbbox as below without success yet.
\documentclass{article}
\usepackage{luamplib}
\usepackage{fancyvrb}
\newbox\verbbox
\begin{document}
\setbox\verbbox=\vbox{\hsize=15cm
\begin{Verbatim}
sample text 1
sample text 2 sample text 21
sample text 3 sample text 31 sample text 32
\end{Verbatim}
}
before verbbox \\
\box\verbbox \\
after verbbox
\begin{mplibcode}
beginfig(1);
label(btex ~ etex, origin) ;
label(btex
\begin{minipage}[t]{16cm}
\box\verbbox
\end{minipage}
etex, (15,-15)) ;
drawarrow (0,0)--(30,-30) ;
endfig ;
\end{mplibcode}
\end{document}
答案1
您可以使用SaveVerbatim
:
\documentclass{article}
\usepackage{luamplib}
\usepackage{fancyvrb}
\begin{document}
\begin{SaveVerbatim}{exampleA}
sample text 1
sample text 2
sample text 3
\end{SaveVerbatim}
\begin{mplibcode}
beginfig(1);
draw (0,0)--(10,-10) ;
label(btex \BUseVerbatim{exampleA} etex,(30,-30));
endfig;
\end{mplibcode}
\end{document}
您可以拥有SaveVerbatim
任意数量的不同名称。\BUseVerbatim
您甚至不需要猜测宽度。