From: engelbert g. <gr...@us...> - 2004-06-18 22:56:45
|
Update of /cvsroot/docutils/docutils/docutils/writers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10477/docutils/writers Modified Files: latex2e.py Log Message: Move unicode to LaTeX into a method. Index: latex2e.py =================================================================== RCS file: /cvsroot/docutils/docutils/docutils/writers/latex2e.py,v retrieving revision 1.110 retrieving revision 1.111 diff -u -d -r1.110 -r1.111 --- latex2e.py 17 Jun 2004 08:31:50 -0000 1.110 +++ latex2e.py 18 Jun 2004 22:56:36 -0000 1.111 @@ -710,6 +710,23 @@ def language_label(self, docutil_label): return self.language.labels[docutil_label] + def utf8_to_latex(self,text): + # see LaTeX codec http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252124 + # Only some special chracters are translated, for documents with many utf-8 + # chars one should use the LaTeX unicode package. + latex_equivalents = { + u'\u00A0' : '~', + u'\u00A9' : '{\\copyright}', + u'\u2013' : '{--}', + u'\u2014' : '{---}', + u'\u2020' : '{\\dag}', + u'\u2021' : '{\\ddag}', + u'\u21d4' : '{$\\Leftrightarrow$}', + } + for uchar in latex_equivalents.keys(): + text = text.replace(uchar,latex_equivalents[uchar]) + return text + def encode(self, text): """ Encode special characters in `text` & return. @@ -785,13 +802,7 @@ if self.insert_none_breaking_blanks: text = text.replace(' ', '~') if self.settings.output_encoding != 'utf-8': - # see LaTeX codec http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252124 - text = text.replace(u'\u00A0', '~') - text = text.replace(u'\u00A9', '{\\copyright}') - text = text.replace(u'\u2013', '{--}') - text = text.replace(u'\u2014', '{---}') - text = text.replace(u'\u2020', '{\\dag}') - text = text.replace(u'\u2021', '{\\ddag}') + text = self.utf8_to_latex(text) return text def attval(self, text, |