#432: Fix UnicodeErrors while building LaTeX in translated locale; do not swallow UnicodeError as a warning.

This commit is contained in:
Georg Brandl 2010-06-05 18:37:16 +02:00
parent 2a8b6f44c7
commit 6ab7cd4ab7
3 changed files with 14 additions and 18 deletions

View File

@ -9,6 +9,8 @@ Release 0.6.7 (in development)
* #428: Add some missing CSS styles for standard docutils classes. * #428: Add some missing CSS styles for standard docutils classes.
* #432: Fix UnicodeErrors while building LaTeX in translated locale.
Release 0.6.6 (May 25, 2010) Release 0.6.6 (May 25, 2010)
============================ ============================

View File

@ -102,13 +102,7 @@ class LaTeXBuilder(Builder):
doctree.settings.title = title doctree.settings.title = title
doctree.settings.docname = docname doctree.settings.docname = docname
doctree.settings.docclass = docclass doctree.settings.docclass = docclass
try: docwriter.write(doctree, destination)
docwriter.write(doctree, destination)
except UnicodeError:
self.warn("a Unicode error occurred when writing the output. "
"Please make sure all config values that contain "
"non-ASCII content are Unicode strings.")
return
self.info("done") self.info("done")
def assemble_doctree(self, indexfile, toctree_only, appendices): def assemble_doctree(self, indexfile, toctree_only, appendices):

View File

@ -262,7 +262,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.first_document = 0 self.first_document = 0
elif self.first_document == 0: elif self.first_document == 0:
# ... and all others are the appendices # ... and all others are the appendices
self.body.append('\n\\appendix\n') self.body.append(u'\n\\appendix\n')
self.first_document = -1 self.first_document = -1
if node.has_key('docname'): if node.has_key('docname'):
self.body.append('\\hypertarget{--doc-%s}{}' % self.body.append('\\hypertarget{--doc-%s}{}' %
@ -275,14 +275,14 @@ class LaTeXTranslator(nodes.NodeVisitor):
for bi in self.bibitems: for bi in self.bibitems:
if len(widest_label) < len(bi[0]): if len(widest_label) < len(bi[0]):
widest_label = bi[0] widest_label = bi[0]
self.body.append('\n\\begin{thebibliography}{%s}\n' % widest_label) self.body.append(u'\n\\begin{thebibliography}{%s}\n' % widest_label)
for bi in self.bibitems: for bi in self.bibitems:
# cite_key: underscores must not be escaped # cite_key: underscores must not be escaped
cite_key = bi[0].replace(r"\_", "_") cite_key = bi[0].replace(r"\_", "_")
self.body.append('\\bibitem[%s]{%s}{\hypertarget{%s}{} %s}\n' % self.body.append(u'\\bibitem[%s]{%s}{\hypertarget{%s}{} %s}\n' %
(bi[0], cite_key, (bi[0], cite_key,
self.idescape(cite_key.lower()), bi[1])) self.idescape(cite_key.lower()), bi[1]))
self.body.append('\\end{thebibliography}\n') self.body.append(u'\\end{thebibliography}\n')
self.bibitems = [] self.bibitems = []
def visit_start_of_file(self, node): def visit_start_of_file(self, node):
@ -578,7 +578,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
pass pass
def visit_seealso(self, node): def visit_seealso(self, node):
self.body.append("\n\n\\strong{%s:}\n\n" % admonitionlabels['seealso']) self.body.append(u'\n\n\\strong{%s:}\n\n' % admonitionlabels['seealso'])
def depart_seealso(self, node): def depart_seealso(self, node):
self.body.append("\n\n") self.body.append("\n\n")
@ -624,8 +624,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.table.longtable = True self.table.longtable = True
self.body = self._body self.body = self._body
if not self.table.longtable and self.table.caption is not None: if not self.table.longtable and self.table.caption is not None:
self.body.append('\n\\begin{threeparttable}\n' self.body.append(u'\n\\begin{threeparttable}\n'
'\\caption{%s}\n' % self.table.caption) u'\\caption{%s}\n' % self.table.caption)
if self.table.longtable: if self.table.longtable:
self.body.append('\n\\begin{longtable}') self.body.append('\n\\begin{longtable}')
elif self.table.has_verbatim: elif self.table.has_verbatim:
@ -645,7 +645,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
else: else:
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n') self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
if self.table.longtable and self.table.caption is not None: if self.table.longtable and self.table.caption is not None:
self.body.append('\\caption{%s} \\\\\n' % self.table.caption) self.body.append(u'\\caption{%s} \\\\\n' % self.table.caption)
if self.table.longtable: if self.table.longtable:
self.body.append('\\hline\n') self.body.append('\\hline\n')
@ -655,7 +655,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
% _('continued from previous page')) % _('continued from previous page'))
self.body.append('\n\\hline\n') self.body.append('\n\\hline\n')
self.body.append('\\endhead\n\n') self.body.append('\\endhead\n\n')
self.body.append(r'\hline \multicolumn{%s}{|r|}{{%s}} \\ \hline' self.body.append(ur'\hline \multicolumn{%s}{|r|}{{%s}} \\ \hline'
% (self.table.colcount, % (self.table.colcount,
_('Continued on next page'))) _('Continued on next page')))
self.body.append('\n\\endfoot\n\n') self.body.append('\n\\endfoot\n\n')
@ -950,7 +950,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def _make_visit_admonition(name): def _make_visit_admonition(name):
def visit_admonition(self, node): def visit_admonition(self, node):
self.body.append('\n\\begin{notice}{%s}{%s:}' % self.body.append(u'\n\\begin{notice}{%s}{%s:}' %
(name, admonitionlabels[name])) (name, admonitionlabels[name]))
return visit_admonition return visit_admonition
def _depart_named_admonition(self, node): def _depart_named_admonition(self, node):
@ -1305,7 +1305,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_inline(self, node): def visit_inline(self, node):
classes = node.get('classes', []) classes = node.get('classes', [])
self.body.append(r'\DUspan{%s}{' %','.join(classes)) self.body.append(r'\DUspan{%s}{' % ','.join(classes))
def depart_inline(self, node): def depart_inline(self, node):
self.body.append('}') self.body.append('}')