summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcben <cben@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-01-14 14:34:05 +0000
committercben <cben@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-01-14 14:34:05 +0000
commitd786670fc8560169cc6740e1131579b172ce8261 (patch)
tree1adab00e8f22287698dd6b4545cfb6409988bc3a
parentefb4d2a5941cdbb1d357b7dbc8012376c9a0bf17 (diff)
downloaddocutils-d786670fc8560169cc6740e1131579b172ce8261.tar.gz
Implemented support for multiple author,organization,address,contact fields with use_latex_docinfo.
Still has a bug: the document must have a title for \maketitle to be emitted. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@2937 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/docutils/writers/latex2e.py48
-rw-r--r--docutils/test/functional/expected/latex_docinfo.tex85
-rw-r--r--docutils/test/functional/input/latex_docinfo.txt13
-rw-r--r--docutils/test/functional/tests/latex_docinfo.py12
4 files changed, 138 insertions, 20 deletions
diff --git a/docutils/docutils/writers/latex2e.py b/docutils/docutils/writers/latex2e.py
index 002e6f492..e90f2d1c2 100644
--- a/docutils/docutils/writers/latex2e.py
+++ b/docutils/docutils/writers/latex2e.py
@@ -349,7 +349,7 @@ class DocumentClass:
return self._deepest_section
class Table:
- """ Manage a table while traversing.
+ """ Manage a table while traversing.
Maybe change to a mixin defining the visit/departs, but then
class Table internal variables are in the Translator.
"""
@@ -381,7 +381,7 @@ class Table:
return ''
def get_latex_type(self):
return self._latex_type
-
+
def set(self,attr,value):
self._attrs[attr] = value
def get(self,attr):
@@ -442,7 +442,7 @@ class Table:
return latex_table_spec+bar
def get_column_width(self):
- """ return columnwidth for current cell (not multicell)
+ """ return columnwidth for current cell (not multicell)
"""
return "%.2f\\locallinewidth" % self._col_width[self._cell_in_row-1]
@@ -471,7 +471,7 @@ class Table:
for i in range(len(self._rowspan)):
if (self._rowspan[i]>0):
self._rowspan[i] -= 1
-
+
if self._table_style == 'standard':
rowspans = []
for i in range(len(self._rowspan)):
@@ -507,7 +507,7 @@ class Table:
def visit_entry(self):
self._cell_in_row += 1
-
+
class LaTeXTranslator(nodes.NodeVisitor):
# When options are given to the documentclass, latex will pass them
@@ -677,8 +677,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.topic_class = ''
# column specification for tables
self.table_caption = None
- # do we have one or more authors
- self.author_stack = None
+ # if use_latex_docinfo: collects lists of author/organization/contact/address lines
+ self.author_stack = []
# Flags to encode
# ---------------
# verbatim: to tell encode not to encode.
@@ -927,14 +927,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_authors(self, node):
# not used: visit_author is called anyway for each author.
- if self.use_latex_docinfo:
- self.author_stack = []
+ pass
def depart_authors(self, node):
- if self.use_latex_docinfo:
- self.head.append('\\author{%s}\n' % \
- ' \\and '.join(self.author_stack) )
- self.author_stack = None
+ pass
def visit_block_quote(self, node):
self.body.append( '\\begin{quote}\n')
@@ -1115,6 +1111,10 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.docinfo.append('\\begin{tabularx}{\\docinfowidth}{lX}\n')
def depart_docinfo(self, node):
+ if self.use_latex_docinfo and self.author_stack:
+ self.head.append('\\author{%s}\n' % \
+ ' \\and\n'.join(['~\\\\\n'.join(author_lines)
+ for author_lines in self.author_stack]) )
self.docinfo.append('\\end{tabularx}\n')
self.docinfo.append('\\end{center}\n')
self.body = self.docinfo + self.body
@@ -1128,14 +1128,22 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.pdfauthor = self.attval(node.astext())
else:
self.pdfauthor += self.author_separator + self.attval(node.astext())
- if self.use_latex_docinfo:
- if self.author_stack == None:
- self.head.append('\\author{%s}\n' % self.attval(node.astext()))
+ if self.use_latex_docinfo:
+ if name in ('author', 'organization', 'contact', 'address'):
+ # We attach these to the last author. If any of them precedes
+ # the first author, put them in a separate "author" group (for
+ # no better semantics).
+ if name == 'author' or not self.author_stack:
+ self.author_stack.append([])
+ if name == 'address': # newlines are meaningful
+ self.insert_newline = 1
+ text = self.encode(node.astext())
+ self.insert_newline = 0
else:
- self.author_stack.append( self.attval(node.astext()) )
+ text = self.attval(node.astext())
+ self.author_stack[-1].append(text)
raise nodes.SkipNode
- elif name == 'date':
- if self.use_latex_docinfo:
+ elif name == 'date':
self.head.append('\\date{%s}\n' % self.attval(node.astext()))
raise nodes.SkipNode
self.docinfo.append('\\textbf{%s}: &\n\t' % self.language_label(name))
@@ -1186,7 +1194,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
for bi in self._bibitems:
self.body.append('\\bibitem[%s]{%s}{%s}\n' % (bi[0], bi[0], bi[1]))
self.body.append('\\end{thebibliography}\n')
-
+
self.body_suffix.append('\\end{document}\n')
def visit_emphasis(self, node):
diff --git a/docutils/test/functional/expected/latex_docinfo.tex b/docutils/test/functional/expected/latex_docinfo.tex
new file mode 100644
index 000000000..4411b52bc
--- /dev/null
+++ b/docutils/test/functional/expected/latex_docinfo.tex
@@ -0,0 +1,85 @@
+\documentclass[10pt,a4paper,english]{article}
+\usepackage{babel}
+\usepackage{ae}
+\usepackage{aeguill}
+\usepackage{shortvrb}
+\usepackage[latin1]{inputenc}
+\usepackage{tabularx}
+\usepackage{longtable}
+\setlength{\extrarowheight}{2pt}
+\usepackage{amsmath}
+\usepackage{graphicx}
+\usepackage{color}
+\usepackage{multirow}
+\usepackage{ifthen}
+\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref}
+\usepackage[DIV12]{typearea}
+%% generator Docutils: http://docutils.sourceforge.net/
+\newlength{\admonitionwidth}
+\setlength{\admonitionwidth}{0.9\textwidth}
+\newlength{\docinfowidth}
+\setlength{\docinfowidth}{0.9\textwidth}
+\newlength{\locallinewidth}
+\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}}
+% begin: floats for footnotes tweaking.
+\setlength{\floatsep}{0.5em}
+\setlength{\textfloatsep}{\fill}
+\addtolength{\textfloatsep}{3em}
+\renewcommand{\textfraction}{0.5}
+\renewcommand{\topfraction}{0.5}
+\renewcommand{\bottomfraction}{0.5}
+\setcounter{totalnumber}{50}
+\setcounter{topnumber}{50}
+\setcounter{bottomnumber}{50}
+% end floats for footnotes
+% some commands, that could be overwritten in the style file.
+\newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}}
+\newcommand{\titlereference}[1]{\textsl{#1}}
+% end of "some commands"
+\title{Title}
+\author{Foo Fred~\\
+Food Foomatics {\&} Friends~\\
+foo@food.example.info~\\
+Fox St 13~\\
+Foowood \and
+Bar Barney~\\
+Bar-BQ Bar~\\
+1-800-BARBQBAR~\\
+Barbara St 16~\\
+South Barwell}
+\hypersetup{
+pdftitle={Title},
+pdfauthor={Foo Fred;Bar Barney}
+}
+\raggedbottom
+\begin{document}
+\maketitle
+
+%___________________________________________________________________________
+\begin{center}
+\begin{tabularx}{\docinfowidth}{lX}
+\end{tabularx}
+\end{center}
+
+\setlength{\locallinewidth}{\linewidth}
+
+\end{document}
diff --git a/docutils/test/functional/input/latex_docinfo.txt b/docutils/test/functional/input/latex_docinfo.txt
new file mode 100644
index 000000000..985a03ecd
--- /dev/null
+++ b/docutils/test/functional/input/latex_docinfo.txt
@@ -0,0 +1,13 @@
+Title
+*****
+
+:Author: Foo Fred
+:Organization: Food Foomatics & Friends
+:Contact: foo@food.example.info
+:Address: Fox St 13
+ Foowood
+:Author: Bar Barney
+:Organization: Bar-BQ Bar
+:Contact: 1-800-BARBQBAR
+:Address: Barbara St 16
+ South Barwell
diff --git a/docutils/test/functional/tests/latex_docinfo.py b/docutils/test/functional/tests/latex_docinfo.py
new file mode 100644
index 000000000..3f9c34455
--- /dev/null
+++ b/docutils/test/functional/tests/latex_docinfo.py
@@ -0,0 +1,12 @@
+# Source and destination file names.
+test_source = "latex_docinfo.txt"
+test_destination = "latex_docinfo.tex"
+
+# Keyword parameters passed to publish_file.
+reader_name = "standalone"
+parser_name = "rst"
+writer_name = "latex"
+
+# Extra setting we need
+
+settings_overrides['use_latex_docinfo'] = 1