Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/docutils/writers/xetex/__init__.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 # :Author: Günter Milde <milde@users.sourceforge.net> | |
| 5 # :Revision: $Revision: 8411 $ | |
| 6 # :Date: $Date: 2019-11-05 14:32:13 +0100 (Di, 05. Nov 2019) $ | |
| 7 # :Copyright: © 2010 Günter Milde. | |
| 8 # :License: Released under the terms of the `2-Clause BSD license`_, in short: | |
| 9 # | |
| 10 # Copying and distribution of this file, with or without modification, | |
| 11 # are permitted in any medium without royalty provided the copyright | |
| 12 # notice and this notice are preserved. | |
| 13 # This file is offered as-is, without any warranty. | |
| 14 # | |
| 15 # .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause | |
| 16 | |
| 17 """ | |
| 18 XeLaTeX document tree Writer. | |
| 19 | |
| 20 A variant of Docutils' standard 'latex2e' writer producing LaTeX output | |
| 21 suited for processing with the Unicode-aware TeX engines | |
| 22 LuaTeX and XeTeX. | |
| 23 """ | |
| 24 | |
| 25 __docformat__ = 'reStructuredText' | |
| 26 | |
| 27 import os | |
| 28 import os.path | |
| 29 import re | |
| 30 | |
| 31 import docutils | |
| 32 from docutils import frontend, nodes, utils, writers, languages | |
| 33 from docutils.writers import latex2e | |
| 34 | |
| 35 class Writer(latex2e.Writer): | |
| 36 """A writer for Unicode-aware LaTeX variants (XeTeX, LuaTeX)""" | |
| 37 | |
| 38 supported = ('lxtex', 'xetex', 'xelatex', 'luatex', 'lualatex') | |
| 39 """Formats this writer supports.""" | |
| 40 | |
| 41 default_template = 'xelatex.tex' | |
| 42 default_preamble = '\n'.join([ | |
| 43 r'% Linux Libertine (free, wide coverage, not only for Linux)', | |
| 44 r'\setmainfont{Linux Libertine O}', | |
| 45 r'\setsansfont{Linux Biolinum O}', | |
| 46 r'\setmonofont[HyphenChar=None,Scale=MatchLowercase]{DejaVu Sans Mono}', | |
| 47 ]) | |
| 48 | |
| 49 config_section = 'xetex writer' | |
| 50 config_section_dependencies = ('writers', 'latex writers', | |
| 51 'latex2e writer') # TODO: remove dependency on `latex2e writer`. | |
| 52 | |
| 53 settings_spec = frontend.filter_settings_spec( | |
| 54 latex2e.Writer.settings_spec, | |
| 55 'font_encoding', | |
| 56 template=('Template file. Default: "%s".' % default_template, | |
| 57 ['--template'], {'default': default_template, 'metavar': '<file>'}), | |
| 58 latex_preamble=('Customization by LaTeX code in the preamble. ' | |
| 59 'Default: select "Linux Libertine" fonts.', | |
| 60 ['--latex-preamble'], | |
| 61 {'default': default_preamble}), | |
| 62 ) | |
| 63 | |
| 64 def __init__(self): | |
| 65 latex2e.Writer.__init__(self) | |
| 66 self.settings_defaults.update({'fontencoding': ''}) # use default (EU1 or EU2) | |
| 67 self.translator_class = XeLaTeXTranslator | |
| 68 | |
| 69 | |
| 70 class Babel(latex2e.Babel): | |
| 71 """Language specifics for XeTeX. | |
| 72 | |
| 73 Use `polyglossia` instead of `babel` and adapt settings. | |
| 74 """ | |
| 75 language_codes = latex2e.Babel.language_codes.copy() | |
| 76 # Additionally supported or differently named languages: | |
| 77 language_codes.update({ | |
| 78 # code Polyglossia-name comment | |
| 79 'cop': 'coptic', | |
| 80 'de': 'german', # new spelling (de_1996) | |
| 81 'de-1901': 'ogerman', # old spelling | |
| 82 'dv': 'divehi', # Maldivian | |
| 83 'dsb': 'lsorbian', | |
| 84 'el-polyton': 'polygreek', | |
| 85 'fa': 'farsi', | |
| 86 'grc': 'ancientgreek', | |
| 87 'hsb': 'usorbian', | |
| 88 'sh-Cyrl': 'serbian', # Serbo-Croatian, Cyrillic script | |
| 89 'sh-Latn': 'croatian', # Serbo-Croatian, Latin script | |
| 90 'sq': 'albanian', | |
| 91 'sr': 'serbian', # Cyrillic script (sr-Cyrl) | |
| 92 'th': 'thai', | |
| 93 'vi': 'vietnamese', | |
| 94 # zh-Latn: ??? # Chinese Pinyin | |
| 95 }) | |
| 96 # normalize (downcase) keys | |
| 97 language_codes = dict([(k.lower(), v) for (k, v) in language_codes.items()]) | |
| 98 | |
| 99 # Languages without Polyglossia support: | |
| 100 for key in ('af', # 'afrikaans', | |
| 101 'de-AT', # 'naustrian', | |
| 102 'de-AT-1901', # 'austrian', | |
| 103 # TODO: use variant=... for English variants | |
| 104 'en-CA', # 'canadian', | |
| 105 'en-GB', # 'british', | |
| 106 'en-NZ', # 'newzealand', | |
| 107 'en-US', # 'american', | |
| 108 'fr-CA', # 'canadien', | |
| 109 'grc-ibycus', # 'ibycus', (Greek Ibycus encoding) | |
| 110 'sr-Latn', # 'serbian script=latin' | |
| 111 ): | |
| 112 del(language_codes[key.lower()]) | |
| 113 | |
| 114 def __init__(self, language_code, reporter): | |
| 115 self.language_code = language_code | |
| 116 self.reporter = reporter | |
| 117 self.language = self.language_name(language_code) | |
| 118 self.otherlanguages = {} | |
| 119 self.warn_msg = 'Language "%s" not supported by Polyglossia.' | |
| 120 self.quote_index = 0 | |
| 121 self.quotes = ('"', '"') | |
| 122 # language dependent configuration: | |
| 123 # double quotes are "active" in some languages (e.g. German). | |
| 124 self.literal_double_quote = u'"' # TODO: use \textquotedbl ? | |
| 125 | |
| 126 def __call__(self): | |
| 127 setup = [r'\usepackage{polyglossia}', | |
| 128 r'\setdefaultlanguage{%s}' % self.language] | |
| 129 if self.otherlanguages: | |
| 130 setup.append(r'\setotherlanguages{%s}' % | |
| 131 ','.join(sorted(self.otherlanguages.keys()))) | |
| 132 return '\n'.join(setup) | |
| 133 | |
| 134 | |
| 135 class XeLaTeXTranslator(latex2e.LaTeXTranslator): | |
| 136 """ | |
| 137 Generate code for LaTeX using Unicode fonts (XeLaTex or LuaLaTeX). | |
| 138 | |
| 139 See the docstring of docutils.writers._html_base.HTMLTranslator for | |
| 140 notes on and examples of safe subclassing. | |
| 141 """ | |
| 142 | |
| 143 def __init__(self, document): | |
| 144 self.is_xetex = True # typeset with XeTeX or LuaTeX engine | |
| 145 latex2e.LaTeXTranslator.__init__(self, document, Babel) | |
| 146 if self.latex_encoding == 'utf8': | |
| 147 self.requirements.pop('_inputenc', None) | |
| 148 else: | |
| 149 self.requirements['_inputenc'] = (r'\XeTeXinputencoding %s ' | |
| 150 % self.latex_encoding) |
