Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to use the verbatim environment (i.e. \begin{verbatim}...\end{verbatim}) in an XY-pic node? If so, please could you provide a MWE (Minimal Working Example)?


Update for those who want example code.

This (which is based on the LaTeX Wikibook examples) renders without errors:

\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}

but this, by contrast

\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}

causes pdflatex to halt with the following:

<xymatrix
! Argument of \verbatim@ has an extra }.
<inserted text> 
                \par 
l.12   }

?
share|improve this question
    
It should be the other way around: you provide a possibly non working example showing what you would like to achieve. –  egreg Jun 29 '12 at 11:34
    
If the question is clear, concise and answerable, why bloat it with a non-working example? –  sampablokuper Jun 29 '12 at 12:34
    
What kind of verbatim do you want to put and where? Xy-pic is a big package that provides many features. –  egreg Jun 29 '12 at 12:36
    
@sampablokuper: Because answers quite often must be tested. If you add a suitable test document to your question you are making life much easier for the people searching for answers. –  Ulrike Fischer Jun 29 '12 at 16:16
    
@egreg, "What kind of verbatim?" The \begin{verbatim}...\end{verbatim} kind. This must have been obvious enough, as David Carlisle below was apparently able to infer it without difficulty. "Where?" In an XY-pic node, as clearly stated in the question. I don't see how the size of the XY-pic package, nor the fact that it provides other features besides nodes, makes this part of my question unclear. –  sampablokuper Jun 30 '12 at 15:01

2 Answers 2

up vote 12 down vote accepted
+50

You can never use verbatim commands in a macro argument. You can however always save it in a box and use that box.

%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}......

Firstly it's worth noting that for the text shown in your edited question verbatim isn't needed at all, a simple font change like \texttt can be used as shown in the first fragment below. verbatim is needed for multi-line text that included TeX-special characters such as \ and { as in the second example. Which is more or less a direct application of my original answer to your edited question.

enter image description here

I switched to article as my copy of standalone can't cope with the display math, I think it's too old.

\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}
share|improve this answer
    
Thanks for your answer. I tried to turn your snippet into a MWE, but without success. Would you mind expanding it into one? If so, I'll gladly mark this answer as accepted! –  sampablokuper Jun 30 '12 at 14:57
3  
it's 20 years since I used xypic, make a basic document using xypic with VERBATIM HERE and I'll make it verbatim there, that's why the person asking the question should make the MWE the people answering them don't always know as much as you think:-) –  David Carlisle Jun 30 '12 at 16:30
    
Thanks. I've now provided a code example. –  sampablokuper Jul 2 '12 at 6:23

Here is the minimal example, expanded from David Carlisle's answer above. Note that \end{verbatim} must appear on it own line.

\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}
share|improve this answer
    
The lrbox environment could go inside the displaymath environment: I believe this is better style, in this case. –  egreg Jul 2 '12 at 8:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.