From d957979dd4e52861630702f8e7337106371bb5c2 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 20 Apr 2008 14:58:50 +0000 Subject: [PATCH] Implement option lists. --- CHANGES | 2 ++ sphinx/latexwriter.py | 48 +++++++++++++++++++++++++++++++++++++ sphinx/texinputs/sphinx.sty | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/CHANGES b/CHANGES index 0e8df6288..16fe9aeac 100644 --- a/CHANGES +++ b/CHANGES @@ -70,6 +70,8 @@ Bugs fixed * 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. diff --git a/sphinx/latexwriter.py b/sphinx/latexwriter.py index 05162d8f0..8173c821b 100644 --- a/sphinx/latexwriter.py +++ b/sphinx/latexwriter.py @@ -27,6 +27,7 @@ HEADER = r'''%% Generated by Sphinx. \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 @@ class LaTeXTranslator(nodes.NodeVisitor): 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"\$"), diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index f3db46644..3721c2f55 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -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}}