TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use the verbatim environment (i.e. \begin{verbatim}...\end{verbatim}) in a dot2tex node? If so, please could you provide a MWE?

Update: this is the closest I've got so far:

digraph g {
d2tdocpreamble = "\usepackage{varwidth} \usepackage{verbatim} \renewcommand{\familydefault}{\sfdefault}";
graph [ rankdir = "TB" ];
node  [ style="rounded,bold,filled" fillcolor="azure" shape = "box" ];

assume_git         [ texlbl="\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 or OS X, enter the following at the command prompt:\\\verb|echo '*.swp'      >> .gitignore|\\\verb|echo '.DS\_Store'  >> .gitignore|\end{varwidth}" ];

START              -> assume_git;

And this is the output from turning it into a PDF via the command dot2tex --crop --margin 1em --autosize dot2tex_test_006_mwe.dot > dot2tex_test_006_mwe.tex; pdflatex dot2tex_test_006_mwe.tex:

enter image description here

This is unsatisfactory in at least two ways:

  1. instead of

    \\\verb|echo '*.swp'      >> .gitignore|\\\verb|echo '.DS\_Store'  >> .gitignore|

    I would much prefer to have been able to use

    echo '*.swp'      >> .gitignore
    echo '.DS_Store'  >> .gitignore

    to avoid the need for unnecessary markup for every newline in the code block, but the latter generated the following errors:

    ERROR    Failed to process input
    Traceback (most recent call last):
      File "build/bdist.macosx-10.6-universal/egg/dot2tex/dot2tex.py", line 2928, in main
        s =  conv.convert(dotdata)
      File "build/bdist.macosx-10.6-universal/egg/dot2tex/dot2tex.py", line 794, in convert
        return self.do_preview_preproc()
      File "build/bdist.macosx-10.6-universal/egg/dot2tex/dot2tex.py", line 1105, in do_preview_preproc
        hp,dp,wt = pp.texdims[name]
    KeyError: 'assume_git'
    This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5) restricted \write18 enabled.
    entering extended mode
    LaTeX2e <2009/09/24>
    Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, czech, slovak, dutch, ukenglish, usenglishmax, basque, french, german-x-2009-06-19, ngerman-x-2009-06-19, german, ngerman, swissgerman, italian, polish, portuguese, spanish, catalan, galician, loaded.
  2. The \\\verb|...| approach in the MWE does not render the code verbatim. Even my short example has the following problems:

    • in order to avoid error messages, I had to add a backslash in front of the underscore, but now the backslash is rendered. So I need a way to render just an underscore;
    • the straight single quote marks around *.swp and .DS\_Store have been replaced by right single quote marks;
    • one member of each pair of greater-than signs has disappeared.
share|improve this question
echo "It's explained on dot2tex man page"; echo 'digraph G {a_0 [texlbl="\verb|XY|"] a_1 [texlbl="$x$"] a_0 -> a_1}' > tmp.dot ; dot2tex tmp.dot > tmp.tex; pdflatex tmp – Marc van Dongen Jun 28 '12 at 7:23
Interesting. I can't find the example you gave in the dot2tex documentation, nor in the repo. man dot2tex doesn't work for me - although I used easy_install, so wasn't expecting it to work - but I can't see any documentation in the latest ZIP file either (dot2tex-2.8.7.zip) that includes your example. Please could you tell me more about where you found that explanation? Thanks. – sampablokuper Jun 28 '12 at 13:23
I didn't write the example I gave was on the man page but the mechanism is explained on the man page, cause that's where I found it (today). – Marc van Dongen Jun 28 '12 at 14:16
Your example works, but both this: echo 'digraph G {a_0 [texlbl="\begin{verbatim}XY\end{verbatim}"] a_1 [texlbl="$x$"] a_0 -> a_1}' > tmp.dot ; dot2tex tmp.dot > tmp.tex; pdflatex tmp and also this: echo 'digraph G {d2tdocpreamble = "\usepackage{verbatim}"; a_0 [texlbl="\begin{verbatim}XY\end{verbatim}"] a_1 [texlbl="$x$"] a_0 -> a_1}' > tmp.dot ; dot2tex tmp.dot > tmp.tex; pdflatex tmp fail with the message ! LaTeX Error: Something's wrong--perhaps a missing \item. So I'd be grateful for a fuller answer :) – sampablokuper Jun 29 '12 at 11:15
I don't know anything about dot2tex, nor can I run it (I think), but the verbatimbox package allows you to stuff verbatim into a box, and then (immediately or later) recall the box. Perhaps that would help you achieve your goal. – Steven B. Segletes May 17 '13 at 17:41

Your Answer


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

Browse other questions tagged or ask your own question.