{verbatim} is about macros and environments like “\verb” and “verbatim” which implement some form of verbatim mode, i.e. change the {catcodes}. A popular package is {fancyvrb}. For questions about the {listings} or the {minted} package, use the respective tag instead.

learn more… | top users | synonyms

56
votes
2answers
48k views

When should one use \verb and when \texttt

Sometimes people here use \verb!A SHORT COMMAND! and sometimes \textt{A SHORT COMMAND}. I'm unsure when to use which. Are there any guidelines or arguments for \verbatim vs. \texttt?
35
votes
2answers
679 views

Viewer-independent copyable spaces at the beginning of a line?

I need to include a couple of Python code listings, where the indentation of the lines (using some number of spaces) is significant. I would like for the code listings to be copyable, so the spaces at ...
30
votes
5answers
5k views

How to obtain verbatim text in a footnote?

I want to employ a \verb command in a footnote. But, when I run pdflatex on \documentclass{article} \begin{document} I want this.\footnote{\verb|But, it does not work!|} \end{document} I get ...
23
votes
4answers
14k views

Verbatim environment that can break too long lines?

I want to generate a PDF of user-submitted text using LaTeX. To handle crazy user input, I first thought about using the verbatim package, but of course it doesn't break up too long lines. Is there ...
22
votes
2answers
2k views

Ensure verbatim code block is copy/paste-able

After rendering a document containing this code block \begin{verbatim} if [ ! -d .git ]; then git init; fi # Initialises a new Git repository, if doesn't already exist. if [ ! -f README.md ]; ...
21
votes
5answers
1k views

typesetting different characters with different colors in a DNA sequence

I have created a macro which I used to format DNA sequences, as they should be in the monospaced font and uppercased: \newcommand{\DNA}[1]{\texttt{\uppercase{#1}}} Now I have a column with some ...
20
votes
2answers
484 views

Incompatibility between verbatim and tabu? (Danger of using \scantokens in a package)

With the following MWE \documentclass{article} \usepackage{verbatim} \usepackage{tabu} \makeatletter \renewcommand\verbatim@processline {% \begin{tabu}to\textwidth{|l|X[-1,l]|} ...
18
votes
3answers
1k views

In LuaLaTeX, how do I pass the content of an environment to Lua verbatim?

In LuaLaTeX, how would I go about capturing the content of an environment for (verbatim) processing by Lua? For example, consider something like \begin{foobar} Hello {World} \end{foobar} I'd like ...
18
votes
2answers
918 views

Write environment body verbatim to a file

How can one write the body of an environment verbatim to an external file. I tried the following but get problems if the body contains undefined macros (error) or e.g. a % (disappears in the output). ...
17
votes
3answers
2k views

How to put \verb command inside of \textbf{} block?

It looks like you can't use \verb|...| inside of \textbf{...}. I tried the following: \textbf{Be very careful when using \verb|-i| as it's destructive and it's not reversible!} And got this error: ...
17
votes
5answers
2k views

How can I provide a verbatim (unescaped) commandline for executing with \write18?

When using \write18 to execute shell commands, there are some cases where lots of backslash strings, and other 'special' LaTeX characters are required in the commandline to be executed (e.g. if a ...
17
votes
4answers
3k views

Getting those %#!^& signs in the footnote!

This is basically an expanded version of part of Control command arguments . The original questioner there wants to redefine \href so that all the links end up in foonotes (rather than in the main ...
16
votes
3answers
1k views

Writing { and } to a file with LaTeX

How can the special characters { and } be written literally to an external file in LaTeX, without being balanced? Obviously the following does not work: \immediate\write\my@outfile{{} ...
16
votes
3answers
240 views

Fancy code environment

I'm writing a small tutorial about LaTeX. So I'd like to insert some code and obtain the result on the right. I'm almost there. I got the desired output but I'd like something more clear, that is, ...
16
votes
2answers
697 views

How can I make lstlisting look exactly like verbatim?

I like the way the verbatim environment looks, and I want to make my lstlistings look like it. I've tried setting the basic style to \ttfamily, but the letter kerning and line spacing seem to be ...
16
votes
1answer
195 views

Why is there a \null in \verb?

In source2e.pdf, the definition of \verb is \def\verb{\relax\ifmmode\hbox\else\leavevmode\null\fi \bgroup \verb@eol@error \let\do\@makeother \dospecials \verbatim@font\@noligs ...
15
votes
2answers
914 views

Highlighting a .diff file

Is there a way to highlight the syntax of a diff file (i.e. by using the listings package)?
15
votes
2answers
2k views

Colored background in inline listings

I would like to make inline code more distinguishable from the text surrounding it, and I thought that using a background might work (like it is done on the stackexchange pages.) Since I use the ...
15
votes
1answer
1k views

beamer's fragile frame as default

Is there a way to specify fragile mode as default for all frames? Now I know how to define a fragile frame: \begin{frame}[fragile].
15
votes
2answers
2k views

Verbatim inside a command

I have a question about a Verbatim, I want to write a word inside of the subsubsection title. I got an error. How can I fix it?: \subsubsection{The \verb+@interface+ Section}
15
votes
2answers
3k views

Verbatim description list item

How do I make an item in a description list verbatim? \verb in \item[] seems to be not allowed: \begin{description} \item[\verb+list comprehension [f a | a <- M a]+] bla bla bla ...
15
votes
1answer
4k views

Verbatim environment and line-breaking

I've been wondering about how to display simple codes. I used verbatim and then found the fancyvrb package which added a lot of nice little features, but then I inserted some code with a long line and ...
15
votes
2answers
448 views

How to make AUCTeX ignore syntax highlighting within environment

I have a problem with syntax highlighting in the Emacs editor using AUCTeX. The problem occurs in particular with the Verbatim environment from the fancyvrb package. Consider the following code: ...
14
votes
3answers
7k views

How to include verbatim in a figure caption?

I would like to include verbatim in a caption of a figure. I only want part of it to be verbatim, not the entire caption. The simple approach does not work because verbatim is not allowed in arguments ...
14
votes
1answer
36k views

In-line \verb — overfull hbox problem

I'm having a problem that I've had before and I'm tired of hacking my way through it and hope that there is some supported solution. I'll go ahead and create a document for example: \documentclass ...
14
votes
1answer
364 views

Escaped characters in typewriter font

I know a number of ways to fix this (e.g. \usepackage[T1]{fontenc}), but I want to understand what's happening in the following example. \documentclass{article} \begin{document} \noindent \$ \% ...
14
votes
1answer
6k views

How do you insert an inline verbatim?

I'm trying to add an inline verbatim into a \paragraph? Was wondering how do you do that?
14
votes
1answer
157 views

Workaround for open lualatex bug in \scantokens?

As package author I am in need of writing a manual with lots of examples. Now I started to make heavy use of lualatex in order to speed up operations which take a long time in TeX (of my package, not ...
14
votes
2answers
436 views

Getting verbatim with soft grey background, as in tex.stackexchange

Given a verbatim as on below, \begin{verbatim} This is an awesome verbatim \end{verbatim} which is displayed with no background on the compiled pdf page : This is an awesome verbatim I would ...
13
votes
4answers
2k views

Hard whitespace

I am using plainTeX and would like to typeset some (python) code examples. Switching to \tt gets me partway there, but I (obviously) need the whitespace respected. Is there a trick for doing this? The ...
13
votes
2answers
935 views

Format a verbatim paragraph

How can I format a verbatim paragraph? I.e. break, fill and join input lines to produce globally balanced output with the lengths of each line approaching the target \textwidth as closely as possible. ...
13
votes
2answers
1k views

Using \lstinline inside a \item

I know about the fragility of verbatim-like commands, and that they should not be used as an argument of another macro, but a need to write a description environment in which the terms to be defined ...
13
votes
1answer
2k views

Manual highlight of TeX code in a verbatim environment

Friends, I'm stuck with a unusual situation: I'm trying to highlight specific words of a TeX code inside a verbatim environment. I know listings can help me by defining a set of keywords, but in this ...
13
votes
1answer
186 views

Comparison of LaTeX example typesetting packages?

I am writing a (longer) text on LaTeX usage, and I want to typeset some LaTeX source code together with its results – and I'm not sure how to achieve it. I am aware of this question, however, it only ...
12
votes
2answers
376 views

Splitting verbatim inside figure across pages

I want to include a long section of verbatim text, which is too long for a single page, inside a figure with a caption. Unfortunately, when the verbatim environment is put into a figure, it does not ...
12
votes
2answers
533 views

Any way to show LaTeX example code *and* execute it? [duplicate]

In (La)TeX documentation and tutorials, it is common to show a snippet of code next to the output it generates. It might be two minipages side by side, or a code listing followed by boxed output, or ...
12
votes
1answer
632 views

escape `|' in \verb

In LaTeX, if I use \verb, how can I escape |? For example, I want to display ab|bc: \verb|ab[]bc|. What should replace []?
12
votes
1answer
2k views

fancy verbatim - bold letters for the first 4 columns

I am writing a book on Python and IPython. I want to insert in this book code listings of Python and IPython. For the code itself I have no problem customizing listings for my intents. Including ...
12
votes
1answer
3k views

Difference between {\tt \{} and \verb+{+

Why is {\tt \{} typeset as an ordinary { and not the same as for instance \verb+{+? To illustrate: {\tt With tt:~ \{} \verb+With verb: {+ yields
12
votes
1answer
1k views

Changing font in tabular

I desperately need someone's help. For the past hour I was trying to perform a task so diabolically difficult, even the Hercules himself couldn't achieve: change the freaking font in a table. My ...
12
votes
2answers
830 views

LaTeX Verbatim Source Code Beside the Typeset Output

I am a beginner to LaTeX, and I am reading Leslie Lamport's A Document Preparation System. In various places of his book, he puts the LaTeX source code beside the output obtained by running latex on ...
12
votes
1answer
5k views

center /verbatim text in /figure

I'm trying to center a the content of a figure that has verbatim text in it, but the verbatim text is always right-aligned: \begin{figure} \centering \begin{verbatim} some text here ...
11
votes
4answers
5k views

Change font size of the verbatim environment

I want to apply small fonts inside the Verbatim environment e.g. {\small \begin{Verbatim} 1 double x, y; 2 double z, w; 3 main(); 4 return 0; \end{Verbatim}} Before the command \small ...
11
votes
4answers
604 views

How can I indent verbatim blocks?

I have blocks surrounded by \begin{verbatim} and \end{verbatim}. I'd like to indent these about half an inch. I'm using pandoc to write pdfs via XeLaTeX and the default.latex pandoc template, so I'd ...
11
votes
3answers
551 views

How to make this verbatim code look nice?

I am doing some slides using Beamer. One of this slides is pure code \begin{frame}[fragile] \begin{verbatim} > dim(X) #dimension of our matrix X [1] 2194 12276 > length(Y) # length of ...
11
votes
2answers
238 views

Print small TeX code verbatim and render it

To write some documentation, I would like the ability to define a command such as \showcase{x^{y}\in\Omega} which expands to something roughly equivalent to \verb|x^{y}\in\Omega| & ...
11
votes
1answer
125 views

Expansion of verbatim material

I am passing a file name in the command line which contains underscores and would like to print the name of the file in the resulting PDF. So, need some expansion magic so that the output is: The ...
11
votes
1answer
1k views

Alternatives to $\backslash$

Background Instead of marking up the text with bold or emphasis, I read (and agree) that it is better to define a command, or environment, that describes the content. Then apply text formatting ...
11
votes
3answers
805 views

unicode \begin{verbatim} with cmtt?

A lot of leading-edge programming languages (like Coq and Agda) allow nearly unrestricted use of unicode symbols in program text, so you can have math characters like $\otimes$ (Unicode U+2A02) as ...
11
votes
3answers
1k views

How to pass an optional argument to an environment with verbatim content?

This is an attempt to make clear what happened in this question of xport (now deleted, sorry). The now deleted question included code that tried to make my answer to this question of xport work for ...