Hot answers tagged verbatim
17
David did beat me by a couple of minutes, but this version here does indentation as requested and is not producing overfull lines (within reason):
\documentclass{article}
\makeatletter
% this defines myverbatim environment. to change name replace "myverbatim" in all places below (strctly speaing it is only necessary in some but ... :-)
...
11
You just want the definition of verbatim without the \obeylines part:
!
\documentclass{article}
\usepackage[T1]{fontenc}
\makeatletter
\newenvironment{exB}{%
\trivlist
\item\relax
\let\do\@makeother \dospecials
\verbatim@font \@noligs
\hyphenchar\font\m@ne
\catcode`\ \active
\catcode`\^^M\active
\catcode`\\\active
\lccode`\~`\\%
...
9
Compute the number by dividing the text width by the width of one character:
\documentclass{article}
\newcommand{\computenumber}[1]{%
Lines contain
{\begingroup\count255=\textwidth
\settowidth{\dimen0}{\ttfamily#1A}%
\divide\count255 by\dimen0
\number\count255\endgroup}
characters in \texttt{\string#1}}
\begin{document}
...
7
It doesn't work because after
\documentclass{article}
\newenvironment{myverbatim}{\tiny\begin{verbatim}}{\end{verbatim}}
\begin{document}
\begin{myverbatim}
test
\ is no longer an escape character it acts verbatim just typestting a \. so this:
\end{myverbatim}
is not a command to end the environment, it is just more text, and so is this:
...
7
Perhaps what you are looking for is
\def\display#1{\texttt{\expandafter\strip@prefix\meaning#1}}
which gives the verbatim-ish rendering of the first level expansion of #1 but similarly to your example it doesn't really make sense to pas in more than a single token as #1.
Any later tokens in either your example or this one are just typeset as normal.
But ...
6
The 'big picture' aim here is to make sure that no ligatures are applied: for example, -- is converted to an en-dash in 'normal' circumstances as it's a ligature. The way this is done is to make the potential ligature characters 'safe' inside the verbatim environment by inserting a kern between them.
The detail you ask about is as follows. The macro ...
6
With e-TeX available, the \detokenize primtive does what you want: it turns all of the material into catcode-12 tokens, apart from spaces which are catcode 10. It also inserts spaces after control words. \detokenize has toks-like syntax, so can be used in the form
\def\display#1{\detokenize\expandafter{#1}}
The \detokenize primitive is expandable, so you ...
6
For formatting tags like <tag> prefer to wrap them into \verb|<tag>|.
Also, I'd recommend to create a custom command, like this (this will allow you to change the typesetting of all XML tags at once):
\documentclass[varwidth]{standalone}
\usepackage{xcolor}
...
6
Maybe simply:
\documentclass{article}
\begin{document}
\makeatletter
%\def\verbatim@font{\normalfont\ttfamily} % original one
\def\verbatim@font{\normalfont\sffamily}
\makeatother
\begin{verbatim}
Sans serif,
indeed.
\end{verbatim}
\end{document}
5
the problem, as pointed out by egreg, is that you need to specify
\begin{frame}[fragile]
when including verbatim material in the frame.
this is documented in the beamer manual (texdoc beamer) in section 3.1.3, "verbatim text". (it almost never hurts to check the manual, and the beamer manual is a good one.)
5
Similar as the definition for the tt fontfamily, you can build a sf family to use \sffamily:
\documentclass{article}
\usepackage{fancyvrb}
\makeatletter
\begingroup
\catcode`\`=\active
\gdef\FV@fontfamily@sf{%
\def\FV@FontScanPrep{\FV@MakeActive\`}%
\def\FV@FontFamily{\sffamily\edef`{{\string`}}}}
\endgroup
\makeatother
\begin{document}
\noindent ...
5
Here's what I add to my Preferences.el file (the .emacs equivalent for Aquamacs):
(setq LaTeX-verbatim-environments-local '("Verbatim" "lstlisting"))
This makes Verbatim and lstlisting behave like verbatim
3
In a verbatim environment some characters are made active in order to break possible ligatures. The list is kept in \verbatim@nolig@list which is defined as
\def\verbatim@nolig@list{\do\`\do\<\do\>\do\,\do\'\do\-}
which tells that the activated characters are `, <, >, , ', -. Also the space is active, unless "visible spaces" are to be output.
...
3
There is no vertical flexibility between listing lines so if the text height is not an exact multiple of the line height (after taking account of the \topskip used for the first line) then you will get this warning (you would also get it in normal text if you had a full page with no paragraph break).
If you cannot change your \textheight you can add ...
3
The main problem with using your definition of myverbatim can be defined in terms of a combination of scope and macro replacement. That is, something that starts with
\begin{<some-env>}
is expected to end with
\end{<some-env>}
If it doesn't, there's a problem, since the scope is not clearly defined. In your case, you start it with
...
3
If you only need fancyvrb and not the full fledged listings package, you can do it quite easily with the commandchars option:
\documentclass{article}
\usepackage{fancyvrb}
\newcommand\userinput[1]{\textbf{#1}}
\usepackage{tgcursor}
\begin{document}
\begin{Verbatim}[commandchars=\\\{\}]
$ \userinput{echo foo}
foo
$
\end{Verbatim}
...
3
The problem is the timing where the \tiny command is issued. It can't go before \verbatim without a preceding \par, but it can't go after it either.
So you have to change the definition of \verbatim@font:
\documentclass{article}
\usepackage{verbatim,etoolbox}
\makeatletter
\newenvironment{myverbA}
{\verbatim}
{\endverbatim}
\newenvironment{myverbB}
...
2
An answer can be found here Command for special text with reserved LaTeX symbols or, if you don't mind the result in boxes (I mean LaTeX box, not a bordered box), you can use the verbatimbox package with an optional argument:
\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
\begin{verbbox}[\tiny]
This is tiny \verbatim
\end{verbbox}
...
2
If you're going to have to type up more of these tags, the listings package may be well worth a try (employing colors for operators (or literals, or whatever) is tricky; if you'd like them, usually, one suggests the package minted, which unfortunately does not do inline stuff! catch 22!):
\documentclass{article}
\usepackage{listings}
\begin{document}
...
2
As shown in Command for special text with reserved LaTeX symbols,
\documentclass{article}
\usepackage{verbatim}
\renewcommand\encodingdefault{T1}
\newenvironment{venv}{\verbatim\venvinner}{\endverbatim}
\makeatletter
\newcommand\venvinner[1][]{{\nfss@catcodes\scantokens{\gdef\tmp{#1}}}\tmp}
\makeatother
\begin{document}
\begin{venv}[\sffamily]
This should ...
2
Use \acronymused{AC} instead of \acused{AC}.
\documentclass[]{article}
\usepackage[printonlyused,withpage]{acronym}
\begin{document}
\begin{verbatim}
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ...
2
I come long after the battle but here is a way which just imitates the way verbatim is done in source2e.
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theo}{Theorem}
\makeatletter
\let\original@proof\proof
% Plagiarizing verbatim set-up:
\begingroup
\catcode `|=0 \catcode `[= 1 \catcode`]=2
\catcode `\{=12 \catcode `\}=12 ...
2
The verbatimbox package has the provisions to add preconditioning commands (e.g., line numbers, etc.) to a file listing. But because it puts it into a box, it is restricted to one page. That is the first thing I show below (\verbfilebox places the file contents in a box, \theverbbox regurgitates it).
Then, I took the command from that package and by ...
2
I prepared something using the listings package. You can adjust the appearance by customizing the \lstset and \lstdefinestyle commands. See the documentation for further information.
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
basicstyle=\color{red}\itshape
}
\lstdefinestyle{inline}{
columns=fullflexible,
...
1
Are you tied to the verbatim environment explicitly, or only the functionality of the verbatim environment? If the latter, this example below formats text in a verbatimlike way, obeying wrapping and margins. With the [c] option, it puts a vertical bar to the left of the text, which, while not a character in the first column of every line, would seem to ...
Only top voted, non community-wiki answers of a minimum length are eligible


