是否可以使用逐字环境(即\begin{verbatim}...\end{verbatim}
)XY图节点?如果是,您能否提供一个 MWE(最小工作示例)?
为那些想要示例代码的人进行更新。
这(基于LaTeX Wikibook 示例) 渲染时没有出现错误:
\documentclass[class=minimal,border=0pt]{standalone}
\usepackage[all]{xy}
\usepackage{varwidth}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{displaymath}
\xymatrix{
*+[F:<3pt>]\txt{START}\ar[d] \\
*+[F:<3pt>]\txt{\begin{varwidth}{30em}We'll assume that Git is to be used for source control; so as a precaution against accidentally checking in temporary files used by Vim, enter the following at the command prompt:\end{varwidth}} \\
}
\end{displaymath}
\end{document}
但相比之下,
\documentclass[class=minimal,border=0pt]{standalone}
\usepackage[all]{xy}
\usepackage{varwidth}
\usepackage{verbatim}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{displaymath}
\xymatrix{
*+[F:<3pt>]\txt{START}\ar[d] \\
*+[F:<3pt>]\txt{\begin{varwidth}{30em}We'll assume that Git is to be used for source control; so as a precaution against accidentally checking in temporary files used by Vim, enter the following at the command prompt: \begin{verbatim}echo '*.swp' >> .gitignore\end{verbatim}\end{varwidth}} \\
}
\end{displaymath}
\end{document}
导致停止的原因pdflatex
如下:
<xymatrix
! Argument of \verbatim@ has an extra }.
<inserted text>
\par
l.12 }
?
答案1
您永远不能在宏参数中使用逐字命令。但是,您始终可以将其保存在框中并使用该框。
%in preamble
\newsavebox\mybox
....
% where you want the text
\begin{lrbox}{\mybox}%
\begin{minipage}{5cm}
\begin{verbatim}
....
\foo
\end{verbatim}
\end{minipage}%
\end{lrbox}
\begin{xy.... \usebox{\mybox}......
首先值得注意的是,对于您编辑的问题中显示的文本,完全不需要逐字逐句,\texttt
可以使用简单的字体更改,如下面的第一个片段所示。对于包含 TeX 特殊字符(如和第二个示例中的verbatim
)的多行文本,则需要这样做。这或多或少是我对您编辑的问题的原始回答的直接应用。\
{
我切换到,article
因为我的副本standalone
无法应对显示数学,我认为它太旧了。
\documentclass{article}
\usepackage[all]{xy}
\usepackage{varwidth}
\usepackage{verbatim}
\renewcommand{\familydefault}{\sfdefault}
\newsavebox\mybox
\begin{document}
\begin{displaymath}
\xymatrix{
*+[F:<3pt>]\txt{START}\ar[d] \\
*+[F:<3pt>]\txt{\begin{varwidth}{30em}We'll assume that Git is to be used for source control; so as a precaution against accidentally checking in temporary files used by Vim, enter the following at the command prompt:
\newline
\texttt{echo '*.swp' >> .gitignore}\end{varwidth}} \\
}
\end{displaymath}
\begin{lrbox}{\mybox}%
\begin{minipage}{.75\textwidth}
\begin{verbatim}
multi-line
stuff
with \backslash
and {
\end{verbatim}
\end{minipage}
\end{lrbox}
\begin{displaymath}
\xymatrix{
*+[F:<3pt>]\txt{START}\ar[d] \\
*+[F:<3pt>]\txt{\begin{varwidth}{30em}We'll assume that Git is to be used for source control; so as a precaution against accidentally checking in temporary files used by Vim, enter the following at the command prompt:
\usebox\mybox
\end{varwidth}} \\
}
\end{displaymath}
\end{document}
答案2
以下是 David Carlisle 上述回答的扩展版,这是一个最小示例。请注意,\end{verbatim}
必须出现在自己的行上。
\documentclass{minimal}
\usepackage[all]{xy}
\usepackage{verbatim}
\newsavebox\mybox
\begin{document}
\begin{lrbox}{\mybox}%
\begin{minipage}{5cm}
\begin{verbatim}
% echo '*.swp' >> .gitignore
\end{verbatim}
\end{minipage}%
\end{lrbox}
\begin{displaymath}
\xymatrix{
*+[F:<3pt>]\txt{START}\ar[d] \\
*+[F:<3pt>]\txt{command prompt: \usebox{\mybox}} \\
}
\end{displaymath}
\end{document}