# Tag Info

1

I use the ability to pass optional arguments to the macros of the verbatimbox package in order to condition the verbatim in various ways (typically font size and style). But in this case, I condition it with a negative \hspace equal to the number of \texttt letters of the desired source-indent, which is passed as a mandatory argument to the newly created ...

4

The verbatim environment is not sophisticated enough for what you're asking. What you can do instead is use an lstlisting environment (from the listings package) in conjunction with the autogobble option (from the lstautogobble package), set the basic style to typewriter font, pass fullflexible to the columns key (more details in 2.10 in the listings ...

14

fontenc package deals with font encodings in the output file (pdf generally). But the font encodings in the input file are handled by inputenc package. Adding \usepackage[utf8]{inputenc} solves the problem. \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} %%<---- add this \begin{document} \begin{verbatim} © ...

3

You can use tcolorbox with listings package seemlessly. There by one can combine the advantages and features of both. Here is an example. \documentclass{article} \usepackage{tcolorbox,listings} \lstdefinestyle{mystyle}{ basicstyle=\ttfamily, numbers=left, numberstyle=\tiny, numbersep=5pt } ...

8

You can use the very powerful tcolorbox package, in combination with fancyvrb \documentclass{article} \usepackage{tcolorbox,fancyvrb,xcolor,tikz} \tcbuselibrary{skins,breakable} \newenvironment{BGVerbatim} {\VerbatimEnvironment \begin{tcolorbox}[ breakable, colback=yellow, spartan ]% \begin{Verbatim}} {\end{Verbatim}\end{tcolorbox}} ...

7

Use package listings instead. It supports page breaks and also fancyvrb: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \begin{document} \begin{lstlisting}[backgroundcolor=\color{yellow},frame=single,basicstyle=\ttfamily] \addcontentsline{toc}{chapter}{The first section name} foo \end{lstlisting} \end{document}

5

You can do that with the fancybox package, which defines the same Verbatim environment. You can define a new verbatim environment, let's say MyVerbatim with background and text colors. \newenvironment{MyVerbatim}{\VerbatimEnvironment% \noindent\begin{Sbox} \begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule} \begin{Verbatim} }{% ...

1

The verbatimbox package can also do this. The nice thing here is that the boxed content is not immidately printed, so that it can then be inserted anywhere a LaTeX box can go. Here it is inside an \fbox, but it can be placed inside a table, a footnote, a section title, etc. There is also a different environment myverbbox in which you provide the name of ...

3

If you wish to add spice to your verbatim later, here is an option with tcolorbox. This box can break across pages. \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{listings,breakable} \newtcblisting{myverbatim}{ arc=3mm, top=0mm, bottom=0mm, left=0mm, right=0mm, boxrule=0.5pt, colback=gray!30, ...

4

The Verbatim environment from the fancyvrb has not an options to do that. But you can use the similar environment boxedverbatim from the moreverb package. Remember anyway to eliminate the spaces at the beginning of lines. MWE \documentclass{article} \usepackage{moreverb} \begin{document} \begin{boxedverbatim} s=0 for j = 1 : i -1 s = s + aij * akj end ...

4

It would be a bit fragile to do that in TeX: I'd do the replace with a regex in the editor as you suggest. (If you just wanted to make a ~ in text and a normal space in math that would be easier, but having it work in listings and verbatim would be harder) For example given \documentclass{article} \usepackage{amsmath} \begin{document} A new example here ...

2

You can use a verbatim (fancyvrb package) or listings environnement. \documentclass{article} \usepackage{fancyvrb} \begin{document} \begin{Verbatim}[frame=single] ^(?\s?\w{1,5}\s*[):.]\s* \end{Verbatim} \end{document}

1

You can use the verbatim environment; just patch it so that it selects a smaller font. In the example I use \small which is 9pt, 10pt or 11pt when the main font size is 10pt, 11pt or 12pt respectively. Instead of \small you can substitute any other \fontsize{X}{Y}\selectfont instruction, but keep in mind that Y stands for the baseline skip, which should be ...

2

I have 3 suggestions for it. Have a look: The first one... \documentclass{article} \usepackage{amsmath}\begin{document} $$\verb!f(x)=ax^2+bx+c! \label{eq:1}$$ In order to typeset $f(x)=ax^2+bx+c$, see~\eqref{eq:1}. \end{document} The second one... \documentclass{article} \usepackage{amsmath} \usepackage{fancyvrb} ...

6

This is the example file from the numberedblock package. It makes the labels slightly different than equation numbering, so that one doesn't confuse them if both are used in the document. However, label placement and style can be changed. The documentation is briefly covered in the .sty file itself, as well as this example file. The parameter defaults, ...

3

Here's a start you can modify to meet other needs. \documentclass{article} \usepackage{amsthm} \newtheorem{VerbatimText}{} \begin{document} \begin{VerbatimText} \label{v:test} \begin{verbatim} This is my numbered verbatim environment \end{verbatim} \end{VerbatimText} I can refer to it with a reference: \ref{v:test}. \end{document}

4

listings is the de-facto standard for typesetting of code these days and offers syntax highlighting and font selection, amongst other things; fancyvrb might be easier to handle for your use case. To answer your more immediate question: you can't put the argument of a command into a verbatim environment, verbatim needs to change the way text is read and it's ...

1

You cannot use any of the verbatim environments, including verbatim itself, just as any of the listing environment without writing, \begin{frame}[fragile]\frametitle{....} ... \end{frame} or any other form of passing the fragile flag to the \frame command.

5

Note: you may upvote this answer ;-). \documentclass{article} \makeatletter \def\myverb {% \relax\leavevmode\null \bgroup \verbatim@font \let\do\do@noligs \verbatim@nolig@list \let\do\@makeother \dospecials \@vobeyspaces \@myverb }% \def\@myverb #1{\catcode#1\active \lccode\~#1% ...

3

Note: please, don't vote for this answer, which is actually a large comment that can't be in comments; it is aimed to a clarification of the question With xparse you can define commands that absorb their argument verbatim: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\verbsagestr}{v}{% \texttt{#1}% } \begin{document} ...

2

If you need the macro just for substituting in the VerbatimOut environment, here's a possibility: \documentclass{article} \usepackage{fancyvrb} \begingroup \endlinechar=^^J \obeyspaces% end of lines are newlines \gdef\definesortfunction #1;{% eat up the space following the macro #1[] sort(#1[] a) { if (a.length <= 1) return a; static #1[] ...

1

I think, this is something similar to the attempt achieved by various 'problem-solution' packages available for LaTeX, where the solution of a problem is typeset, not expanded and ten written verbatim to another file to be included at some other position. Your approach is to expand first the macros, then write them verbatim to a programming language source ...

Top 50 recent answers are included