[Python-checkins] r62665 - in doctools/trunk: CHANGES doc/conf.py doc/config.rst doc/ext/appapi.rst doc/markup/misc.rst sphinx/addnodes.py sphinx/builder.py sphinx/config.py sphinx/directives.py sphinx/htmlwriter.py sphinx/latexwriter.py sphinx/quickstart.py sphinx/texinputs/Makefile sphinx/texinputs/howto.cls sphinx/texinputs/manual.cls sphinx/texinputs/sphinx.sty sphinx/texinputs/tabulary.sty

georg.brandl python-checkins at python.org
Sat May 3 20:14:14 CEST 2008


Author: georg.brandl
Date: Sat May  3 20:14:13 2008
New Revision: 62665

Log:
* New LaTeX table handling.
* Support parts in LaTeX output.


Added:
   doctools/trunk/sphinx/texinputs/tabulary.sty
Modified:
   doctools/trunk/CHANGES
   doctools/trunk/doc/conf.py
   doctools/trunk/doc/config.rst
   doctools/trunk/doc/ext/appapi.rst
   doctools/trunk/doc/markup/misc.rst
   doctools/trunk/sphinx/addnodes.py
   doctools/trunk/sphinx/builder.py
   doctools/trunk/sphinx/config.py
   doctools/trunk/sphinx/directives.py
   doctools/trunk/sphinx/htmlwriter.py
   doctools/trunk/sphinx/latexwriter.py
   doctools/trunk/sphinx/quickstart.py
   doctools/trunk/sphinx/texinputs/Makefile
   doctools/trunk/sphinx/texinputs/howto.cls
   doctools/trunk/sphinx/texinputs/manual.cls
   doctools/trunk/sphinx/texinputs/sphinx.sty

Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES	(original)
+++ doctools/trunk/CHANGES	Sat May  3 20:14:13 2008
@@ -15,6 +15,12 @@
   independently from the source directory.  For that, a new command-line
   option ``-c`` has been added.
 
+* A new directive ``tabularcolumns`` can be used to give a tabular column
+  specification for LaTeX output.  Tables now use the ``tabulary`` package.
+
+* A new config value, `latex_use_parts`, can be used to enable parts in LaTeX
+  documents.
+
 Bugs fixed
 ----------
 
@@ -22,6 +28,8 @@
   master document.  Also encode non-ASCII characters as entities in TOC
   and index file.
 
+* Lots of little fixes to the LaTeX output and style.
+
 
 Release 0.2 (Apr 27, 2008)
 ==========================

Modified: doctools/trunk/doc/conf.py
==============================================================================
--- doctools/trunk/doc/conf.py	(original)
+++ doctools/trunk/doc/conf.py	Sat May  3 20:14:13 2008
@@ -123,6 +123,8 @@
 
 latex_logo = '_static/sphinx.png'
 
+#latex_use_parts = True
+
 # Additional stuff for the LaTeX preamble.
 #latex_preamble = ''
 

Modified: doctools/trunk/doc/config.rst
==============================================================================
--- doctools/trunk/doc/config.rst	(original)
+++ doctools/trunk/doc/config.rst	Sat May  3 20:14:13 2008
@@ -310,6 +310,13 @@
    configuration directory) that is the logo of the docs.  It is placed at the
    top of the title page.  Default: ``None``.
 
+.. confval:: latex_use_parts
+
+   If true, the topmost sectioning unit is parts, else it is chapters.  Default:
+   ``False``.
+
+   .. versionadded:: 0.2.1
+
 .. confval:: latex_appendices
 
    Documents to append as an appendix to all manuals.

Modified: doctools/trunk/doc/ext/appapi.rst
==============================================================================
--- doctools/trunk/doc/ext/appapi.rst	(original)
+++ doctools/trunk/doc/ext/appapi.rst	Sat May  3 20:14:13 2008
@@ -159,6 +159,8 @@
 
 These events are known to the core:
 
+.. tabularcolumns:: |l|L|L|
+
 ====================== =================================== =========
 Event name             Emitted when                        Arguments
 ====================== =================================== =========

Modified: doctools/trunk/doc/markup/misc.rst
==============================================================================
--- doctools/trunk/doc/markup/misc.rst	(original)
+++ doctools/trunk/doc/markup/misc.rst	Sat May  3 20:14:13 2008
@@ -39,3 +39,40 @@
    keep track of contributions), but you can set the configuration value
    :confval:`show_authors` to True to make them produce a paragraph in the
    output.
+
+
+Tables
+------
+
+Use standard reStructuredText tables.  They work fine in HTML output, however
+there are some gotchas when using tables in LaTeX: the column width is hard to
+determine correctly automatically.  For this reason, the following directive
+exists:
+
+.. directive:: .. tabularcolumns:: column spec
+
+   This directive gives a "column spec" for the next table occurring in the
+   source file.  The spec is the second argument to the LaTeX ``tabulary``
+   package's environment (which Sphinx uses to translate tables).  It can have
+   values like ::
+
+      |l|l|l|
+
+   which means three left-adjusted, nonbreaking columns.  For columns with
+   longer text that should automatically be broken, use either the standard
+   ``p{width}`` construct, or tabulary's automatic specifiers:
+
+   +-----+------------------------------------------+
+   |``L``| ragged-left column with automatic width  |
+   +-----+------------------------------------------+
+   |``R``| ragged-right column with automatic width |
+   +-----+------------------------------------------+
+   |``C``| centered column with automatic width     |
+   +-----+------------------------------------------+
+   |``J``| justified column with automatic width    |
+   +-----+------------------------------------------+
+
+   The automatic width is determined by rendering the content in the table, and
+   scaling them according to their share of the total width.
+
+   .. versionadded:: 0.2.1

Modified: doctools/trunk/sphinx/addnodes.py
==============================================================================
--- doctools/trunk/sphinx/addnodes.py	(original)
+++ doctools/trunk/sphinx/addnodes.py	Sat May  3 20:14:13 2008
@@ -66,10 +66,16 @@
 # module declaration
 class module(nodes.Element): pass
 
-# make them known to docutils. this is needed, because the HTMl writer
+# start of a file, used in the LaTeX builder only
+class start_of_file(nodes.Element): pass
+
+# tabular column specification, used for the LaTeX writer
+class tabular_col_spec(nodes.Element): pass
+
+# make them known to docutils. this is needed, because the HTML writer
 # will choke at some point if these are not added
 nodes._add_node_class_names("""index desc desc_content desc_signature desc_type
       desc_classname desc_name desc_parameterlist desc_parameter desc_optional
       centered versionmodified seealso productionlist production toctree
       pending_xref compact_paragraph highlightlang literal_emphasis
-      glossary acks module""".split())
+      glossary acks module start_of_file tabular_col_spec""".split())

Modified: doctools/trunk/sphinx/builder.py
==============================================================================
--- doctools/trunk/sphinx/builder.py	(original)
+++ doctools/trunk/sphinx/builder.py	Sat May  3 20:14:13 2008
@@ -775,6 +775,7 @@
                         self.warn('%s: toctree contains ref to nonexisting file %r' %
                                   (docname, includefile))
                     else:
+                        newnodes.append(addnodes.start_of_file())
                         newnodes.extend(subtree.children)
                 toctreenode.parent.replace(toctreenode, newnodes)
             return tree
@@ -813,7 +814,6 @@
         # the logo is handled differently
         if self.config.latex_logo:
             logobase = path.basename(self.config.latex_logo)
-            self.info(' '+logobase, nonl=1)
             shutil.copyfile(path.join(self.confdir, self.config.latex_logo),
                             path.join(self.outdir, logobase))
 

Modified: doctools/trunk/sphinx/config.py
==============================================================================
--- doctools/trunk/sphinx/config.py	(original)
+++ doctools/trunk/sphinx/config.py	Sat May  3 20:14:13 2008
@@ -69,6 +69,7 @@
         latex_logo = (None, False),
         latex_preamble = ('', False),
         latex_appendices = ([], False),
+        latex_use_parts = (False, False),
         latex_use_modindex = (True, False),
     )
 

Modified: doctools/trunk/sphinx/directives.py
==============================================================================
--- doctools/trunk/sphinx/directives.py	(original)
+++ doctools/trunk/sphinx/directives.py	Sat May  3 20:14:13 2008
@@ -815,3 +815,18 @@
 acks_directive.content = 1
 acks_directive.arguments = (0, 0, 0)
 directives.register_directive('acks', acks_directive)
+
+
+# ------ tabularcolumns directive ---------------------------------------------------
+
+def tabularcolumns_directive(name, arguments, options, content, lineno,
+                             content_offset, block_text, state, state_machine):
+    # support giving explicit tabulary column definition to latex
+    node = addnodes.tabular_col_spec()
+    node['spec'] = arguments[0]
+    return [node]
+
+tabularcolumns_directive.content = 0
+tabularcolumns_directive.arguments = (1, 0, 1)
+directives.register_directive('tabularcolumns', tabularcolumns_directive)
+

Modified: doctools/trunk/sphinx/htmlwriter.py
==============================================================================
--- doctools/trunk/sphinx/htmlwriter.py	(original)
+++ doctools/trunk/sphinx/htmlwriter.py	Sat May  3 20:14:13 2008
@@ -264,6 +264,9 @@
     def visit_index(self, node):
         raise nodes.SkipNode
 
+    def visit_tabular_col_spec(self, node):
+        raise nodes.SkipNode
+
     def visit_glossary(self, node):
         pass
     def depart_glossary(self, node):

Modified: doctools/trunk/sphinx/latexwriter.py
==============================================================================
--- doctools/trunk/sphinx/latexwriter.py	(original)
+++ doctools/trunk/sphinx/latexwriter.py	Sat May  3 20:14:13 2008
@@ -72,12 +72,14 @@
 
 # Helper classes
 
-class TableSpec:
+class Table(object):
     def __init__(self):
-        self.columnCount = 0
-        self.firstRow = 1
+        self.col = 0
+        self.colcount = 0
+        self.had_head = False
 
-class Desc:
+
+class Desc(object):
     def __init__(self, node):
         self.env = LaTeXTranslator.desc_map.get(node['desctype'], 'describe')
         self.ni = node['noindex']
@@ -86,7 +88,7 @@
 
 
 class LaTeXTranslator(nodes.NodeVisitor):
-    sectionnames = ["chapter", "chapter", "section", "subsection",
+    sectionnames = ["part", "chapter", "section", "subsection",
                     "subsubsection", "paragraph", "subparagraph"]
 
     def __init__(self, document, builder):
@@ -118,13 +120,19 @@
             'latex', builder.config.pygments_style)
         self.context = []
         self.descstack = []
+        self.table = None
+        self.next_table_colspec = None
         self.highlightlang = 'python'
         self.highlightlinenothreshold = sys.maxint
         self.written_ids = set()
         if docclass == 'manual':
-            self.top_sectionlevel = 0
+            if builder.config.latex_use_parts:
+                self.top_sectionlevel = -1
+            else:
+                self.top_sectionlevel = 0
         else:
             self.top_sectionlevel = 1
+        self.next_section_target = None
         # flags
         self.verbatim = None
         self.in_title = 0
@@ -141,20 +149,31 @@
                (self.need_graphicx and GRAPHICX or '') + \
                '\n\n' + \
                u''.join(self.body) + \
-               (self.options['modindex'] and '\\printmodindex\n' or '') + \
+               (self.options['modindex'] and
+                '\\renewcommand{\\indexname}{Module Index}'
+                '\\printmodindex'
+                '\\renewcommand{\\indexname}{Index}\n' or '') + \
                (FOOTER % self.options)
 
     def visit_document(self, node):
         if self.first_document == 1:
+            # the first document is all the regular content ...
             self.body.append('\\begin{document}\n\\maketitle\n\\tableofcontents\n')
             self.first_document = 0
         elif self.first_document == 0:
+            # ... and all others are the appendices
             self.body.append('\n\\appendix\n')
             self.first_document = -1
         self.sectionlevel = self.top_sectionlevel
     def depart_document(self, node):
         pass
 
+    def visit_start_of_file(self, node):
+        # This marks the begin of a new file; therefore the current module and
+        # class must be reset
+        self.body.append('\n\\resetcurrentobjects\n')
+        raise nodes.SkipNode
+
     def visit_highlightlang(self, node):
         self.highlightlang = node['lang']
         self.highlightlinenothreshold = node['linenothreshold']
@@ -167,11 +186,14 @@
         if not self.this_is_the_title:
             self.sectionlevel += 1
         self.body.append('\n\n')
-        if node.get('ids'):
-            for id in node['ids']:
-                if id not in self.written_ids:
-                    self.body.append(r'\hypertarget{%s}{}' % id)
-                    self.written_ids.add(id)
+        if self.next_section_target:
+            self.body.append(r'\hypertarget{%s}{}' % self.next_section_target)
+            self.next_section_target = None
+        #if node.get('ids'):
+        #    for id in node['ids']:
+        #        if id not in self.written_ids:
+        #            self.body.append(r'\hypertarget{%s}{}' % id)
+        #            self.written_ids.add(id)
     def depart_section(self, node):
         self.sectionlevel -= 1
 
@@ -355,75 +377,64 @@
     def visit_label(self, node):
         raise nodes.SkipNode
 
+    def visit_tabular_col_spec(self, node):
+        self.next_table_colspec = node['spec']
+        raise nodes.SkipNode
+
     def visit_table(self, node):
-        self.tableSpec = TableSpec()
+        if self.table:
+            raise NotImplementedError('Nested tables are not supported.')
+        self.table = Table()
+        self.body.append('\n\\begin{tabulary}{\\textwidth}')
     def depart_table(self, node):
-        self.tableSpec = None
+        self.body.append('\\end{tabulary}\n\n')
+        self.table = None
 
     def visit_colspec(self, node):
-        pass
+        self.table.colcount += 1
     def depart_colspec(self, node):
         pass
 
     def visit_tgroup(self, node):
-        columnCount = int(node.get('cols', 0))
-        self.tableSpec.columnCount = columnCount
-        if columnCount == 2:
-            self.body.append('\\begin{tableii}{l|l}{textrm}')
-        elif columnCount == 3:
-            self.body.append('\\begin{tableiii}{l|l|l}{textrm}')
-        elif columnCount == 4:
-            self.body.append('\\begin{tableiv}{l|l|l|l}{textrm}')
-        elif columnCount == 5:
-            self.body.append('\\begin{tablev}{l|l|l|l|l}{textrm}')
-        else:
-            self.builder.warn('table with too many columns, ignoring')
-            raise nodes.SkipNode
+        pass
     def depart_tgroup(self, node):
-        if self.tableSpec.columnCount == 2:
-            self.body.append('\n\\end{tableii}\n\n')
-        elif self.tableSpec.columnCount == 3:
-            self.body.append('\n\\end{tableiii}\n\n')
-        elif self.tableSpec.columnCount == 4:
-            self.body.append('\n\\end{tableiv}\n\n')
-        elif self.tableSpec.columnCount == 5:
-            self.body.append('\n\\end{tablev}\n\n')
+        pass
 
     def visit_thead(self, node):
-        pass
+        if self.next_table_colspec:
+            self.body.append('{%s}\n' % self.next_table_colspec)
+        else:
+            self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
+        self.next_table_colspec = None
+        self.body.append('\\hline\n')
+        self.table.had_head = True
     def depart_thead(self, node):
-        pass
+        self.body.append('\\hline\n')
 
     def visit_tbody(self, node):
-        pass
+        if not self.table.had_head:
+            self.visit_thead(node)
     def depart_tbody(self, node):
-        pass
+        self.body.append('\\hline\n')
 
     def visit_row(self, node):
-        if not self.tableSpec.firstRow:
-            if self.tableSpec.columnCount == 2:
-                self.body.append('\n\\lineii')
-            elif self.tableSpec.columnCount == 3:
-                self.body.append('\n\\lineiii')
-            elif self.tableSpec.columnCount == 4:
-                self.body.append('\n\\lineiv')
-            elif self.tableSpec.columnCount == 5:
-                self.body.append('\n\\linev')
+        self.table.col = 0
     def depart_row(self, node):
-        if self.tableSpec.firstRow:
-            self.tableSpec.firstRow = 0
+        self.body.append('\\\\\n')
 
     def visit_entry(self, node):
-        if self.tableSpec.firstRow:
-            self.body.append('{%s}' % self.encode(node.astext().strip(' ')))
-            raise nodes.SkipNode
+        if node.has_key('morerows') or node.has_key('morecols'):
+            raise NotImplementedError('Column or row spanning cells are not implemented.')
+        if self.table.col > 0:
+            self.body.append(' & ')
+        self.table.col += 1
+        if isinstance(node.parent.parent, nodes.thead):
+            self.body.append('\\textbf{')
+            self.context.append('}')
         else:
-            self.body.append('{')
+            self.context.append('')
     def depart_entry(self, node):
-        if self.tableSpec.firstRow:
-            pass
-        else:
-            self.body.append('}')
+        self.body.append(self.context.pop()) # header
 
     def visit_acks(self, node):
         # this is a list in the source, but should be rendered as a
@@ -591,25 +602,21 @@
             # indexing uses standard LaTeX index markup, so the targets
             # will be generated differently
             if not id.startswith('index-'):
-                self.body.append(r'\hypertarget{%s}{' % id)
-                return '}'
-            return ''
-
-        if not (node.has_key('refuri') or node.has_key('refid')
-                or node.has_key('refname')):
-            ctx = ''
-            for id in node['ids']:
-                if id not in self.written_ids:
-                    self.written_ids.add(id)
-                    ctx += add_target(id)
-            self.context.append(ctx)
-        elif node.has_key('refid') and node['refid'] not in self.written_ids:
-            self.context.append(add_target(node['refid']))
+                self.body.append(r'\hypertarget{%s}{}' % id)
+
+        if node.has_key('refid') and node['refid'] not in self.written_ids:
+            parindex = node.parent.index(node)
+            try:
+                next = node.parent[parindex+1]
+                if isinstance(next, nodes.section):
+                    self.next_section_target = node['refid']
+                    return
+            except IndexError:
+                pass
+            add_target(node['refid'])
             self.written_ids.add(node['refid'])
-        else:
-            self.context.append('')
     def depart_target(self, node):
-        self.body.append(self.context.pop())
+        pass
 
     indextype_map = {
         'module': 'refmodindex',

Modified: doctools/trunk/sphinx/quickstart.py
==============================================================================
--- doctools/trunk/sphinx/quickstart.py	(original)
+++ doctools/trunk/sphinx/quickstart.py	Sat May  3 20:14:13 2008
@@ -161,6 +161,10 @@
 # the title page.
 #latex_logo = None
 
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
 # Additional stuff for the LaTeX preamble.
 #latex_preamble = ''
 

Modified: doctools/trunk/sphinx/texinputs/Makefile
==============================================================================
--- doctools/trunk/sphinx/texinputs/Makefile	(original)
+++ doctools/trunk/sphinx/texinputs/Makefile	Sat May  3 20:14:13 2008
@@ -50,7 +50,7 @@
 
 clean:
 	rm -f *.pdf *.dvi *.ps
-	rm -f *.log *.ind *.aux *.toc *.syn *.idx *.out *.ilg
+	rm -f *.log *.ind *.aux *.toc *.syn *.idx *.out *.ilg *.pla
 
 .PHONY: all all-pdf all-dvi all-ps clean
 

Modified: doctools/trunk/sphinx/texinputs/howto.cls
==============================================================================
--- doctools/trunk/sphinx/texinputs/howto.cls	(original)
+++ doctools/trunk/sphinx/texinputs/howto.cls	Sat May  3 20:14:13 2008
@@ -3,7 +3,7 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesClass{howto}[1998/02/25 Document class (Python HOWTO)]
+\ProvidesClass{howto}[2008/05/01 Document class (Sphinx HOWTO)]
 
 \RequirePackage{fancybox}
 
@@ -12,44 +12,34 @@
 \ProcessOptions\relax
 \LoadClass[twoside]{article}
 
-\setcounter{secnumdepth}{1}
 
-% Optional packages:
+% Set some sane defaults for section numbering depth and TOC depth.  You can
+% reset these counter in your preamble.
 %
-% If processing of these documents fails at your TeX installation,
-% these may be commented out (independently) to make things work.
-% These are both supplied with the current version of the teTeX
-% distribution.
-%
-% The "fancyhdr" package makes nicer page footers reasonable to
-% implement, and is used to put the chapter and section information in 
-% the footers.
-%
-\RequirePackage{fancyhdr}
+\setcounter{secnumdepth}{2}
 
 
-% Required package:
+% The "fancyhdr" package makes nicer page footers reasonable to implement, and
+% is used to put the chapter and section information in the footers.
 %
-% This gives us all the Python-specific markup that we really want.
-% This should come last.  Do not change this.
+\RequirePackage{fancyhdr}
+
+% This gives us all the Python-specific markup that we really want.  This should
+% come last.  Do not change this.
 %
 \RequirePackage{sphinx}
 
-% This comes after python.sty because it otherwise defines its own
-% "seealso" command.
+% This comes after python.sty because it otherwise defines its own "seealso"
+% command.
+%
 \RequirePackage{makeidx}
 
-
-% Support for module synopsis sections:
-\newcommand{\py at ModSynopsisFilename}{\jobname.syn}
-
-
 % Need to do one of these....
 \newcommand{\py at doHorizontalRule}{\rule{\textwidth}{1pt}}
 
 
-% Change the title page to look a bit better, and fit in with the
-% fncychap ``Bjarne'' style a bit better.
+% Change the title page to look a bit better, and fit in with the fncychap
+% ``Bjarne'' style a bit better.
 %
 \renewcommand{\maketitle}{
   \py at doHorizontalRule
@@ -90,16 +80,16 @@
   \endgroup
   \py at doHorizontalRule
   \vspace{12pt}
-  \py at doing@page at targetstrue
 }  
 
-% Fix the theindex environment to add an entry to the Table of
-% Contents; this is much nicer than just having to jump to the end of
-% the book and flip around, especially with multiple indexes.
+% Fix the theindex environment to add an entry to the Table of Contents; this is
+% much nicer than just having to jump to the end of the book and flip around,
+% especially with multiple indexes.
 %
 \let\py at OldTheindex=\theindex
 \renewcommand{\theindex}{
   \clearpage
+  \phantomsection
   \py at OldTheindex
   \addcontentsline{toc}{section}{\indexname}
 }
@@ -108,6 +98,5 @@
   \pagestyle{plain}}{
   \pagestyle{normal}}		% start this way; change for
 \pagenumbering{arabic}		% ToC & chapters
-\setcounter{secnumdepth}{2}
 
 \thispagestyle{empty}

Modified: doctools/trunk/sphinx/texinputs/manual.cls
==============================================================================
--- doctools/trunk/sphinx/texinputs/manual.cls	(original)
+++ doctools/trunk/sphinx/texinputs/manual.cls	Sat May  3 20:14:13 2008
@@ -3,7 +3,7 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesClass{manual}[1998/03/03 Document class (Python manual)]
+\ProvidesClass{manual}[2008/05/01 Document class (Sphinx manual)]
 
 \RequirePackage{fancybox}
 
@@ -12,54 +12,38 @@
 \ProcessOptions\relax
 \LoadClass[twoside,openright]{report}
 
-\setcounter{secnumdepth}{2}
 
-% Optional packages:
+% Set some sane defaults for section numbering depth and TOC depth.  You can
+% reset these counter in your preamble.
 %
-% If processing of these documents fails at your TeX installation,
-% these may be commented out (independently) to make things work.
-% These are both supplied with the current version of the teTeX
-% distribution.
-%
-% The "fancyhdr" package makes nicer page footers reasonable to
-% implement, and is used to put the chapter and section information in 
-% the footers.
+\setcounter{secnumdepth}{2}
+\setcounter{tocdepth}{1}
+
+
+% The "fancyhdr" package makes nicer page footers reasonable to implement, and
+% is used to put the chapter and section information in the footers.
 %
 \RequirePackage{fancyhdr}
 
-% Required packages:
-%
-% The "fncychap" package is used to get the nice chapter headers.  The
-% .sty file is distributed with Sphinx, so you should not need to disable
-% it.  You'd also end up with a mixed page style; uglier than stock LaTeX!
+% The "fncychap" package is used to get the nice chapter headers.
 %
 \RequirePackage[Bjarne]{fncychap}
 % Do horizontal rules it this way to match:
 \newcommand{\py at doHorizontalRule}{\mghrulefill{\RW}}
 
-
-% This gives us all the Sphinx-specific markup that we really want.
-% This should come last.  Do not change this.
+% This gives us all the Sphinx-specific markup that we really want.  This should
+% come last.  Do not change this.
 %
 \RequirePackage{sphinx}
 
-% This comes after sphinx.sty because it otherwise defines its own
-% "seealso" command.
+% This comes after sphinx.sty because it otherwise defines its own "seealso"
+% command.
+%
 \RequirePackage{makeidx}
 
 
-% Support for module synopsis sections:
-\newcommand{\py at ModSynopsisFilename}{\jobname\thechapter.syn}
-\let\py at OldChapter=\chapter
-\renewcommand{\chapter}{
-  \py at ProcessModSynopsis
-  \py at closeModSynopsisFile
-  \py at OldChapter
-}
-
-
-% Change the title page to look a bit better, and fit in with the
-% fncychap ``Bjarne'' style a bit better.
+% Change the title page to look a bit better, and fit in with the fncychap
+% ``Bjarne'' style a bit better.
 %
 \renewcommand{\maketitle}{%
   \begin{titlepage}%
@@ -99,8 +83,8 @@
 }
 
 
-% Catch the end of the {abstract} environment, but here make sure the
-% abstract is followed by a blank page if the 'openright' option is used.
+% Catch the end of the {abstract} environment, but here make sure the abstract
+% is followed by a blank page if the 'openright' option is used.
 %
 \let\py at OldEndAbstract=\endabstract
 \renewcommand{\endabstract}{
@@ -113,10 +97,10 @@
   \py at OldEndAbstract
 }
 
-% This wraps the \tableofcontents macro with all the magic to get the
-% spacing right and have the right number of pages if the 'openright'
-% option has been used.  This eliminates a fair amount of crud in the
-% individual document files.
+
+% This wraps the \tableofcontents macro with all the magic to get the spacing
+% right and have the right number of pages if the 'openright' option has been
+% used.  This eliminates a fair amount of crud in the individual document files.
 %
 \let\py at OldTableofcontents=\tableofcontents
 \renewcommand{\tableofcontents}{%
@@ -136,23 +120,24 @@
   }%
   \pagenumbering{arabic}%
   \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
-  \py at doing@page at targetstrue%
 }
+
+
 % This is needed to get the width of the section # area wide enough in the
 % library reference.  Doing it here keeps it the same for all the manuals.
 %
 \renewcommand*\l at section{\@dottedtocline{1}{1.5em}{2.6em}}
 \renewcommand*\l at subsection{\@dottedtocline{2}{4.1em}{3.5em}}
-\setcounter{tocdepth}{1}
 
 
-% Fix the theindex environment to add an entry to the Table of
-% Contents; this is much nicer than just having to jump to the end of
-% the book and flip around, especially with multiple indexes.
+% Fix the theindex environment to add an entry to the Table of Contents; this is
+% much nicer than just having to jump to the end of the book and flip around,
+% especially with multiple indexes.
 %
 \let\py at OldTheindex=\theindex
 \renewcommand{\theindex}{
   \cleardoublepage
+  \phantomsection
   \py at OldTheindex
   \addcontentsline{toc}{chapter}{\indexname}
 }

Modified: doctools/trunk/sphinx/texinputs/sphinx.sty
==============================================================================
--- doctools/trunk/sphinx/texinputs/sphinx.sty	(original)
+++ doctools/trunk/sphinx/texinputs/sphinx.sty	Sat May  3 20:14:13 2008
@@ -6,20 +6,20 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
-\ProvidesPackage{sphinx}[2007/12/30 LaTeX package (Sphinx markup)]
+\ProvidesPackage{sphinx}[2008/05/01 LaTeX package (Sphinx markup)]
 
 \RequirePackage{textcomp}
-\RequirePackage{longtable}
 \RequirePackage{times}
 \RequirePackage{fancyvrb}
 \RequirePackage{titlesec}
+\RequirePackage{tabulary}
 
 \RequirePackage{color}
-% Define these colors to your liking in the preamble.
+% Redefine these colors to your liking in the preamble.
 \definecolor{TitleColor}{rgb}{0.126,0.263,0.361}
 \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
+% Redefine 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}
@@ -47,17 +47,7 @@
 %\renewcommand{\paperwidth}{8.5in}   % typical squarish manual
 %\renewcommand{\paperwidth}{7in}     % O'Reilly ``Programmming Python''
 
-% If we ever want to indent paragraphs, this needs to be changed.
-% This is used inside the macros defined here instead of coding
-% \noindent directly.
-\let\py at parindent=\noindent
-
-% for PDF output, use maximal compression & a lot of other stuff
-% (test for PDF recommended by Tanmoy Bhattacharya <tanmoy at qcd.lanl.gov>)
-%
-\newif\ifpy at doing@page at targets
-\py at doing@page at targetsfalse
-
+% for PDF output, use maximal compression
 \newif\ifpdf\pdffalse
 \ifx\pdfoutput\undefined\else\ifcase\pdfoutput
   \let\py at NormalColor\relax
@@ -65,85 +55,9 @@
 \else
   \pdftrue
   \input{pdfcolor}
-  \let\py at LinkColor=\NavyBlue
   \let\py at NormalColor=\Black
   \def\py at TitleColor{\color{TitleColor}}
   \pdfcompresslevel=9
-  \pdfpagewidth=\paperwidth    % page width of PDF output
-  \pdfpageheight=\paperheight  % page height of PDF output
-  %
-  % Pad the number with '0' to 3 digits wide so no page name is a prefix
-  % of any other.
-  %
-  \newcommand{\py at targetno}[1]{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
-  \newcommand{\py at pageno}{\py at targetno\thepage}
-  %
-  % This definition allows the entries in the page-view of the ToC to be
-  % active links.  Some work, some don't.
-  %
-  \let\py at OldContentsline=\contentsline
-  %
-  % Backward compatibility hack: pdfTeX 0.13 defined \pdfannotlink,
-  % but it changed to \pdfstartlink in 0.14.  This let's us use either
-  % version and still get useful behavior.
-  %
-  \@ifundefined{pdfstartlink}{
-    \let\pdfstartlink=\pdfannotlink
-  }{}
-  %
-  % The \py at parindent here is a hack -- we're forcing pdfTeX into
-  % horizontal mode since \pdfstartlink requires that.
-  \def\py at pdfstartlink{%
-    \ifvmode\py at parindent\fi%
-    \pdfstartlink%
-  }
-  %
-  % Macro that takes two args: the name to link to and the content of
-  % the link.  This takes care of the PDF magic, getting the colors
-  % the same for each link, and avoids having lots of garbage all over 
-  % this style file.
-  \newcommand{\py at linkToName}[2]{%
-    \py at pdfstartlink attr{/Border [0 0 0]} goto name{#1}%
-      \color{InnerLinkColor}#2\py at NormalColor%
-    \pdfendlink%
-  }
-  % Compute the padded page number separately since we end up with a pair of
-  % \relax tokens; this gets the right string computed and works.
-  \renewcommand{\contentsline}[3]{%
-    \def\my at pageno{\py at targetno{#3}}%
-    \py at OldContentsline{#1}{\py at linkToName{page\my at pageno}{#2}}{#3}%
-  }
-  \AtEndDocument{
-    \def\_{\string_}
-    \InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
-  }
-  \newcommand{\py at target}[1]{%
-    \ifpy at doing@page at targets%
-      {\pdfdest name{#1} xyz}%
-    \fi%
-  }
-  \let\py at OldLabel=\label
-  \renewcommand{\label}[1]{%
-    \py at OldLabel{#1}%
-    \py at target{label-#1}%
-  }
-  % This stuff adds a page# destination to every PDF page, where # is three
-  % digits wide, padded with leading zeros.  This doesn't really help with
-  % the frontmatter, but does fine with the body.
-  %
-  % This is *heavily* based on the hyperref package.
-  %
-  \def\@begindvi{%
-    \unvbox \@begindvibox
-    \@hyperfixhead
-  }
-  \def\@hyperfixhead{%
-   \let\H at old@thehead\@thehead
-       \global\def\@foo{\py at target{page\py at pageno}}%
-     \expandafter\ifx\expandafter\@empty\H at old@thehead
-       \def\H at old@thehead{\hfil}\fi
-    \def\@thehead{\@foo\relax\H at old@thehead}%
-  }
 \fi\fi
 
 % Increase printable page size (copied from fullpage.sty)
@@ -341,36 +255,30 @@
 % Add the defining entry for a module
 \newcommand{\py at modindex}[2]{%
   \renewcommand{\py at thismodule}{#1}
-  \index{#1@{\py at idxcode{#1}} (#2module)|textbf}%
+  \index{#1@{\py at idxcode{#1}} (#2module)}%
   \ifpy at UseModuleIndex%
     \@ifundefined{py at modplat@\py at thismodulekey}{
-      \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}}{\thepage}}%
-    }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1} %
-        \emph{(\py at platformof[\py at thismodulekey]{})}}}{\thepage}}%
+      \write\modindexfile{\protect\indexentry{#1@{\texttt{#1}}|hyperpage}{\thepage}}%
+    }{\write\modindexfile{\protect\indexentry{#1@{\texttt{#1 }%
+        \emph{(\platformof{#1})}}|hyperpage}{\thepage}}%
     }
   \fi%
 }
 
-
-% Module synopsis processing -----------------------------------------------
-%
+% "Current" keys
 \newcommand{\py at thisclass}{}
 \newcommand{\py at thismodule}{}
 \newcommand{\py at thismodulekey}{}
 \newcommand{\py at thismoduletype}{}
 
+% Module index types
 \newcommand{\py at standardIndexModule}[1]{\py at modindex{#1}{standard }}
 \newcommand{\py at builtinIndexModule}[1]{\py at modindex{#1}{built-in }}
 \newcommand{\py at extensionIndexModule}[1]{\py at modindex{#1}{extension }}
 \newcommand{\py at IndexModule}[1]{\py at modindex{#1}{}}
 
-\newif\ifpy at HaveModSynopsis       \py at HaveModSynopsisfalse
-\newif\ifpy at ModSynopsisFileIsOpen \py at ModSynopsisFileIsOpenfalse
-\newif\ifpy at HaveModPlatform       \py at HaveModPlatformfalse
-
 % \declaremodule[key]{type}{name}
 \newcommand{\declaremodule}[3][\py at modulebadkey]{
-  \py at openModSynopsisFile
   \renewcommand{\py at thismoduletype}{#2}
   \ifx\py at modulebadkey#1
     \renewcommand{\py at thismodulekey}{#3}
@@ -383,9 +291,16 @@
   }{%
     \csname py@#2IndexModule\endcsname{#3}%
   }
-  \label{module-\py at thismodulekey}
+  %\label{module-\py at thismodulekey}
 }
+
+% Record module platforms for the Module Index
 \newif\ifpy at ModPlatformFileIsOpen \py at ModPlatformFileIsOpenfalse
+\long\def\py at writeModPlatformFile#1{%
+  \protected at write\py at ModPlatformFile%
+    {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
+    {\string#1}%
+}
 \newcommand{\py at ModPlatformFilename}{\jobname.pla}
 \newcommand{\platform}[1]{
   \ifpy at ModPlatformFileIsOpen\else
@@ -393,15 +308,12 @@
     \openout\py at ModPlatformFile=\py at ModPlatformFilename
     \py at ModPlatformFileIsOpentrue
   \fi
+  \py at writeModPlatformFile{\py at defplatform{\py at thismodulekey}{#1}}
 }
+\newcommand{\py at defplatform}[2]{\expandafter\def\csname py at modplat@#1\endcsname{#2}}
+\newcommand{\platformof}[1]{\csname py at modplat@#1\endcsname}
+
 \InputIfFileExists{\jobname.pla}{}{}
-\newcommand{\py at platformof}[2][\py at modulebadkey]{%
-  \ifx\py at modulebadkey#1 \def\py at key{#2}%
-  \else \def\py at key{#1}%
-  \fi%
-  \csname py at modplat@\py at key\endcsname%
-}
-\newcommand{\ignorePlatformAnnotation}[1]{}
 
 % \moduleauthor{name}{email}
 \newcommand{\moduleauthor}[2]{}
@@ -409,83 +321,11 @@
 % \sectionauthor{name}{email}
 \newcommand{\sectionauthor}[2]{}
 
+% Ignore module synopsis.
+\newcommand{\modulesynopsis}[1]{}
 
-\newcommand{\py at defsynopsis}{Module has no synopsis.}
-\newcommand{\py at modulesynopsis}{\py at defsynopsis}
-\newcommand{\modulesynopsis}[1]{
-  \py at HaveModSynopsistrue
-  \renewcommand{\py at modulesynopsis}{#1}
-}
-
-% define the file
-\newwrite\py at ModSynopsisFile
-
-% hacked from \addtocontents from latex.ltx:
-\long\def\py at writeModSynopsisFile#1{%
-  \protected at write\py at ModSynopsisFile%
-      {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
-      {\string#1}%
-}
-\newcommand{\py at closeModSynopsisFile}{
-  \ifpy at ModSynopsisFileIsOpen
-    \closeout\py at ModSynopsisFile
-    \py at ModSynopsisFileIsOpenfalse
-  \fi
-}
-\newcommand{\py at openModSynopsisFile}{
-  \ifpy at ModSynopsisFileIsOpen\else
-    \openout\py at ModSynopsisFile=\py at ModSynopsisFilename
-    \py at ModSynopsisFileIsOpentrue
-  \fi
-}
-
-\newcommand{\py at ProcessModSynopsis}{
-  \ifpy at HaveModSynopsis
-    \py at writeModSynopsisFile{\modulesynopsis%
-      {\py at thismodulekey}{\py at thismodule}%
-      {\py at thismoduletype}{\py at modulesynopsis}}%
-    \py at HaveModSynopsisfalse
-  \fi
-  \renewcommand{\py at modulesynopsis}{\py at defsynopsis}
-}
-\AtEndDocument{\py at ProcessModSynopsis\py at closeModSynopsisFile}
-
-
-\long\def\py at writeModPlatformFile#1{%
-  \protected at write\py at ModPlatformFile%
-    {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
-    {\string#1}%
-}
-
-
-\newcommand{\localmoduletable}{
-  \IfFileExists{\py at ModSynopsisFilename}{
-    \begin{synopsistable}
-      \input{\py at ModSynopsisFilename}
-    \end{synopsistable}
-  }{}
-}
-
-\ifpdf
-  \newcommand{\py at ModSynopsisSummary}[4]{%
-    \py at linkToName{label-module-#1}{\bfcode{#2}} & #4\\
-  }
-\else
-  \newcommand{\py at ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
-\fi
-\newenvironment{synopsistable}{
-  % key, name, type, synopsis
-  \let\modulesynopsis=\py at ModSynopsisSummary
-  \begin{tabular}{ll}
-}{
-  \end{tabular}
-}
-%
-% --------------------------------------------------------------------------
-
-
-\newcommand{\py at reset}{
-  \py at ProcessModSynopsis
+% Reset "current" objects.
+\newcommand{\resetcurrentobjects}{
   \renewcommand{\py at thisclass}{}
   \renewcommand{\py at thismodule}{}
   \renewcommand{\py at thismodulekey}{}
@@ -495,7 +335,7 @@
 % Augment the sectioning commands used to get our own font family in place,
 % and reset some internal data items:
 \titleformat{\section}{\Large\py at HeaderFamily\py at TitleColor}%
-{\thesection}{-1em}{\py at reset}{\py at NormalColor}
+{\thesection}{0.5em}{}{\py at NormalColor}
 \titleformat{\subsection}{\large\py at HeaderFamily\py at TitleColor}%
 {\thesubsection}{0.5em}{}{\py at NormalColor}
 \titleformat{\subsubsection}{\py at HeaderFamily\py at TitleColor}%
@@ -881,88 +721,6 @@
 }
 
 
-% Tables.
-%
-\newenvironment{tableii}[4]{%
-  \begin{center}%
-    \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
-    \begin{tabular}{#1}\strong{#3}&\strong{#4} \\* \hline%
-}{%
-    \end{tabular}%
-  \end{center}%
-}
-
-\newenvironment{longtableii}[4]{%
-  \begin{center}%
-    \def\lineii##1##2{\csname#2\endcsname{##1}&##2\\}%
-    \begin{longtable}[c]{#1}\strong{#3}&\strong{#4} \\* \hline\endhead%
-}{%
-    \end{longtable}%
-  \end{center}%
-}
-
-\newenvironment{tableiii}[5]{%
-  \begin{center}%
-    \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
-    \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
-      \hline%
-}{%
-    \end{tabular}%
-  \end{center}%
-}
-
-\newenvironment{longtableiii}[5]{%
-  \begin{center}%
-    \def\lineiii##1##2##3{\csname#2\endcsname{##1}&##2&##3\\}%
-    \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5} \\%
-      \hline\endhead%
-}{%
-    \end{longtable}%
-  \end{center}%
-}
-
-\newenvironment{tableiv}[6]{%
-  \begin{center}%
-    \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
-    \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6} \\%
-      \hline%
-}{%
-    \end{tabular}%
-  \end{center}%
-}
-
-\newenvironment{longtableiv}[6]{%
-  \begin{center}%
-    \def\lineiv##1##2##3##4{\csname#2\endcsname{##1}&##2&##3&##4\\}%
-    \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}%
-      \\%
-      \hline\endhead%
-}{%
-    \end{longtable}%
-  \end{center}%
-}
-
-\newenvironment{tablev}[7]{%
-  \begin{center}%
-    \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
-    \begin{tabular}{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7} \\%
-      \hline%
-}{%
-    \end{tabular}%
-  \end{center}%
-}
-
-\newenvironment{longtablev}[7]{%
-  \begin{center}%
-    \def\linev##1##2##3##4##5{\csname#2\endcsname{##1}&##2&##3&##4&##5\\}%
-    \begin{longtable}[c]{#1}\strong{#3}&\strong{#4}&\strong{#5}&\strong{#6}&\strong{#7}%
-      \\%
-      \hline\endhead%
-}{%
-    \end{longtable}%
-  \end{center}%
-}
-
 % See-also environment
 \newenvironment{seealso}{
   \par

Added: doctools/trunk/sphinx/texinputs/tabulary.sty
==============================================================================
--- (empty file)
+++ doctools/trunk/sphinx/texinputs/tabulary.sty	Sat May  3 20:14:13 2008
@@ -0,0 +1,449 @@
+%%
+%% This is file `tabulary.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% tabulary.dtx  (with options: `package')
+%% DRAFT VERSION
+%%
+%% File `tabulary.dtx'.
+%% Copyright (C) 1995 1996 2003 David Carlisle
+%% This file may be distributed under the terms of the LPPL.
+%% See 00readme.txt for details.
+%%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{tabulary}
+          [2007/10/02 v0.9 tabulary package (DPC)]
+\RequirePackage{array}
+\catcode`\Z=14
+\DeclareOption{debugshow}{\catcode`\Z=9\relax}
+\ProcessOptions
+\def\arraybackslash{\let\\=\@arraycr}
+\def\@finalstrut#1{%
+  \unskip\ifhmode\nobreak\fi\vrule\@width\z@\@height\z@\@depth\dp#1}
+\newcount\TY at count
+\def\tabulary{%
+  \let\TY at final\tabular
+  \let\endTY at final\endtabular
+  \TY at tabular}
+\def\TY at tabular#1{%
+  \edef\TY@{\@currenvir}%
+  {\ifnum0=`}\fi
+  \@ovxx\TY at linewidth
+  \@ovyy\TY at tablewidth
+  \count@\z@
+  \@tempswatrue
+  \@whilesw\if at tempswa\fi{%
+  \advance\count@\@ne
+  \expandafter\ifx\csname TY at F\the\count@\endcsname\relax
+    \@tempswafalse
+  \else
+    \expandafter\let\csname TY at SF\the\count@\expandafter\endcsname
+                     \csname TY at F\the\count@\endcsname
+    \global\expandafter\let\csname TY at F\the\count@\endcsname\relax
+    \expandafter\let\csname TY at S\the\count@\expandafter\endcsname
+                     \csname TY@\the\count@\endcsname
+  \fi}%
+    \global\TY at count\@ne
+    \TY at width\xdef{0pt}%
+    \global\TY at tablewidth\z@
+    \global\TY at linewidth#1\relax
+Z\message{^^J^^JTable^^J%
+Z        Target Width: \the\TY at linewidth^^J%
+Z        \string\tabcolsep: \the\tabcolsep\space
+Z        \string\arrayrulewidth: \the\arrayrulewidth\space
+Z        \string\doublerulesep: \the\doublerulesep^^J%
+Z        \string\tymin: \the\tymin\space
+Z        \string\tymax: \the\tymax^^J}%
+    \let\@classz\TY at classz
+    \let\verb\TX at verb
+    \toks@{}\TY at get@body}
+\let\TY@@mkpream\@mkpream
+\def\TY at mkpream{%
+    \def\@addamp{%
+      \if at firstamp \@firstampfalse \else
+      \global\advance\TY at count\@ne
+      \edef\@preamble{\@preamble &}\fi
+      \TY at width\xdef{0pt}}%
+    \def\@acol{%
+      \TY at subwidth\col at sep
+      \@addtopreamble{\hskip\col at sep}}%
+    \let\@arrayrule\TY at arrayrule
+    \let\@classvi\TY at classvi
+    \def\@classv{\save at decl
+      \expandafter\NC at ecs\@nextchar\extracolsep{}\extracolsep\@@@
+      \sbox\z@{\d at llarbegin\@nextchar\d at llarend}%
+      \TY at subwidth{\wd\z@}%
+      \@addtopreamble{\d at llarbegin\the at toks\the\count@\relax\d at llarend}%
+      \prepnext at tok}%
+  \global\let\@mkpream\TY@@mkpream
+  \TY@@mkpream}
+\def\TY at arrayrule{%
+  \TY at subwidth\arrayrulewidth
+  \@addtopreamble \vline}
+\def\TY at classvi{\ifcase \@lastchclass
+  \@acol \or
+  \TY at subwidth\doublerulesep
+  \@addtopreamble{\hskip \doublerulesep}\or
+  \@acol \or
+  \@classvii
+  \fi}
+\def\TY at tab{%
+  \setbox\z@\hbox\bgroup
+  \let\[$\let\]$%
+  \let\equation$\let\endequation$%
+    \col at sep\tabcolsep
+    \let\d at llarbegin\begingroup\let\d at llarend\endgroup
+    \let\@mkpream\TY at mkpream
+      \def\multicolumn##1##2##3{\multispan##1\relax}%
+    \CT at start\TY at tabarray}
+\def\TY at tabarray{\@ifnextchar[{\TY at array}{\@array[t]}}
+\def\TY at array[#1]{\@array[t]}
+\def\TY at width#1{%
+  \expandafter#1\csname TY@\the\TY at count\endcsname}
+\def\TY at subwidth#1{%
+  \TY at width\dimen@
+  \advance\dimen at -#1\relax
+  \TY at width\xdef{\the\dimen@}%
+  \global\advance\TY at linewidth-#1\relax}
+\def\endtabulary{%
+  \gdef\@halignto{}%
+  \expandafter\TY at tab\the\toks@
+  \crcr\omit
+  {\xdef\TY at save@row{}%
+     \loop
+    \advance\TY at count\m at ne
+    \ifnum\TY at count>\z@
+    \xdef\TY at save@row{\TY at save@row&\omit}%
+    \repeat}\TY at save@row
+  \endarray\global\setbox1=\lastbox\setbox0=\vbox{\unvbox1
+    \unskip\global\setbox1=\lastbox}\egroup
+  \dimen@\TY at linewidth
+  \divide\dimen@\TY at count
+  \ifdim\dimen@<\tymin
+    \TY at warn{tymin too large (\the\tymin), resetting to \the\dimen@}%
+    \tymin\dimen@
+  \fi
+  \setbox\tw@=\hbox{\unhbox\@ne
+    \loop
+\@tempdima=\lastskip
+\ifdim\@tempdima>\z@
+Z   \message{ecs=\the\@tempdima^^J}%
+   \global\advance\TY at linewidth-\@tempdima
+\fi
+    \unskip
+    \setbox\tw@=\lastbox
+    \ifhbox\tw@
+Z     \message{Col \the\TY at count: Initial=\the\wd\tw@\space}%
+      \ifdim\wd\tw@>\tymax
+        \wd\tw@\tymax
+Z       \message{> max\space}%
+Z     \else
+Z       \message{ \@spaces\space}%
+      \fi
+  \TY at width\dimen@
+Z \message{\the\dimen@\space}%
+  \advance\dimen@\wd\tw@
+Z \message{Final=\the\dimen@\space}%
+   \TY at width\xdef{\the\dimen@}%
+      \ifdim\dimen@<\tymin
+Z        \message{< tymin}%
+         \global\advance\TY at linewidth-\dimen@
+         \expandafter\xdef\csname TY at F\the\TY at count\endcsname
+                                                        {\the\dimen@}%
+       \else
+      \expandafter\ifx\csname TY at F\the\TY at count\endcsname\z@
+Z        \message{***}%
+         \global\advance\TY at linewidth-\dimen@
+         \expandafter\xdef\csname TY at F\the\TY at count\endcsname
+                                                        {\the\dimen@}%
+        \else
+Z        \message{> tymin}%
+         \global\advance\TY at tablewidth\dimen@
+         \global\expandafter\let\csname TY at F\the\TY at count\endcsname
+                                                               \maxdimen
+       \fi\fi
+       \advance\TY at count\m at ne
+    \repeat}%
+    \TY at checkmin
+    \TY at checkmin
+    \TY at checkmin
+    \TY at checkmin
+    \TY at count\z@
+    \let\TY at box\TY at box@v
+  {\expandafter\TY at final\the\toks@\endTY at final}%
+  \count@\z@
+  \@tempswatrue
+  \@whilesw\if at tempswa\fi{%
+  \advance\count@\@ne
+  \expandafter\ifx\csname TY at SF\the\count@\endcsname\relax
+    \@tempswafalse
+  \else
+    \global\expandafter\let\csname TY at F\the\count@\expandafter\endcsname
+                   \csname TY at SF\the\count@\endcsname
+    \global\expandafter\let\csname TY@\the\count@\expandafter\endcsname
+                   \csname TY at S\the\count@\endcsname
+  \fi}%
+  \TY at linewidth\@ovxx
+  \TY at tablewidth\@ovyy
+    \ifnum0=`{\fi}}
+\def\TY at checkmin{%
+  \let\TY at checkmin\relax
+\ifdim\TY at tablewidth>\z@
+  \Gscale at div\TY at ratio\TY at linewidth\TY at tablewidth
+ \ifdim\TY at tablewidth <\linewidth
+   \def\TY at ratio{1}%
+ \fi
+\else
+  \TY at warn{No suitable columns!}%
+  \def\TY at ratio{1}%
+\fi
+\count@\z@
+Z \message{^^JLine Width: \the\TY at linewidth,
+Z             Natural Width: \the\TY at tablewidth,
+Z             Ratio: \TY at ratio^^J}%
+\@tempdima\z@
+\loop
+\ifnum\count@<\TY at count
+\advance\count@\@ne
+  \ifdim\csname TY at F\the\count@\endcsname>\tymin
+    \dimen@\csname TY@\the\count@\endcsname
+    \dimen@\TY at ratio\dimen@
+    \ifdim\dimen@<\tymin
+Z     \message{Column \the\count@\space ->}%
+      \global\expandafter\let\csname TY at F\the\count@\endcsname\tymin
+      \global\advance\TY at linewidth-\tymin
+      \global\advance\TY at tablewidth-\csname TY@\the\count@\endcsname
+      \let\TY at checkmin\TY@@checkmin
+    \else
+      \expandafter\xdef\csname TY at F\the\count@\endcsname{\the\dimen@}%
+      \advance\@tempdima\csname TY at F\the\count@\endcsname
+    \fi
+  \fi
+Z \dimen@\csname TY at F\the\count@\endcsname\message{\the\dimen@, }%
+\repeat
+Z \message{^^JTotal:\the\@tempdima^^J}%
+}
+\let\TY@@checkmin\TY at checkmin
+\newdimen\TY at linewidth
+\def\tyformat{\everypar{{\nobreak\hskip\z at skip}}}
+\newdimen\tymin
+\tymin=10pt
+\newdimen\tymax
+\tymax=2\textwidth
+\def\@testpach{\@chclass
+ \ifnum \@lastchclass=6 \@ne \@chnum \@ne \else
+  \ifnum \@lastchclass=7 5 \else
+   \ifnum \@lastchclass=8 \tw@ \else
+    \ifnum \@lastchclass=9 \thr@@
+   \else \z@
+   \ifnum \@lastchclass = 10 \else
+   \edef\@nextchar{\expandafter\string\@nextchar}%
+   \@chnum
+   \if \@nextchar c\z@ \else
+    \if \@nextchar l\@ne \else
+     \if \@nextchar r\tw@ \else
+   \if \@nextchar C7 \else
+    \if \@nextchar L8 \else
+     \if \@nextchar R9 \else
+     \if \@nextchar J10 \else
+   \z@ \@chclass
+   \if\@nextchar |\@ne \else
+    \if \@nextchar !6 \else
+     \if \@nextchar @7 \else
+      \if \@nextchar <8 \else
+       \if \@nextchar >9 \else
+  10
+  \@chnum
+  \if \@nextchar m\thr@@\else
+   \if \@nextchar p4 \else
+    \if \@nextchar b5 \else
+   \z@ \@chclass \z@ \@preamerr \z@ \fi \fi \fi \fi\fi \fi \fi\fi \fi
+     \fi  \fi  \fi  \fi  \fi  \fi \fi \fi \fi \fi \fi}
+\def\TY at classz{%
+  \@classx
+  \@tempcnta\count@
+  \ifx\TY at box\TY at box@v
+    \global\advance\TY at count\@ne
+  \fi
+  \let\centering c%
+  \let\raggedright\noindent
+  \let\raggedleft\indent
+  \let\arraybackslash\relax
+  \prepnext at tok
+  \ifnum\@chnum<4
+    \global\expandafter\let\csname TY at F\the\TY at count\endcsname\z@
+  \fi
+  \ifnum\@chnum=6
+    \global\expandafter\let\csname TY at F\the\TY at count\endcsname\z@
+  \fi
+  \@addtopreamble{%
+    \ifcase\@chnum
+      \hfil \d at llarbegin\insert at column\d at llarend \hfil \or
+      \kern\z@
+       \d at llarbegin \insert at column \d at llarend \hfil \or
+      \hfil\kern\z@ \d at llarbegin \insert at column \d at llarend \or
+      $\vcenter\@startpbox{\@nextchar}\insert at column \@endpbox $\or
+      \vtop \@startpbox{\@nextchar}\insert at column \@endpbox \or
+      \vbox \@startpbox{\@nextchar}\insert at column \@endpbox \or
+      \d at llarbegin \insert at column \d at llarend \or% dubious "s" case
+      \TY at box\centering\or
+      \TY at box\raggedright\or
+      \TY at box\raggedleft\or
+      \TY at box\relax
+    \fi}\prepnext at tok}
+\def\TY at box#1{%
+  \ifx\centering#1%
+      \hfil \d at llarbegin\insert at column\d at llarend \hfil \else
+  \ifx\raggedright#1%
+        \kern\z@%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      \d at llarbegin \insert at column \d at llarend \hfil \else
+  \ifx\raggedleft#1%
+      \hfil\kern\z@ \d at llarbegin \insert at column \d at llarend \else
+  \ifx\relax#1%
+       \d at llarbegin \insert at column \d at llarend
+  \fi  \fi  \fi  \fi}
+\def\TY at box@v#1{%
+      \vtop \@startpbox{\csname TY at F\the\TY at count\endcsname}%
+              #1\arraybackslash\tyformat
+                              \insert at column\@endpbox}
+\newdimen\TY at tablewidth
+\def\Gscale at div#1#2#3{%
+  \setlength\dimen@{#3}%
+  \ifdim\dimen@=\z@
+    \PackageError{graphics}{Division by 0}\@eha
+    \dimen@#2%
+  \fi
+  \edef\@tempd{\the\dimen@}%
+  \setlength\dimen@{#2}%
+  \count at 65536\relax
+  \ifdim\dimen@<\z@
+    \dimen at -\dimen@
+    \count at -\count@
+  \fi
+  \loop
+    \ifdim\dimen@<8192\p@
+      \dimen@\tw@\dimen@
+      \divide\count@\tw@
+  \repeat
+  \dimen at ii=\@tempd\relax
+  \divide\dimen at ii\count@
+  \divide\dimen@\dimen at ii
+  \edef#1{\strip at pt\dimen@}}
+\long\def\TY at get@body#1\end
+  {\toks@\expandafter{\the\toks@#1}\TY at find@end}
+\def\TY at find@end#1{%
+  \def\@tempa{#1}%
+  \ifx\@tempa\TY@\def\@tempa{\end{#1}}\expandafter\@tempa
+  \else\toks@\expandafter
+    {\the\toks@\end{#1}}\expandafter\TY at get@body\fi}
+\def\TY at warn{%
+  \PackageWarning{tabulary}}
+\catcode`\Z=11
+\AtBeginDocument{
+\@ifpackageloaded{colortbl}{%
+\expandafter\def\expandafter\@mkpream\expandafter#\expandafter1%
+  \expandafter{%
+    \expandafter\let\expandafter\CT at setup\expandafter\relax
+    \expandafter\let\expandafter\CT at color\expandafter\relax
+    \expandafter\let\expandafter\CT at do@color\expandafter\relax
+    \expandafter\let\expandafter\color\expandafter\relax
+    \expandafter\let\expandafter\CT at column@color\expandafter\relax
+    \expandafter\let\expandafter\CT at row@color\expandafter\relax
+    \@mkpream{#1}}
+\let\TY@@mkpream\@mkpream
+\def\TY at classz{%
+  \@classx
+  \@tempcnta\count@
+  \ifx\TY at box\TY at box@v
+    \global\advance\TY at count\@ne
+  \fi
+  \let\centering c%
+  \let\raggedright\noindent
+  \let\raggedleft\indent
+  \let\arraybackslash\relax
+  \prepnext at tok
+\expandafter\CT at extract\the\toks\@tempcnta\columncolor!\@nil
+  \ifnum\@chnum<4
+    \global\expandafter\let\csname TY at F\the\TY at count\endcsname\z@
+  \fi
+  \ifnum\@chnum=6
+    \global\expandafter\let\csname TY at F\the\TY at count\endcsname\z@
+  \fi
+  \@addtopreamble{%
+    \setbox\z@\hbox\bgroup\bgroup
+    \ifcase\@chnum
+      \hskip\stretch{.5}\kern\z@
+      \d at llarbegin\insert at column\d at llarend\hskip\stretch{.5}\or
+      \kern\z@%<<<<<<<<<<<<<<<<<<<<<<<<<<<
+       \d at llarbegin \insert at column \d at llarend \hfill \or
+      \hfill\kern\z@ \d at llarbegin \insert at column \d at llarend \or
+      $\vcenter\@startpbox{\@nextchar}\insert at column \@endpbox $\or
+      \vtop \@startpbox{\@nextchar}\insert at column \@endpbox \or
+      \vbox \@startpbox{\@nextchar}\insert at column \@endpbox \or
+      \d at llarbegin \insert at column \d at llarend \or% dubious s case
+      \TY at box\centering\or
+      \TY at box\raggedright\or
+      \TY at box\raggedleft\or
+      \TY at box\relax
+    \fi
+ \egroup\egroup
+\begingroup
+  \CT at setup
+  \CT at column@color
+  \CT at row@color
+  \CT at do@color
+\endgroup
+        \@tempdima\ht\z@
+        \advance\@tempdima\minrowclearance
+        \vrule\@height\@tempdima\@width\z@
+\unhbox\z@
+}\prepnext at tok}%
+    \def\TY at arrayrule{%
+      \TY at subwidth\arrayrulewidth
+      \@addtopreamble{{\CT at arc@\vline}}}%
+    \def\TY at classvi{\ifcase \@lastchclass
+      \@acol \or
+      \TY at subwidth\doublerulesep
+      \ifx\CT at drsc@\relax
+        \@addtopreamble{\hskip\doublerulesep}%
+      \else
+        \@addtopreamble{{\CT at drsc@\vrule\@width\doublerulesep}}%
+      \fi\or
+      \@acol \or
+      \@classvii
+      \fi}%
+}{%
+\let\CT at start\relax
+}
+}
+{\uccode`\*=`\ %
+\uppercase{\gdef\TX at verb{%
+  \leavevmode\null\TX at vwarn
+  {\ifnum0=`}\fi\ttfamily\let\\\ignorespaces
+  \@ifstar{\let~*\TX at vb}{\TX at vb}}}}
+\def\TX at vb#1{\def\@tempa##1#1{\toks@{##1}\edef\@tempa{\the\toks@}%
+    \expandafter\TX at v\meaning\@tempa\\ \\\ifnum0=`{\fi}}\@tempa!}
+\def\TX at v#1!{\afterassignment\TX at vfirst\let\@tempa= }
+\begingroup
+\catcode`\*=\catcode`\#
+\catcode`\#=12
+\gdef\TX at vfirst{%
+  \if\@tempa#%
+    \def\@tempb{\TX at v@#}%
+  \else
+    \let\@tempb\TX at v@
+    \if\@tempa\space~\else\@tempa\fi
+  \fi
+  \@tempb}
+\gdef\TX at v@*1 *2{%
+  \TX at v@hash*1##\relax\if*2\\\else~\expandafter\TX at v@\fi*2}
+\gdef\TX at v@hash*1##*2{*1\ifx*2\relax\else#\expandafter\TX at v@hash\fi*2}
+\endgroup
+\def\TX at vwarn{%
+  \@warning{\noexpand\verb may be unreliable inside tabularx/y}%
+  \global\let\TX at vwarn\@empty}
+\endinput
+%%
+%% End of file `tabulary.sty'.


More information about the Python-checkins mailing list