Discussion:
verbatim background color
(too old to reply)
Piet
2005-12-01 13:17:46 UTC
Permalink
Hi,

Can anyone tell me if there is an easy way to change the background
color of the verbatim environment, preferably just once in the
preamble? Creating a new environment with verbatim + background color
would be ok too.

Thanks in advance
Mycroft
2005-12-01 15:42:12 UTC
Permalink
This kinda works... but not perfectly. Anyway, take a look at the
fancyvrb package. It does not handle background color perfectly, but I
suspect it might help you or give you an alternative idea...

Martin


\documentclass{article}
\usepackage{fancyvrb}
\usepackage{color}

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

\begin{document}

This is before verbatim.

\begin{Verbatim}
Verbatim line 1
Verbatim line 2
Verbatim line 3
\end{Verbatim}

This is after verbatim.

\end{document}
Ulrich Diez
2005-12-01 15:51:12 UTC
Permalink
Post by Piet
Can anyone tell me if there is an easy way to change the background
color of the verbatim environment, preferably just once in the
preamble?
You could use Donald Arseneau's framed.sty and place your
verbatim-stuff into a shaded-environment - David Carlisle's
color-package is also needed as you have to declare the
(background-)color "shadecolor" for the shaded-environment.
Whenever you change it, the change will persist throughout the
current group until the next change occurs. You can declare
that color in the preamble.

\documentclass{article}
\usepackage{framed}
\usepackage[dvipsnames]{color}
\definecolor{shadecolor}{named}{Green}
%
\begin{document}
\begin{shaded}
% supress ugly vertical space which is inserted by
% verbatim-environment above and below text:
\topsep=0ex\relax
\begin{verbatim}
\noindent This is verbatim
\@nil -> \TeX is funny!
\end{verbatim}
\end{shaded}
\end{document}
Post by Piet
Creating a new environment with verbatim + background color
would be ok too.
Thanks in advance
If you wish to declare a new environment, which takes as argument
the background-color, I suggest using the verbatim-package of
Rainer Schöpf, Bernd Raichle and Chris Rowley. In the example
below the color-argument is optional. If you omit it, the
color "Green" will be used.

\documentclass{article}
\usepackage{verbatim,framed}
\usepackage[dvipsnames]{color}

\newenvironment{colorverbatim}[1][Green]%
{%
\definecolor{shadecolor}{named}{#1}%
% supress ugly vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
% start shaded and verbatim:
\shaded
\verbatim
}%
{%
\endverbatim
\endshaded
}%

\begin{document}

\begin{colorverbatim}
This is verbatim
\@nil -> \TeX is funny!
\end{colorverbatim}

\begin{colorverbatim}[MidnightBlue]
This is verbatim
\@nil -> \TeX is funny!
\end{colorverbatim}

\end{document}

Ulrich

ps: AFAIK
- the documentation of the framed-package is within the comments
of the file framed.sty.
- color-package is part of David Carlisle's praphics-bundle
which's usage is documented in grfguide[.dvi/.ps/.pdf]
- verbatim-package is documented in the dtx-source, that means
there should be a file verbatim[.dvi/.ps/.pdf] somewhere on
your system.

These color-names get predeclared by using the dvipsnames-option
in the color-package -you can always define more colors/names... :

GreenYellow, Yellow, Goldenrod, Dandelion, Apricot, Peach,
Melon, YellowOrange, Orange, BurntOrange, Bittersweet, RedOrange,
Mahogany, Maroon, BrickRed, Red, OrangeRed, RubineRed,
WildStrawberry, Salmon, CarnationPink, Magenta, VioletRed,
Rhodamine, Mulberry, RedViolet, Fuchsia, Lavender, Thistle,
Orchid, DarkOrchid, Purple, Plum, Violet, RoyalPurple, BlueViolet,
Periwinkle, CadetBlue, CornflowerBlue, MidnightBlue, NavyBlue,
RoyalBlue, Blue, Cerulean, Cyan, ProcessBlue, SkyBlue, Turquoise,
TealBlue, Aquamarine, BlueGreen, Emerald, JungleGreen, SeaGreen,
Green, ForestGreen, PineGreen, LimeGreen, YellowGreen, SpringGreen,
OliveGreen, RawSienna, Sepia, Brown, Tan, Gray, Black, White
Ulrich Diez
2005-12-01 19:49:44 UTC
Permalink
Post by Ulrich Diez
If you wish to declare a new environment, which takes as argument
the background-color, I suggest using the verbatim-package of
Rainer Schöpf, Bernd Raichle and Chris Rowley. In the example
below the color-argument is optional. If you omit it, the
color "Green" will be used.
Perhaps you want a "starred environment" also:

\documentclass{article}
\usepackage{verbatim,framed}
\usepackage[dvipsnames]{color}

\newenvironment{colorverbatim}[1][Green]%
{%
\definecolor{shadecolor}{named}{#1}%
% supress ugly vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
% start shaded and verbatim:
\shaded
\verbatim
}%
{%
\endverbatim
\endshaded
}%

\newenvironment{colorverbatim*}[1][Green]%
{%
\definecolor{shadecolor}{named}{#1}%
% supress ugly vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
% start shaded and verbatim:
\shaded
\csname verbatim*\endcsname
}%
{%
\csname endverbatim*\endcsname
\endshaded
}%

\begin{document}

\begin{colorverbatim}
This is verbatim
\@nil -> \TeX is funny!
\end{colorverbatim}

\begin{colorverbatim}[MidnightBlue]
This is verbatim
\@nil -> \TeX is funny!
\end{colorverbatim}

\begin{colorverbatim*}
This is verbatim*
\@nil -> \TeX is funny!
\end{colorverbatim*}

\begin{colorverbatim*}[MidnightBlue]
This is verbatim*
\@nil -> \TeX is funny!
\end{colorverbatim*}

\end{document}


Ulrich
Ulrich Diez
2005-12-02 06:14:32 UTC
Permalink
Sorry, in my last posting I introduced two BIG BUGS!
verbatim-environment in conjunction with optional arguments
needs special treatment
- as characters might already get tokenized while checking for
the optional arguments, which might lead to unwanted results
when these already tokenized characters are (re)read but not
(re-)catcoded by the \verbatim-macro.
- as you also might get into trouble if verbatim-listing shall
start with a [<something>]-construct.

Therefore I decided to rewrite the whole thing.

Now there are 4 environments.

Each environment has two optional arguments:
- The first optional argument specifies the background-color
- The second optional argument specifies the color-model
If they are not specified, standard-values which are specified
in \colorverbatimcolor respective \colorverbatimmodel will
be used.

1. colorverbatim
----------------
The color-block's width equals the linewidth, spaces
are not visible.

2. colorverbatim*
-----------------
The color-block's width equals the linewidth, spaces
are visible (_).

3. smallblockcolorverbatim
--------------------------
The color-block is just as wide as the widest line
in the listing, spaces are not visible.


4. smallblockcolorverbatim*
---------------------------
The color-block is just as wide as the widest line
in the listing, spaces are visible (_).

Environments 3 and 4 detect width of textblock by means of
the aux-file. That means you may have to run LaTeX _twice_
after having something changed.

Ulrich

\documentclass{article}
\usepackage{verbatim,framed}
\usepackage[dvipsnames]{color}

% Each time when a new smallblockcolorverbatim-listing is started,
% this counter gets "stepped".
\newcommand*\colorverbatims{}%
\newcount\colorverbatims
\colorverbatims=0\relax

% Length of the current line in a smallblockcolorverbatim-listing.
\newcommand*\colorverbatimwidth{}%
\newdimen\colorverbatimwidth

% standard-color if optional color-argument is not specified.
\newcommand*\colorverbatimcolor{SeaGreen}%
% standard-model if optional model-argument is not specified.
\newcommand*\colorverbatimmodel{named}%

% need to access some internals which have "@" in their
% macro-names. So let's
\makeatletter

\newenvironment{smallblockcolorverbatim*}%
{\newcommand*\inersmallblock[1][\colorverbatimcolor]{%
\newcommand*\innersmallblock[1][\colorverbatimmodel]{%
\definecolor{shadecolor}{####1}{##1}%
% supress vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
\global\advance\colorverbatims by 1\relax
\csname colorverbatimhsize\number\colorverbatims\endcsname
\expandafter\gdef
\csname colorverbatimhsize\number\colorverbatims\endcsname{0pt}%
\def\***@processline{%
\settowidth{\colorverbatimwidth}{\the\***@line}%
\expandafter\ifdim
\csname colorverbatimhsize\number\colorverbatims\endcsname
<\colorverbatimwidth\relax
\expandafter\xdef
\csname colorverbatimhsize\number\colorverbatims\endcsname
{\the\colorverbatimwidth}%
\fi
\the\***@line\par
}%
% start shaded and verbatim
\shaded
\csname verbatim*\endcsname
}%
\obeylines\expandafter\innersmallblock\noexpand
}%
\obeylines\expandafter\inersmallblock\noexpand
}%
{%
\csname endverbatim*\endcsname
\endshaded
\immediate\write\@auxout{%
\string\expandafter\string\gdef
\string\csname\space colorverbatimhsize\number\colorverbatims
\string\endcsname
{\string
\hsize=\csname colorverbatimhsize\number\colorverbatims\endcsname}%
\string\relax
}%
}%

% The same as the starred, just need to replace
% \verbatim* by \verbatim:
\newenvironment{smallblockcolorverbatim}%
{\expandafter\let\csname verbatim*\endcsname\verbatim
\csname smallblockcolorverbatim*\endcsname}%
{\csname endsmallblockcolorverbatim*\endcsname}%

\makeatother

\newenvironment{colorverbatim*}%
{\newcommand*\inersmallblock[1][\colorverbatimcolor]{%
\newcommand*\innersmallblock[1][\colorverbatimmodel]{%
\definecolor{shadecolor}{####1}{##1}%
% supress vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
% start shaded and verbatim
\shaded
\csname verbatim*\endcsname
}%
\obeylines\expandafter\innersmallblock\noexpand
}%
\obeylines\expandafter\inersmallblock\noexpand
}%
{%
\csname endverbatim*\endcsname
\endshaded
}%

% The same as the starred, just need to replace
% \verbatim* by \verbatim:
\newenvironment{colorverbatim}
{\expandafter\let\csname verbatim*\endcsname\verbatim
\csname colorverbatim*\endcsname}%
{\csname endcolorverbatim*\endcsname}%


\begin{document}

\begin{smallblockcolorverbatim}
[]
This is smallblockcolorverbatim
\@nil -> \TeX is funny! 123456
\end{smallblockcolorverbatim}

\begin{smallblockcolorverbatim}[MidnightBlue][named]
[]
This is smallblockcolorverbatim 123456 123456
\@nil -> \TeX is funny!
\end{smallblockcolorverbatim}

\begin{smallblockcolorverbatim*}
[]
This is smallblockcolorverbatim* 123456
\@nil -> \TeX is funny!
\end{smallblockcolorverbatim*}

\begin{smallblockcolorverbatim*}[MidnightBlue][named]
[]
This is smallblockcolorverbatim*
\@nil -> \TeX is funny! 123456 123456 123456 123456
\end{smallblockcolorverbatim*}

\begin{colorverbatim}
[]
This is colorverbatim
\@nil -> \TeX is funny! 123456
\end{colorverbatim}

\begin{colorverbatim}[MidnightBlue][named]
[]
This is colorverbatim 123456 123456 123456 123
\@nil -> \TeX is funny!
\end{colorverbatim}

\begin{colorverbatim*}
[]
This is colorverbatim*
\@nil -> \TeX is funny! 123456
\end{colorverbatim*}

\begin{colorverbatim*}[MidnightBlue][named]
[]
This is colorverbatim* 123456 123456 123456 12
\@nil -> \TeX is funny!
\end{colorverbatim*}

\end{document}
Piet
2005-12-02 08:52:10 UTC
Permalink
Hi Ulrich,

I'm very interested in your code, but I can't get it to work and even
the examples you gave me don't compile very well. Maybe there's
seomthing wrong with my system? I'm using TeXnicCenter under WinXP.
This is what I get for the first example (the errors for the final code
look similar):

This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4)
(preloaded format=latex 2005.10.6) 2 DEC 2005 09:44
entering extended mode
**C:/Documents*and*Settings/pieterp/Desktop/LaTeX1.tex
(C:/Documents and Settings/pieterp/Desktop/LaTeX1.tex
LaTeX2e <2003/12/01>
Babel <v3.8a> and hyphenation patterns for english, french, german,
ngerman, dumylang, nohyphenation, loaded.
(C:\texmf\tex\latex\base\article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(C:\texmf\tex\latex\base\size10.clo
File: size10.clo 2004/02/16 v1.4f Standard LaTeX file (size option)
)
\***@part=\count79
\***@section=\count80
\***@subsection=\count81
\***@subsubsection=\count82
\***@paragraph=\count83
\***@subparagraph=\count84
\***@figure=\count85
\***@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (C:\texmf\tex\latex\tools\verbatim.sty
Package: verbatim 2003/08/22 v1.5q LaTeX2e package for verbatim
enhancements
\***@verbatim=\toks14
\***@line=\toks15
\***@in@stream=\read1
) (C:\texmf\tex\latex\ltxmisc\framed.sty
Package: framed 2003/07/21 v 0.8a: framed or shaded text with page
breaks
\FrameRule=\dimen103
\FrameSep=\dimen104
)
(C:\texmf\tex\latex\graphics\color.sty
Package: color 1999/02/16 v1.0i Standard LaTeX Color (DPC)
(C:\texmf\tex\latex\00miktex\color.cfg
File: color.cfg 2003/03/08 v1.0 MiKTeX 'color' configuration
)
Package color Info: Driver file: pdftex.def on input line 125.
(C:\texmf\tex\latex\graphics\pdftex.def
File: pdftex.def 2002/06/19 v0.03k graphics/color for pdftex
\***@gobject=\count87
)
(C:\texmf\tex\latex\graphics\dvipsnam.def
File: dvipsnam.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
))
! Missing } inserted.
<inserted text>
}
l.17 \endverbatim

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Extra \endgroup.
<recently read> \endgroup

l.17 \endverbatim

Things are pretty mixed up, but I think the worst is over.

! Too many }'s.
\endMakeFramed ...\kern \z@ \penalty -100 \egroup
\begingroup
\***@frame \en...
l.18 \endshaded

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

! Undefined control sequence.
\***@frame ...ageshrink \advance \dimen@ -\***@frh
\relax \expandafter
\endgr...
l.18 \endshaded

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing number, treated as zero.
<to be read again>
\relax
l.18 \endshaded

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again>
\relax
l.18 \endshaded

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Too many }'s.
l.20 }
%
You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

(LaTeX1.aux)
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
(C:\texmf\tex\context\base\supp-pdf.tex
(C:\texmf\tex\context\base\supp-mis.tex
loading : Context Support Macros / Miscellaneous
\protectiondepth=\count88
\scratchcounter=\count89
\scratchtoks=\toks16
\scratchdimen=\dimen105
\scratchskip=\skip43
\scratchmuskip=\muskip10
\scratchbox=\box26
\scratchread=\read2
\scratchwrite=\write3
\zeropoint=\dimen106
\onepoint=\dimen107
\onebasepoint=\dimen108
\minusone=\count90
\thousandpoint=\dimen109
\onerealpoint=\dimen110
\emptytoks=\toks17
\nextbox=\box27
\nextdepth=\dimen111
\everyline=\toks18
\!!counta=\count91
\!!countb=\count92
\recursecounter=\count93
)
loading : Context Support Macros / PDF (2004.03.26)
\nofMPsegments=\count94
\nofMParguments=\count95
\everyMPtoPDFconversion=\toks19
)
Package color Info: Redefining color shadecolor on input line 29.


! LaTeX Error: \begin{colorverbatim} on input line 29 ended by
\end{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.34 \end{document}

Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.

(LaTeX1.aux)
! You can't use `\end' in internal vertical mode.
\enddocument ... \endgroup \deadcycles \z@ \@@end

l.34 \end{document}

Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.


! LaTeX Error: \begin{colorverbatim} on input line 29 ended by
\end{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.34 \end{document}

Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.

! Missing } inserted.
<inserted text>
}
l.34 \end{document}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

)
! Emergency stop.
<*> ...nts*and*Settings/pieterp/Desktop/LaTeX1.tex

*** (job aborted, no legal \end found)
Ulrich Diez
2005-12-02 12:37:00 UTC
Permalink
If I got it right, the counters which I did introduce in the document-preamble
of my example between the comments (it's one large document) did not get
assigned. There should be \colorverbatims and \colorverbatimwidth
mentioned in the .log-file, but they are not.
Are you sure you copied/pasted the _whole_ example, including
the preamble and all macro-definitions?
In case of doubt you can send a file-attachment to
***@alumni.uni-tuebingen.de so that I can reproduce the
problem.

Sincerely

Ulrich
Post by Piet
Hi Ulrich,
I'm very interested in your code, but I can't get it to work and even
the examples you gave me don't compile very well. Maybe there's
seomthing wrong with my system? I'm using TeXnicCenter under WinXP.
This is what I get for the first example (the errors for the final code
This is pdfeTeX, Version 3.141592-1.20a-rc7.2-2.2 (MiKTeX 2.4)
(preloaded format=latex 2005.10.6) 2 DEC 2005 09:44
entering extended mode
**C:/Documents*and*Settings/pieterp/Desktop/LaTeX1.tex
(C:/Documents and Settings/pieterp/Desktop/LaTeX1.tex
LaTeX2e <2003/12/01>
Babel <v3.8a> and hyphenation patterns for english, french, german,
ngerman, dumylang, nohyphenation, loaded.
(C:\texmf\tex\latex\base\article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(C:\texmf\tex\latex\base\size10.clo
File: size10.clo 2004/02/16 v1.4f Standard LaTeX file (size option)
)
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (C:\texmf\tex\latex\tools\verbatim.sty
Package: verbatim 2003/08/22 v1.5q LaTeX2e package for verbatim
enhancements
) (C:\texmf\tex\latex\ltxmisc\framed.sty
Package: framed 2003/07/21 v 0.8a: framed or shaded text with page
breaks
\FrameRule=\dimen103
\FrameSep=\dimen104
)
(C:\texmf\tex\latex\graphics\color.sty
Package: color 1999/02/16 v1.0i Standard LaTeX Color (DPC)
(C:\texmf\tex\latex\00miktex\color.cfg
File: color.cfg 2003/03/08 v1.0 MiKTeX 'color' configuration
)
Package color Info: Driver file: pdftex.def on input line 125.
(C:\texmf\tex\latex\graphics\pdftex.def
File: pdftex.def 2002/06/19 v0.03k graphics/color for pdftex
)
(C:\texmf\tex\latex\graphics\dvipsnam.def
File: dvipsnam.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
))
! Missing } inserted.
<inserted text>
}
l.17 \endverbatim
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.
! Extra \endgroup.
<recently read> \endgroup
l.17 \endverbatim
Things are pretty mixed up, but I think the worst is over.
! Too many }'s.
\begingroup
l.18 \endshaded
You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.
! Undefined control sequence.
\relax \expandafter
\endgr...
l.18 \endshaded
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Missing number, treated as zero.
<to be read again>
\relax
l.18 \endshaded
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
! Illegal unit of measure (pt inserted).
<to be read again>
\relax
l.18 \endshaded
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)
! Too many }'s.
l.20 }
%
You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.
(LaTeX1.aux)
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line
22.
LaTeX Font Info: ... okay on input line 22.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 22.
LaTeX Font Info: ... okay on input line 22.
(C:\texmf\tex\context\base\supp-pdf.tex
(C:\texmf\tex\context\base\supp-mis.tex
loading : Context Support Macros / Miscellaneous
\protectiondepth=\count88
\scratchcounter=\count89
\scratchtoks=\toks16
\scratchdimen=\dimen105
\scratchskip=\skip43
\scratchmuskip=\muskip10
\scratchbox=\box26
\scratchread=\read2
\scratchwrite=\write3
\zeropoint=\dimen106
\onepoint=\dimen107
\onebasepoint=\dimen108
\minusone=\count90
\thousandpoint=\dimen109
\onerealpoint=\dimen110
\emptytoks=\toks17
\nextbox=\box27
\nextdepth=\dimen111
\everyline=\toks18
\!!counta=\count91
\!!countb=\count92
\recursecounter=\count93
)
loading : Context Support Macros / PDF (2004.03.26)
\nofMPsegments=\count94
\nofMParguments=\count95
\everyMPtoPDFconversion=\toks19
)
Package color Info: Redefining color shadecolor on input line 29.
! LaTeX Error: \begin{colorverbatim} on input line 29 ended by
\end{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.34 \end{document}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
(LaTeX1.aux)
! You can't use `\end' in internal vertical mode.
l.34 \end{document}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.
! LaTeX Error: \begin{colorverbatim} on input line 29 ended by
\end{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.34 \end{document}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
! Missing } inserted.
<inserted text>
}
l.34 \end{document}
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.
)
! Emergency stop.
<*> ...nts*and*Settings/pieterp/Desktop/LaTeX1.tex
*** (job aborted, no legal \end found)
Piet
2005-12-02 13:20:59 UTC
Permalink
It seems like the line breaks caused the problem, it works pretty well
now. If have some additional problems/questions:

- When I try to define a color like this
\definecolor{mygray}{rgb}{0.2,0.2,0.2} I get an error saying mygray not
defined. Any thoughts about what could be going wrong here?
- I still have some annoying space above the verbatim text, but
changing topsep only changes the white space above the shading, not the
space between the top of the shaded box and the first line of text.

In order to avoid any confusion: I'm now using the second script given
in Ulrich's first post.

Many thanks!
Piet
Ulrich Diez
2005-12-02 15:03:23 UTC
Permalink
Post by Piet
It seems like the line breaks caused the problem, it works pretty well
- When I try to define a color like this
\definecolor{mygray}{rgb}{0.2,0.2,0.2} I get an error saying mygray not
defined. Any thoughts about what could be going wrong here?
This specifies a color but it does not add the color to a specific color-scheme.
You need to do so before you can use it for declaring other colors based
on it.
\DefineNamedColor{named}{MyGray}{rgb}{0.2,0.2,0.2}
Post by Piet
- I still have some annoying space above the verbatim text, but
changing topsep only changes the white space above the shading, not the
space between the top of the shaded box and the first line of text.
Line-spacing is related to \lineskip, \lineskiplimit, \baselineskip.
The small white-space between the line above the colored box and
the colored box is due to these parameters.
Perhaps playing around with \fboxsep will decrease the small colored-
space between the top of the color-block and the first verbatim-line
in that box.
Post by Piet
In order to avoid any confusion: I'm now using the second script given
in Ulrich's first post.
Don't use it. It will fail as soon as the first item in the listing is either
a control-sequence, or "[" or "{"...
Use the script which I posted today (Fri, 2 Dec 2005 07:14:32 +0100)
under the ID: dmoor5$d42$***@newsserv.zdv.uni-tuebingen.de

Ulrich
Ulrich Diez
2005-12-02 16:18:35 UTC
Permalink
Post by Piet
It seems like the line breaks caused the problem, it works pretty well
- When I try to define a color like this
\definecolor{mygray}{rgb}{0.2,0.2,0.2} I get an error saying mygray not
defined. Any thoughts about what could be going wrong here?
Just fond another issue in the environments:
The optional arguments need to be expanded before internally calling
\definecolor.
This is a fixed example where you can easily specify rgb-colors and
the like also. I also decided to put it into a .sty-file. Though you can
load this by \usepackage, I do not consider this a package in the sense
of the namig- or licensing-stuff.

<--------------begin of colrverb.sty----------------->
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{colrverb}
[2005/02/12 v1.00beta1 verbatim and colors]
%% Author: Ulrich Diez
%% License: Do with it whatever you want.
%%
%% Usage:
%% There are 4 environments.
%%
%% Each environment has two optional arguments:
%% - The first optional argument specifies the background-color
%% - The second optional argument specifies the color-model
%% If they are not specified, standard-values which are specified
%% in \colorverbatimcolor respective \colorverbatimmodel will
%% be used.
%%
%% 1. colorverbatim
%% ----------------
%% The color-block's width equals the linewidth, spaces
%% are not visible.
%%
%% 2. colorverbatim*
%% -----------------
%% The color-block's width equals the linewidth, spaces
%% are visible (_).
%%
%% 3. smallblockcolorverbatim
%% --------------------------
%% The color-block is just as wide as the widest line
%% in the listing, spaces are not visible.
%%
%%
%% 4. smallblockcolorverbatim*
%% ---------------------------
%% The color-block is just as wide as the widest line
%% in the listing, spaces are visible (_).
%%
%% Environments 3 and 4 detect width of textblock by means of
%% the aux-file. That means you may have to run LaTeX _twice_
%% after having something changed.
%%
%%
\RequirePackage{verbatim}%
\RequirePackage{framed}%
\RequirePackage{color}%
%
% Each time when a new smallblockcolorverbatim-listing is started,
% this counter gets "stepped".
\newcommand*\colorverbatims{}%
\newcount\colorverbatims
\colorverbatims=0\relax
%
% Length of the current line in a smallblockcolorverbatim-listing.
\newcommand*\colorverbatimwidth{}%
\newdimen\colorverbatimwidth
%
% standard-color if optional color-argument is not specified.
\newcommand*\colorverbatimcolor{Green}%
% standard-model if optional model-argument is not specified.
\newcommand*\colorverbatimmodel{named}%
%
% The environments:
%
\newenvironment{smallblockcolorverbatim*}%
{\expandafter\newcommand\expandafter*\expandafter\inersmallblock
\expandafter[\expandafter1\expandafter]\expandafter[\colorverbatimcolor]{%
\expandafter\newcommand\expandafter*\expandafter\innersmallblock
\expandafter[\expandafter1\expandafter]\expandafter[\colorverbatimmodel]{%
\definecolor{shadecolor}{####1}{##1}%
% supress vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
\global\advance\colorverbatims by 1\relax
\csname colorverbatimhsize\number\colorverbatims\endcsname
\expandafter\gdef
\csname colorverbatimhsize\number\colorverbatims\endcsname{0pt}%
\def\***@processline{%
\settowidth{\colorverbatimwidth}{\the\***@line}%
\expandafter\ifdim
\csname colorverbatimhsize\number\colorverbatims\endcsname
<\colorverbatimwidth\relax
\expandafter\xdef
\csname colorverbatimhsize\number\colorverbatims\endcsname
{\the\colorverbatimwidth}%
\fi
\the\***@line\par
}%
% start shaded and verbatim
\shaded
\csname verbatim*\endcsname
}%
\obeylines\expandafter\innersmallblock\noexpand
}%
\obeylines\expandafter\inersmallblock\noexpand
}%
{%
\csname endverbatim*\endcsname
\endshaded
\immediate\write\@auxout{%
\string\expandafter\string\gdef
\string\csname\space colorverbatimhsize\number\colorverbatims
\string\endcsname
{\string
\hsize=\csname colorverbatimhsize\number\colorverbatims\endcsname}%
\string\relax
}%
}%
%
%
%
\newenvironment{smallblockcolorverbatim}%
{\expandafter\let\csname verbatim*\endcsname\verbatim
\csname smallblockcolorverbatim*\endcsname}%
{\csname endsmallblockcolorverbatim*\endcsname}%
%
%
%
\newenvironment{colorverbatim*}%
{\expandafter\newcommand\expandafter*\expandafter\inersmallblock
\expandafter[\expandafter1\expandafter]\expandafter[\colorverbatimcolor]{%
\expandafter\newcommand\expandafter*\expandafter\innersmallblock
\expandafter[\expandafter1\expandafter]\expandafter[\colorverbatimmodel]{%
\definecolor{shadecolor}{####1}{##1}%
% supress vertical space which is inserted by
% environment above and below text:
\topsep=0ex\relax
% start shaded and verbatim
\shaded
\csname verbatim*\endcsname
}%
\obeylines\expandafter\innersmallblock\noexpand
}%
\obeylines\expandafter\inersmallblock\noexpand
}%
{%
\csname endverbatim*\endcsname
\endshaded
}%
%
%
%
\newenvironment{colorverbatim}
{\expandafter\let\csname verbatim*\endcsname\verbatim
\csname colorverbatim*\endcsname}%
{\csname endcolorverbatim*\endcsname}%
%
\endinput
%%
%% End of file `colrverb.sty'.
<--------------end of colrverb.sty------------------->

<--------------begin of example----------------->
\documentclass{article}
\usepackage[dvipsnames]{color}
\usepackage{colrverb}

\begin{document}

\begin{smallblockcolorverbatim}
[]
This is smallblockcolorverbatim
\@nil -> \TeX is funny! 123456
\end{smallblockcolorverbatim}

\begin{smallblockcolorverbatim}[MidnightBlue][named]
[]
This is smallblockcolorverbatim 123456 123456
\@nil -> \TeX is funny!
\end{smallblockcolorverbatim}

\begin{smallblockcolorverbatim*}
[]
This is smallblockcolorverbatim* 123456
\@nil -> \TeX is funny!
\end{smallblockcolorverbatim*}

\begin{smallblockcolorverbatim*}[MidnightBlue][named]
[]
This is smallblockcolorverbatim*
\@nil -> \TeX is funny! 123456 123456 123456 123456
\end{smallblockcolorverbatim*}

\begin{colorverbatim}
[]
This is colorverbatim
\@nil -> \TeX is funny! 123456
\end{colorverbatim}

\begin{colorverbatim}[0.7,0.4,0.8][rgb]
[]
This is colorverbatim 123456 123456 123456 123
\@nil -> \TeX is funny!
\end{colorverbatim}

\begin{colorverbatim*}
[]
This is colorverbatim*
\@nil -> \TeX is funny! 123456
\end{colorverbatim*}

\begin{colorverbatim*}[MidnightBlue][named]
[]
This is colorverbatim* 123456 123456 123456 12
\@nil -> \TeX is funny!
\end{colorverbatim*}

\end{document}
<--------------end of example------------------->

That's all - I hope.

Ulrich

Continue reading on narkive:
Loading...