Hi,

Now I put modified files under sphinx's directory:

- builders/xelatex.py
- writers/xelatex.py

And add a line in builders/__init__.py under BUILTIN_BUILDERS :

    'xelatex':   ('xelatex', 'XeLaTeXBuilder'),

It still complains unknown node "math".

I cannot find how to attach file in web mode, so I paste the diffs
between xelatex.py and latex.py here.

Best wishes,
Wei-Wei



Diff between builders/xelatex.py and builders/latex.py
======================================================

--- latex.py    2009-08-05 05:06:14.000000000 +0800
+++ xelatex.py  2009-09-17 16:11:39.000000000 +0800
@@ -1,9 +1,9 @@
 # -*- coding: utf-8 -*-
 """
-    sphinx.builders.latex
-    ~~~~~~~~~~~~~~~~~~~~~
+    sphinx.builders.xelatex
+    ~~~~~~~~~~~~~~~~~~~~~~~

-    LaTeX builder.
+    XeLaTeX builder.

     :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
     :license: BSD, see LICENSE for details.
@@ -22,15 +22,15 @@
 from sphinx.builders import Builder
 from sphinx.environment import NoUri
 from sphinx.util.console import bold, darkgreen
-from sphinx.writers.latex import LaTeXWriter
+from sphinx.writers.xelatex import XeLaTeXWriter


-class LaTeXBuilder(Builder):
+class XeLaTeXBuilder(Builder):
     """
-    Builds LaTeX output to create PDF.
+    Builds XeLaTeX output to create PDF.
     """
-    name = 'latex'
-    format = 'latex'
+    name = 'xelatex'
+    format = 'xelatex'
     supported_image_types = ['application/pdf', 'image/png',
                              'image/gif', 'image/jpeg']

@@ -45,7 +45,7 @@
     def get_target_uri(self, docname, typ=None):
         if typ == 'token':
             # token references are always inside production lists and
must be
-            # replaced by \token{} in LaTeX
+            # replaced by \token{} in XeLaTeX
             return '@token'
         if docname not in self.docnames:
             raise NoUri
@@ -76,7 +76,7 @@
             self.titles.append((docname, entry[2]))

     def write(self, *ignored):
-        docwriter = LaTeXWriter(self)
+        docwriter = XeLaTeXWriter(self)
         docsettings = OptionParser(
             defaults=self.env.settings,
             components=(docwriter,)).get_default_values()



Diff between writers/xelatex.py and writers/latex.py
====================================================

--- latex.py    2009-09-14 21:03:00.000000000 +0800
+++ xelatex.py  2009-09-17 16:09:22.000000000 +0800
@@ -1,9 +1,9 @@
 # -*- coding: utf-8 -*-
 """
-    sphinx.writers.latex
-    ~~~~~~~~~~~~~~~~~~~~
+    sphinx.writers.xelatex
+    ~~~~~~~~~~~~~~~~~~~~~~

-    Custom docutils writer for LaTeX.
+    Custom docutils writer for XeLaTeX.

     Much of this code is adapted from Dave Kuhlman's "docpy" writer
from his
     docutils sandbox.
@@ -17,7 +17,6 @@
 from os import path

 from docutils import nodes, writers
-from docutils.writers.latex2e import Babel

 from sphinx import addnodes
 from sphinx import highlighting
@@ -29,10 +28,19 @@

 HEADER = r'''%% Generated by Sphinx.
 \documentclass[%(papersize)s,%(pointsize)s%(classoptions)s]{%
(docclass)s}
-%(inputenc)s
-%(fontenc)s
-%(babel)s
-%(fontpkg)s
+\usepackage{fontspec}
+\usepackage{xunicode}
+\usepackage{xltxtra}
+\XeTeXlinebreaklocale "zh"
+\XeTeXlinebreakskip = 0pt plus 1pt
+\setmainfont{Times New Roman}
+\setsansfont{Arial}
+\setmonofont{Courier New}
+\RequirePackage[CJKnormalspaces,slantfont,boldfont]{xeCJK}
+\setCJKmainfont{Adobe Song Std}
+\setCJKsansfont{Adobe Heiti Std}
+\setCJKmonofont{Adobe Kaiti Std}
+\punctstyle{kaiming}
 %(fncychap)s
 %(longtable)s
 \usepackage{sphinx}
@@ -68,14 +76,14 @@
     """Footnotes that are collected are assigned this class."""

 class UnsupportedError(SphinxError):
-    category = 'Markup is unsupported in LaTeX'
+    category = 'Markup is unsupported in XeLaTeX'


-class LaTeXWriter(writers.Writer):
+class XeLaTeXWriter(writers.Writer):

     supported = ('sphinxlatex',)

-    settings_spec = ('LaTeX writer options', '', (
+    settings_spec = ('XeLaTeX writer options', '', (
         ('Document name', ['--docname'], {'default': ''}),
         ('Document class', ['--docclass'], {'default': 'manual'}),
         ('Author', ['--author'], {'default': ''}),
@@ -89,24 +97,13 @@
         self.builder = builder

     def translate(self):
-        visitor = LaTeXTranslator(self.document, self.builder)
+        visitor = XeLaTeXTranslator(self.document, self.builder)
         self.document.walkabout(visitor)
         self.output = visitor.astext()


 # Helper classes

-class ExtBabel(Babel):
-    def get_shorthandoff(self):
-        shortlang = self.language.split('_')[0]
-        if shortlang in ('de', 'sl', 'pt', 'es', 'nl', 'pl', 'it'):
-            return '\\shorthandoff{"}'
-        return ''
-
-    _ISO639_TO_BABEL = Babel._ISO639_TO_BABEL.copy()
-    _ISO639_TO_BABEL['sl'] = 'slovene'
-
-
 class Table(object):
     def __init__(self):
         self.col = 0
@@ -121,13 +118,13 @@

 class Desc(object):
     def __init__(self, node):
-        self.env = LaTeXTranslator.desc_map.get(node['desctype'],
'describe')
+        self.env = XeLaTeXTranslator.desc_map.get(node['desctype'],
'describe')
         self.type = self.cls = self.name = self.params = \
                     self.annotation = self.returns = ''
         self.count = 0


-class LaTeXTranslator(nodes.NodeVisitor):
+class XeLaTeXTranslator(nodes.NodeVisitor):
     sectionnames = ["part", "chapter", "section", "subsection",
                     "subsubsection", "paragraph", "subparagraph"]

@@ -138,10 +135,6 @@
         'papersize':       'letterpaper',
         'pointsize':       '10pt',
         'classoptions':    '',
-        'inputenc':        '\\usepackage[utf8]{inputenc}',
-        'fontenc':         '\\usepackage[T1]{fontenc}',
-        'babel':           '\\usepackage{babel}',
-        'fontpkg':         '\\usepackage{times}',
         'fncychap':        '\\usepackage[Bjarne]{fncychap}',
         'longtable':       '\\usepackage{longtable}',
         'preamble':        '',
@@ -191,17 +184,9 @@
             self.elements['logo'] = '\\includegraphics{%s}\\par' % \
                                     path.basename
(builder.config.latex_logo)
         if builder.config.language:
-            babel = ExtBabel(builder.config.language)
-            lang = babel.get_language()
-            if lang:
-                self.elements['classoptions'] += ',' +
babel.get_language()
-            else:
-                self.builder.warn('no Babel option known for language
%r' %
-                                  builder.config.language)
-            self.elements['shorthandoff'] = babel.get_shorthandoff()
-            self.elements['fncychap'] = '\\usepackage[Sonny]
{fncychap}'
+            pass
         else:
-            self.elements['classoptions'] += ',english'
+            pass
         if not builder.config.latex_use_modindex:
             self.elements['makemodindex'] = ''
             self.elements['printmodindex'] = ''
@@ -729,7 +714,7 @@

     def visit_list_item(self, node):
         # Append "{}" in case the next character is "[", which would
break
-        # LaTeX's list environment (no numbering and the "[" is not
printed).
+        # XeLaTeX's list environment (no numbering and the "[" is not
printed).
         self.body.append(r'\item {} ')
     def depart_list_item(self, node):
         self.body.append('\n')
@@ -825,7 +810,7 @@
         res = width_str
         amount, unit = match.groups()[:2]
         if not unit or unit == "px":
-            # pixels: let LaTeX alone
+            # pixels: let XeLaTeX alone
             return None
         elif unit == "%":
             res = "%.3f\\linewidth" % (float(amount) / 100.0)
@@ -969,7 +954,7 @@

     def visit_target(self, node):
         def add_target(id):
-            # indexing uses standard LaTeX index markup, so the
targets
+            # indexing uses standard XeLaTeX index markup, so the
targets
             # will be generated differently
             if not id.startswith('index-'):
                 self.body.append(r'\hypertarget{%s}{}' % id)
@@ -1324,7 +1309,7 @@
         text = unicode(text).translate(tex_escape_map)
         if self.literal_whitespace:
             # Insert a blank before the newline, to avoid
-            # ! LaTeX Error: There's no line here to end.
+            # ! XeLaTeX Error: There's no line here to end.
             text = text.replace(u'\n', u'~\\\\\n').replace(u' ',
u'~')
         if self.no_contractions:
             text = text.replace('--', u'-{-}')







On Sep 17, 2:57 pm, Wei-Wei Guo <[email protected]> wrote:
> Dear all,
>
> I modified the latex builder to axelatexbuilder, because the Babel
> and related parts are conflict with my own Chinese configuration 
> andxelatexcan avoid the problem. Myxelatexbuilder is used as an
> extension. It works fine mostly, but when I want to use the pngmath
> extension, it complains don't know the node "math". Does anyone has
> any hints on why?
>
> BTW, is that possible that the latex builder of Sphinx moves toxelatex? It 
> doesn't require much work to do. WithXeLaTeX, we don't
> need to worry about problem of fonts and encoding of the generated
> latex files anymore and the way of using LaTeX do not need any
> change.
>
> Best wishes,
> Wei-Wei
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to