[Python-checkins] r62529 - doctools/trunk/sphinx/texinputs/sphinx.sty

georg.brandl python-checkins at python.org
Sun Apr 27 18:46:20 CEST 2008


Author: georg.brandl
Date: Sun Apr 27 18:46:20 2008
New Revision: 62529

Log:
Add the possibility to have colored verbatim border and background.


Modified:
   doctools/trunk/sphinx/texinputs/sphinx.sty

Modified: doctools/trunk/sphinx/texinputs/sphinx.sty
==============================================================================
--- doctools/trunk/sphinx/texinputs/sphinx.sty	(original)
+++ doctools/trunk/sphinx/texinputs/sphinx.sty	Sun Apr 27 18:46:20 2008
@@ -15,16 +15,20 @@
 \RequirePackage{titlesec}
 
 \RequirePackage{color}
-\definecolor{py at InnerLinkColor}{rgb}{0.208,0.374,0.486}
-\definecolor{py at OuterLinkColor}{rgb}{0.216,0.439,0.388}
+\definecolor{InnerLinkColor}{rgb}{0.208,0.374,0.486}
+\definecolor{OuterLinkColor}{rgb}{0.216,0.439,0.388}
+% Define these colors to something not white if you want to have colored
+% background and border for code examples.
+\definecolor{VerbatimColor}{rgb}{1,1,1}
+\definecolor{VerbatimBorderColor}{rgb}{1,1,1}
 
 \RequirePackage[colorlinks,
 		breaklinks,
-		linkcolor=py at InnerLinkColor,
-		filecolor=py at OuterLinkColor,
-		menucolor=py at OuterLinkColor,
-		pagecolor=py at OuterLinkColor,
-		urlcolor=py at OuterLinkColor,
+		linkcolor=InnerLinkColor,
+		filecolor=OuterLinkColor,
+		menucolor=OuterLinkColor,
+		pagecolor=OuterLinkColor,
+		urlcolor=OuterLinkColor,
 	       ]{hyperref}
 
 \RequirePackage{framed}
@@ -234,8 +238,52 @@
 
 \newcommand{\py at modulebadkey}{{--just-some-junk--}}
 
-%%  Lots of index-entry generation support.
+% Redefine the Verbatim environment to allow border and background colors.
+%
+\let\py at OldVerbatim=\Verbatim
+\let\py at OldEndVerbatim=\endVerbatim
+
+% Play with vpsace to be able to keep the indentation.
+\newlength\distancetoright
+\newlength\leftsidespace
+\def\mycolorbox#1{%
+  \setlength\leftsidespace{\@totalleftmargin}%
+  \setlength\distancetoright{\textwidth}%
+  \advance\distancetoright -\@totalleftmargin %
+  \noindent\hspace*{\@totalleftmargin}%
+  \fcolorbox{VerbatimBorderColor}{VerbatimColor}{%
+  \begin{minipage}{\distancetoright}%
+    \smallskip%
+    \noindent\hspace*{-\leftsidespace}%
+    #1
+  \end{minipage}%
+  }%
+}
+\def\FrameCommand{\mycolorbox}
+
+\renewcommand{\Verbatim}[1][1]{%
+  % The list environement is needed to control perfectly the vertical
+  % space.
+  \list{}{%
+  \setlength\parskip{0pt}%
+  \setlength\itemsep{0ex}%
+  \setlength\topsep{0ex}%
+  \setlength\partopsep{0pt}%
+  \setlength\leftmargin{0pt}%
+  }%
+  \item\MakeFramed {\FrameRestore}%
+     \small%
+    \py at OldVerbatim[#1]%
+}
+\renewcommand{\endVerbatim}{%
+    \py at OldEndVerbatim%
+  \endMakeFramed%
+  \endlist%
+}
 
+
+% Lots of index-entry generation support.
+%
 % Command to wrap around stuff that refers to function / module /
 % attribute names  in the index.  Default behavior: like \code{}.  To
 % just keep the index entries in the roman font, uncomment the second


More information about the Python-checkins mailing list