📄 __init__.py
字号:
# Author: Engelbert Gruber# Contact: grubert@users.sourceforge.net# Revision: $Revision: 4242 $# Date: $Date: 2006-01-06 00:28:53 +0100 (Fri, 06 Jan 2006) $# Copyright: This module has been placed in the public domain."""LaTeX2e document tree Writer."""__docformat__ = 'reStructuredText'# code contributions from several people included, thanks to all.# some named: David Abrahams, Julien Letessier, Lele Gaifax, and others.## convention deactivate code by two # e.g. ##.import sysimport timeimport reimport stringfrom types import ListTypefrom docutils import frontend, nodes, languages, writers, utilsclass Writer(writers.Writer): supported = ('latex','latex2e') """Formats this writer supports.""" settings_spec = ( 'LaTeX-Specific Options', 'The LaTeX "--output-encoding" default is "latin-1:strict".', (('Specify documentclass. Default is "article".', ['--documentclass'], {'default': 'article', }), ('Specify document options. Multiple options can be given, ' 'separated by commas. Default is "10pt,a4paper".', ['--documentoptions'], {'default': '10pt,a4paper', }), ('Use LaTeX footnotes. LaTeX supports only numbered footnotes (does it?). ' 'Default: no, uses figures.', ['--use-latex-footnotes'], {'default': 0, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Format for footnote references: one of "superscript" or ' '"brackets". Default is "superscript".', ['--footnote-references'], {'choices': ['superscript', 'brackets'], 'default': 'superscript', 'metavar': '<format>', 'overrides': 'trim_footnote_reference_space'}), ('Use LaTeX citations. ' 'Default: no, uses figures which might get mixed with images.', ['--use-latex-citations'], {'default': 0, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Format for block quote attributions: one of "dash" (em-dash ' 'prefix), "parentheses"/"parens", or "none". Default is "dash".', ['--attribution'], {'choices': ['dash', 'parentheses', 'parens', 'none'], 'default': 'dash', 'metavar': '<format>'}), ('Specify a stylesheet file. The file will be "input" by latex in ' 'the document header. Default is no stylesheet (""). ' 'Overrides --stylesheet-path.', ['--stylesheet'], {'default': '', 'metavar': '<file>', 'overrides': 'stylesheet_path'}), ('Specify a stylesheet file, relative to the current working ' 'directory. Overrides --stylesheet.', ['--stylesheet-path'], {'metavar': '<file>', 'overrides': 'stylesheet'}), ('Table of contents by docutils (default) or latex. Latex (writer) ' 'supports only one ToC per document, but docutils does not write ' 'pagenumbers.', ['--use-latex-toc'], {'default': 0, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Let LaTeX print author and date, do not show it in docutils ' 'document info.', ['--use-latex-docinfo'], {'default': 0, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Color of any hyperlinks embedded in text ' '(default: "blue", "0" to disable).', ['--hyperlink-color'], {'default': 'blue'}), ('Enable compound enumerators for nested enumerated lists ' '(e.g. "1.2.a.ii"). Default: disabled.', ['--compound-enumerators'], {'default': None, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Disable compound enumerators for nested enumerated lists. This is ' 'the default.', ['--no-compound-enumerators'], {'action': 'store_false', 'dest': 'compound_enumerators'}), ('Enable section ("." subsection ...) prefixes for compound ' 'enumerators. This has no effect without --compound-enumerators. ' 'Default: disabled.', ['--section-prefix-for-enumerators'], {'default': None, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Disable section prefixes for compound enumerators. ' 'This is the default.', ['--no-section-prefix-for-enumerators'], {'action': 'store_false', 'dest': 'section_prefix_for_enumerators'}), ('Set the separator between section number and enumerator ' 'for compound enumerated lists. Default is "-".', ['--section-enumerator-separator'], {'default': '-', 'metavar': '<char>'}), ('When possibile, use verbatim for literal-blocks. ' 'Default is to always use the mbox environment.', ['--use-verbatim-when-possible'], {'default': 0, 'action': 'store_true', 'validator': frontend.validate_boolean}), ('Table style. "standard" with horizontal and vertical lines, ' '"booktabs" (LaTeX booktabs style) only horizontal lines ' 'above and below the table and below the header or "nolines". ' 'Default: "standard"', ['--table-style'], {'choices': ['standard', 'booktabs','nolines'], 'default': 'standard', 'metavar': '<format>'}), ('LaTeX graphicx package option. ' 'Possible values are "dvips", "pdftex". "auto" includes LaTeX code ' 'to use "pdftex" if processing with pdf(la)tex and dvips otherwise. ' 'Default is no option.', ['--graphicx-option'], {'default': ''}), ('LaTeX font encoding. ' 'Possible values are "T1", "OT1", "" or some other fontenc option. ' 'The font encoding influences available symbols, e.g. "<<" as one ' 'character. Default is "" which leads to package "ae" (a T1 ' 'emulation using CM fonts).', ['--font-encoding'], {'default': ''}), ),) settings_defaults = {'output_encoding': 'latin-1'} relative_path_settings = ('stylesheet_path',) config_section = 'latex2e writer' config_section_dependencies = ('writers',) output = None """Final translated form of `document`.""" def __init__(self): writers.Writer.__init__(self) self.translator_class = LaTeXTranslator def translate(self): visitor = self.translator_class(self.document) self.document.walkabout(visitor) self.output = visitor.astext() self.head_prefix = visitor.head_prefix self.head = visitor.head self.body_prefix = visitor.body_prefix self.body = visitor.body self.body_suffix = visitor.body_suffix"""Notes on LaTeX--------------* latex does not support multiple tocs in one document. (might be no limitation except for docutils documentation)* width * linewidth - width of a line in the local environment * textwidth - the width of text on the page Maybe always use linewidth ? *Bug* inside a minipage a (e.g. Sidebar) the linewidth is not changed, needs fix in docutils so that tables are not too wide. So we add locallinewidth set it initially and on entering sidebar and reset on exit."""class Babel: """Language specifics for LaTeX.""" # country code by a.schlock. # partly manually converted from iso and babel stuff, dialects and some _ISO639_TO_BABEL = { 'no': 'norsk', #XXX added by hand ( forget about nynorsk?) 'gd': 'scottish', #XXX added by hand 'hu': 'magyar', #XXX added by hand 'pt': 'portuguese',#XXX added by hand 'sl': 'slovenian', 'af': 'afrikaans', 'bg': 'bulgarian', 'br': 'breton', 'ca': 'catalan', 'cs': 'czech', 'cy': 'welsh', 'da': 'danish', 'fr': 'french', # french, francais, canadien, acadian 'de': 'ngerman', #XXX rather than german # ngerman, naustrian, german, germanb, austrian 'el': 'greek', 'en': 'english', # english, USenglish, american, UKenglish, british, canadian 'eo': 'esperanto', 'es': 'spanish', 'et': 'estonian', 'eu': 'basque', 'fi': 'finnish', 'ga': 'irish', 'gl': 'galician', 'he': 'hebrew', 'hr': 'croatian', 'hu': 'hungarian', 'is': 'icelandic', 'it': 'italian', 'la': 'latin', 'nl': 'dutch', 'pl': 'polish', 'pt': 'portuguese', 'ro': 'romanian', 'ru': 'russian', 'sk': 'slovak', 'sr': 'serbian', 'sv': 'swedish', 'tr': 'turkish', 'uk': 'ukrainian' } def __init__(self,lang): self.language = lang # pdflatex does not produce double quotes for ngerman in tt. self.double_quote_replacment = None if re.search('^de',self.language): #self.quotes = ("\"`", "\"'") self.quotes = ('{\\glqq}', '{\\grqq}') self.double_quote_replacment = "{\\dq}" else: self.quotes = ("``", "''") self.quote_index = 0 def next_quote(self): q = self.quotes[self.quote_index] self.quote_index = (self.quote_index+1)%2 return q def quote_quotes(self,text): t = None for part in text.split('"'): if t == None: t = part else: t += self.next_quote() + part return t def double_quotes_in_tt (self,text): if not self.double_quote_replacment: return text return text.replace('"', self.double_quote_replacment) def get_language(self): if self._ISO639_TO_BABEL.has_key(self.language): return self._ISO639_TO_BABEL[self.language] else: # support dialects. l = self.language.split("_")[0] if self._ISO639_TO_BABEL.has_key(l): return self._ISO639_TO_BABEL[l] return Nonelatex_headings = { 'optionlist_environment' : [ '\\newcommand{\\optionlistlabel}[1]{\\bf #1 \\hfill}\n' '\\newenvironment{optionlist}[1]\n' '{\\begin{list}{}\n' ' {\\setlength{\\labelwidth}{#1}\n' ' \\setlength{\\rightmargin}{1cm}\n' ' \\setlength{\\leftmargin}{\\rightmargin}\n' ' \\addtolength{\\leftmargin}{\\labelwidth}\n' ' \\addtolength{\\leftmargin}{\\labelsep}\n' ' \\renewcommand{\\makelabel}{\\optionlistlabel}}\n' '}{\\end{list}}\n', ], 'lineblock_environment' : [ '\\newlength{\\lineblockindentation}\n' '\\setlength{\\lineblockindentation}{2.5em}\n' '\\newenvironment{lineblock}[1]\n' '{\\begin{list}{}\n' ' {\\setlength{\\partopsep}{\\parskip}\n' ' \\addtolength{\\partopsep}{\\baselineskip}\n' ' \\topsep0pt\\itemsep0.15\\baselineskip\\parsep0pt\n' ' \\leftmargin#1}\n' ' \\raggedright}\n' '{\\end{list}}\n' ], 'footnote_floats' : [ '% begin: floats for footnotes tweaking.\n', '\\setlength{\\floatsep}{0.5em}\n', '\\setlength{\\textfloatsep}{\\fill}\n', '\\addtolength{\\textfloatsep}{3em}\n', '\\renewcommand{\\textfraction}{0.5}\n', '\\renewcommand{\\topfraction}{0.5}\n', '\\renewcommand{\\bottomfraction}{0.5}\n', '\\setcounter{totalnumber}{50}\n', '\\setcounter{topnumber}{50}\n', '\\setcounter{bottomnumber}{50}\n', '% end floats for footnotes\n', ], 'some_commands' : [ '% some commands, that could be overwritten in the style file.\n' '\\newcommand{\\rubric}[1]' '{\\subsection*{~\\hfill {\\it #1} \\hfill ~}}\n' '\\newcommand{\\titlereference}[1]{\\textsl{#1}}\n' '% end of "some commands"\n', ] }class DocumentClass: """Details of a LaTeX document class.""" # BUG: LaTeX has no deeper sections (actually paragrah is no # section either). # BUG: No support for unknown document classes. Make 'article' # default? _class_sections = { 'book': ( 'chapter', 'section', 'subsection', 'subsubsection' ), 'scrbook': ( 'chapter', 'section', 'subsection', 'subsubsection' ), 'report': ( 'chapter', 'section', 'subsection', 'subsubsection' ), 'scrreprt': ( 'chapter', 'section', 'subsection', 'subsubsection' ), 'article': ( 'section', 'subsection', 'subsubsection' ), 'scrartcl': ( 'section', 'subsection', 'subsubsection' ), } _deepest_section = 'subsubsection' def __init__(self, document_class): self.document_class = document_class def section(self, level): """ Return the section name at the given level for the specific document class. Level is 1,2,3..., as level 0 is the title.""" sections = self._class_sections[self.document_class] if level <= len(sections): return sections[level-1] else:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -