[Python-checkins] r62415 - in doctools/trunk: CHANGES sphinx/latexwriter.py sphinx/texinputs/sphinx.sty

georg.brandl python-checkins at python.org
Sun Apr 20 16:58:50 CEST 2008


Author: georg.brandl
Date: Sun Apr 20 16:58:50 2008
New Revision: 62415

Log:
Implement option lists.


Modified:
   doctools/trunk/CHANGES
   doctools/trunk/sphinx/latexwriter.py
   doctools/trunk/sphinx/texinputs/sphinx.sty

Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES	(original)
+++ doctools/trunk/CHANGES	Sun Apr 20 16:58:50 2008
@@ -70,6 +70,8 @@
 
 * sphinx.htmlwriter: Don't use os.path for joining image HREFs.
 
+* sphinx.latexwriter: Implement option lists.
+
 * sphinx.roles: Fix referencing glossary terms with explicit targets.
 
 * sphinx.environment: Don't swallow TOC entries when resolving subtrees.

Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py	(original)
+++ doctools/trunk/sphinx/latexwriter.py	Sun Apr 20 16:58:50 2008
@@ -27,6 +27,7 @@
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
 \usepackage[colorlinks,breaklinks]{hyperref}
+\usepackage{tabularx}
 \title{%(title)s}
 \date{%(date)s}
 \release{%(release)s}
@@ -762,6 +763,53 @@
         if not done:
             self.body.append('\\end{quote}\n')
 
+    # option node handling copied from docutils' latex writer
+
+    def visit_option(self, node):
+        if self.context[-1]:
+            # this is not the first option
+            self.body.append(', ')
+    def depart_option(self, node):
+        # flag that the first option is done.
+        self.context[-1] += 1
+
+    def visit_option_argument(self, node):
+        """The delimiter betweeen an option and its argument."""
+        self.body.append(node.get('delimiter', ' '))
+    def depart_option_argument(self, node):
+        pass
+
+    def visit_option_group(self, node):
+        self.body.append('\\item [')
+        # flag for first option
+        self.context.append(0)
+    def depart_option_group(self, node):
+        self.context.pop() # the flag
+        self.body.append('] ')
+
+    def visit_option_list(self, node):
+        self.body.append('% [option list]\n')
+        self.body.append('\\begin{optionlist}{3cm}\n')
+    def depart_option_list(self, node):
+        self.body.append('\\end{optionlist}\n')
+
+    def visit_option_list_item(self, node):
+        pass
+    def depart_option_list_item(self, node):
+        pass
+
+    def visit_option_string(self, node):
+        pass
+    def depart_option_string(self, node):
+        pass
+
+    def visit_description(self, node):
+        self.body.append( ' ' )
+    def depart_description(self, node):
+        pass
+
+    # text handling
+
     replacements = [
         (u"\\", u"\x00"),
         (u"$", ur"\$"),

Modified: doctools/trunk/sphinx/texinputs/sphinx.sty
==============================================================================
--- doctools/trunk/sphinx/texinputs/sphinx.sty	(original)
+++ doctools/trunk/sphinx/texinputs/sphinx.sty	Sun Apr 20 16:58:50 2008
@@ -1268,3 +1268,28 @@
 
 % Tell TeX about pathological hyphenation cases:
 \hyphenation{Base-HTTP-Re-quest-Hand-ler}
+
+
+% The following is stuff copied from docutils' latex writer.
+%
+\newcommand{\optionlistlabel}[1]{\bf #1 \hfill}
+\newenvironment{optionlist}[1]
+{\begin{list}{}
+  {\setlength{\labelwidth}{#1}
+   \setlength{\rightmargin}{1cm}
+   \setlength{\leftmargin}{\rightmargin}
+   \addtolength{\leftmargin}{\labelwidth}
+   \addtolength{\leftmargin}{\labelsep}
+   \renewcommand{\makelabel}{\optionlistlabel}}
+}{\end{list}}
+
+\newlength{\lineblockindentation}
+\setlength{\lineblockindentation}{2.5em}
+\newenvironment{lineblock}[1]
+{\begin{list}{}
+  {\setlength{\partopsep}{\parskip}
+   \addtolength{\partopsep}{\baselineskip}
+   \topsep0pt\itemsep0.15\baselineskip\parsep0pt
+   \leftmargin#1}
+ \raggedright}
+{\end{list}}


More information about the Python-checkins mailing list