# Tag Info

3

As mentioned in Change typeface of verbatim environment, the default font used in verbatim is \ttfamily, as set in \verbatim@font. You can create a user interface to adjust this font in the following way: \documentclass{article} \usepackage{lipsum} % just for the example \makeatletter ...

5

You appear to be using fancyvrb, which already has the feature you want: \documentclass{article} \usepackage{fancyvrb} \usepackage{lipsum} % just for the example \begin{document} \lipsum*[3] \begin{Verbatim}[fontsize=\small] 1 double x, y; 2 double z, w; 3 main(); 4 return 0; \end{Verbatim} \lipsum[3] \end{document}

4

I would recommend the package listings, which is ment for this purpose. See the page on Wikibooks for simple explanations about settings and my MWE below: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{ % language=C++, % choose the language of the code numbers=left, % where to put the line-numbers ...

6

The macros of the verbatimbox package can take things like \small as an optional argument. In this case, I chose the verbnobox environment, but there are others in that package than may better suit your need. \documentclass{article} \usepackage{verbatimbox} \begin{document} \noindent Normal Size \begin{verbnobox}[\small] 1 double x, y; 2 double z, w; ...

1

First, here is a solution that uses only the xcolor package and the standard verbatim environment. But it is not a new environment, per se, and so does not directly answer the OP's question (for that, see below). \documentclass{article} \usepackage{xcolor} \fboxrule=1pt \begin{document} \setbox0=\hbox{\begin{minipage}{3in} \color{red!90} \begin{verbatim} ...

4

For fancyvrb, you need to use \VerbatimEnvironment before the \begin{Verbatim}. That tells fancyvrb to detect the name of the current environment, and look for the end of that environment, rather than looking for a literal \end{Verbatim}. You will probably want to use a proper framing package to provide the background color...that way you won't have to ...

5

There is a case, where \null makes a difference: At the start of a line TeX removes glue and penalties. If \verb starts with an invisible space, then it would be removed: \documentclass{article} \begin{document} \noindent x\\ \begingroup % \let\null\relax \verb| |y \endgroup \end{document} \null as \hbox{} prevents that the space is gobbled ...

2

Using fragile does not work for me when changing the mode as when generating slides and handouts from separate driver files calling the same content file so I came up with an ugly but effective work around. Let me give an example expanding on the one given above. The driver file to create slides is called contentfile.beamer and has the following: ...

3

One possibility using the listings package; since apparently you only want to highlight some specific strings, you can escape to LaTeX and do the coloring there (in my example I used the bera package just to have a mono-spaced font allowing boldface) \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{bera}% for boldfaced ...

Top 50 recent answers are included