Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

verbatim with background color

538 views
Skip to first unread message

Dennis Lubert

unread,
Nov 2, 2005, 7:01:24 PM11/2/05
to
Hi,

I would like to have some verbatim text within a box that has a background
color, lets say grey. How can I do it? I cannot find any verbatim package
that can have background color.

greets

Dennis

Will Robertson

unread,
Nov 3, 2005, 1:14:25 AM11/3/05
to

Have you looked at the listings package?

Will

Dennis Lubert

unread,
Nov 3, 2005, 6:00:39 AM11/3/05
to
Will Robertson wrote:

Yes, although it can have a background color, it is not what I want. I
really like the verbatim environment, with the fixed font. Listings do
syntax highlighting, and even if you get it to syntax highlight everything
with a tt font, the spacings between the single letters are much bigger
than in verbatim and it just looks ugly.

greets

Dennis

Ulrike Fischer

unread,
Nov 3, 2005, 6:56:04 AM11/3/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:

>>> I would like to have some verbatim text within a box that has a
>>> background color, lets say grey. How can I do it? I cannot find any
>>> verbatim package that can have background color.

fancyvrb



>> Have you looked at the listings package?

> Yes, although it can have a background color, it is not what I want. I
> really like the verbatim environment, with the fixed font. Listings do
> syntax highlighting, and even if you get it to syntax highlight
> everything with a tt font, the spacings between the single letters are
> much bigger than in verbatim and it just looks ugly.

This can all be changed. The spacing between letters e.g. with
columns=flexible or =fullflexible.

--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.

Dennis Lubert

unread,
Nov 3, 2005, 7:40:41 AM11/3/05
to
Ulrike Fischer wrote:

> Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:
>
>>>> I would like to have some verbatim text within a box that has a
>>>> background color, lets say grey. How can I do it? I cannot find any
>>>> verbatim package that can have background color.
>
> fancyvrb

How can I set background color there? I only found options for setting
border/frame colors.

greets

Dennis

Ulrike Fischer

unread,
Nov 3, 2005, 8:21:06 AM11/3/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:


\documentclass{article}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor,fancyvrb}

\begin{document}
\begin{SaveVerbatim}{myenv}
test
test
\end{SaveVerbatim}

\colorbox{red}{\BUseVerbatim{myenv}}
\end{document}

Dennis Lubert

unread,
Nov 3, 2005, 8:27:03 AM11/3/05
to
Ulrike Fischer wrote:

> Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:
>
>> Ulrike Fischer wrote:
>>
>>> Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:
>>

>> How can I set background color there? I only found options for setting
>> border/frame colors.
>
>
> \documentclass{article}
> \usepackage[ansinew]{inputenc}
> \usepackage[T1]{fontenc}
> \usepackage{xcolor,fancyvrb}
>
> \begin{document}
> \begin{SaveVerbatim}{myenv}
> test
> test
> \end{SaveVerbatim}
>
> \colorbox{red}{\BUseVerbatim{myenv}}
> \end{document}

Intresting trick, thanx. Can I get this to go over multiple pages too? In a
longer verbatim block I have things go over ~3 pages.

greets

Dennis

Ulrike Fischer

unread,
Nov 3, 2005, 9:37:01 AM11/3/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:

> Intresting trick, thanx. Can I get this to go over multiple pages too?
> In a longer verbatim block I have things go over ~3 pages.
>

Use listings.sty. Or the following

\documentclass{article}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor,fancyvrb}

\begin{document}
\renewcommand\FancyVerbFormatLine[1]
{\colorbox{red}{{#1}}}

\nointerlineskip
\begin{Verbatim}
test test
test
\end{Verbatim}

\renewcommand\FancyVerbFormatLine[1]
{\colorbox{red}{\makebox[\linewidth][l]{#1}}}

\begin{Verbatim}
test
test
\end{Verbatim}

Dennis Lubert

unread,
Nov 3, 2005, 9:59:33 AM11/3/05
to
Ulrike Fischer wrote:

> Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:
>
>> Intresting trick, thanx. Can I get this to go over multiple pages too?
>> In a longer verbatim block I have things go over ~3 pages.
>>
>
> Use listings.sty. Or the following

This leaves white between some of the lines, especially between two
newlines. setting columns=flexible etc. in listings does not work here too.
I think its just one of the cases where doing explicit styling in latex
does not work.
I will stick to plain verbatim without color until maybe someone extends
fancyvrb to contain colored background...

greets and thanx for the tips

Dennis

Robin Fairbairns

unread,
Nov 3, 2005, 10:26:08 AM11/3/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> writes:

>Ulrike Fischer wrote:
>> \documentclass{article}
>> \usepackage[ansinew]{inputenc}
>> \usepackage[T1]{fontenc}
>> \usepackage{xcolor,fancyvrb}
>>
>> \begin{document}
>> \begin{SaveVerbatim}{myenv}
>> test
>> test
>> \end{SaveVerbatim}
>>
>> \colorbox{red}{\BUseVerbatim{myenv}}
>> \end{document}
>
>Intresting trick, thanx. Can I get this to go over multiple pages too? In a
>longer verbatim block I have things go over ~3 pages.

use the shaded environment out of framed.sty, instead of \colorbox.
--
Robin (http://www.tex.ac.uk/faq) Fairbairns, Cambridge

Ulrike Fischer

unread,
Nov 3, 2005, 11:07:27 AM11/3/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:


>>> Intresting trick, thanx. Can I get this to go over multiple pages
>>> too? In a longer verbatim block I have things go over ~3 pages.
>>>
>>
>> Use listings.sty. Or the following
>
> This leaves white between some of the lines, especially between two
> newlines.

Yes that's the problem if you want to stick to fancyvrb.

> setting columns=flexible etc. in listings does not work here
> too.

listings is able to do it. And if it doesn't do it on your place you
either haven't found out the correct options (which can be difficult)
or you are doing something wrong.

This code gives at my place complety identical verbatim look. One only
had to sure (e.g. by putting an empty lstlocal.cfg in the document
folder) that one doesn't load some local listings settings that mess
things up.

\documentclass{article}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\usepackage{listings}
\lstset{basicstyle=\ttfamily, columns=flexible,
%or columns=fullflexible
backgroundcolor=\color{red}}

\begin{document}
\begin{verbatim}
test
\string
\hbox
\begin{document}
comment %
\end{verbatim}

\begin{lstlisting}
test
\string
\hbox
\begin{document}
comment %
\end{lstlisting}

Dennis Lubert

unread,
Nov 3, 2005, 4:01:18 PM11/3/05
to
Ulrike Fischer wrote:

> Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:
>
>
>>>> Intresting trick, thanx. Can I get this to go over multiple pages
>>>> too? In a longer verbatim block I have things go over ~3 pages.
>>>>
>>>
>>> Use listings.sty. Or the following
>>
>> This leaves white between some of the lines, especially between two
>> newlines.
>
> Yes that's the problem if you want to stick to fancyvrb.
>
>> setting columns=flexible etc. in listings does not work here
>> too.
>
> listings is able to do it. And if it doesn't do it on your place you
> either haven't found out the correct options (which can be difficult)
> or you are doing something wrong.
>
> This code gives at my place complety identical verbatim look. One only
> had to sure (e.g. by putting an empty lstlocal.cfg in the document
> folder) that one doesn't load some local listings settings that mess
> things up.

The example code works well here, though not within my document. Its quite
big and not everything is from me alone, so I assume that somehow the
language is set to something, since it does still syntax highlighting here.
Can I somehow disable it ? I tried to set language to "" or just language=
etc. nothing works, is there some special "non-highlighting" language I
have to choose?
Thanx for your help so far, it should be documented somewhere, since
googling around only resulted in people having the same question but no
solution (at least here)

greets

Dennis

Ulrike Fischer

unread,
Nov 4, 2005, 4:22:53 AM11/4/05
to
Dennis Lubert <plasmahh_at_proj...@nospam.com> schrieb:

> The example code works well here, though not within my document.

Then there is something within your document that changes the listings
settings. Either your document loads another lstlocal.cfg or it use
some \lstset-commands. It shouldn't be to difficult to find it, you
only need to look in the log if which files are input and the use a
simple search for "\lst" on this files.


> Its quite big and not everything is from me alone, so I assume that
> somehow the language is set to something, since it does still syntax
> highlighting here. Can I somehow disable it ? I tried to set language
> to "" or just language= etc. nothing works, is there some special
> "non-highlighting" language I have to choose?
> Thanx for your help so far, it should be documented somewhere, since
> googling around only resulted in people having the same question but
> no solution (at least here)

"somewhere" is the manual of listings.sty. googling is quite fine but
one should try the obvious things first.

By reading the manual I come up with three solutions:

1. Setting all styles (keywordstyle, etc) to \ttfamily, then the
highlighting wouldn't show up.

2. Defining an "nohighlight"-language

3. Using language=, which works fine for me.

\documentclass{article}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,

language=TeX,
keywordstyle=\sffamily\bfseries, %to see the difference


columns=flexible,
%or columns=fullflexible
backgroundcolor=\color{red}}


\begin{document}


\begin{lstlisting}
test
\string
\hbox
\begin{document}
comment %
\end{lstlisting}

\begin{lstlisting}[keywordstyle=\ttfamily, commentstyle=\ttfamily]


test
\string
\hbox
\begin{document}
comment %
\end{lstlisting}

\begin{lstlisting}[language=]


test
\string
\hbox
\begin{document}
comment %
\end{lstlisting}

\lstdefinelanguage{nohighlight}{}

\begin{lstlisting}[language=nohighlight]

Dennis Lubert

unread,
Nov 4, 2005, 8:14:34 AM11/4/05
to
Ulrike Fischer wrote:
> "somewhere" is the manual of listings.sty. googling is quite fine but
> one should try the obvious things first.
>
> By reading the manual I come up with three solutions:
>
> 1. Setting all styles (keywordstyle, etc) to \ttfamily, then the
> highlighting wouldn't show up.
>
> 2. Defining an "nohighlight"-language
Seems to work, thanx for the tips :)

> 3. Using language=, which works fine for me.
Unfortunately does not here.

greets

Dennis

John Culleton

unread,
Nov 29, 2005, 10:09:32 AM11/29/05
to
Dennis Lubert wrote:

Easily done in Context. But Context is not LaTeX. In general when your
requirements stray from the usual and expected then LaTeX gets more
difficult and other approaches offer more direct solutions.

You don't want to switch just to solve this one problem. But you might want
to look at the documentation of Context cited below and consider switching
to simplify a whole host of problems.

http://www/pragma-ade.nl/document-1.htm
--
John Culleton
Able Indexers and Typesetters

0 new messages