def default_latex_documents(config): # type: (Config) -> List[Tuple[str, str, str, str, str]] """ Better default latex_documents settings. """ return [(config.master_doc, make_filename_from_project(config.project) + '.tex', texescape.escape_abbr(texescape.escape(config.project)), texescape.escape_abbr(texescape.escape(config.author)), 'manual')]
def default_latex_documents(config: Config) -> List[Tuple[str, str, str, str, str]]: """ Better default latex_documents settings. """ project = texescape.escape(config.project, config.latex_engine) author = texescape.escape(config.author, config.latex_engine) return [(config.master_doc, make_filename_from_project(config.project) + '.tex', texescape.escape_abbr(project), texescape.escape_abbr(author), config.latex_theme)]
def latex_visit_todo_node(self: LaTeXTranslator, node: todo_node) -> None: if self.config.todo_include_todos: self.body.append('\n\\begin{sphinxadmonition}{note}{') self.body.append(self.hypertarget_to(node)) title_node = cast(nodes.title, node[0]) title = texescape.escape(title_node.astext(), self.config.latex_engine) self.body.append('%s:}' % title) node.pop(0) else: raise nodes.SkipNode
def unhighlighted(self, source: str) -> str: warnings.warn('PygmentsBridge.unhighlighted() is now deprecated.', RemovedInSphinx30Warning, stacklevel=2) if self.dest == 'html': return '<pre>' + html.escape(source) + '</pre>\n' else: # first, escape highlighting characters like Pygments does source = source.translate(escape_hl_chars) # then, escape all characters nonrepresentable in LaTeX source = texescape.escape(source, self.latex_engine) return '\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n' + \ source + '\\end{Verbatim}\n'
def visit_caption(self, node): self.in_caption += 1 if isinstance(node.parent, captioned_literal_block): self.body.append('\\sphinxSetupCaptionForVerbatim{') elif self.in_minipage and isinstance(node.parent, nodes.figure): self.body.append('\\captionof{figure}{') elif self.table and node.parent.tagname == 'figure': self.body.append('\\sphinxfigcaption{') else: # Use alt text as short caption for the \listoffigures short = '' if isinstance(node.parent, nodes.figure): if isinstance(node.parent.children[0], nodes.image): alt = node.parent.children[0].get('alt') if alt: short = '[' + texescape.escape(alt) + ']' self.body.append('\\caption%s{' % short)
def visit_desc(translator: LaTeXTranslator, node: addnodes.desc) -> None: """ Visit an :class:`addnodes.desc` node and add a custom table of contents label for the item, if required. .. versionadded:: 0.3.0 :param translator: :param node: """ translator.body.append("\n\n\\vspace{5px}\n\n\\begin{fulllineitems}\n") # Add class, function and method directives to toctree. if node.attributes["objtype"] in set(translator.config.toctree_plus_types): attributes = node.children[0].attributes if attributes["ids"]: # Only want nodes with an anchor title = texescape.escape(attributes.get("fullname", node.children[0].astext())) sectionlevel = translator.sectionlevel + 1 if node.attributes["objtype"] in {"method", "attribute"}: # TODO: remove special case title = title.split('.', 1)[-1] sectionlevel += 1 sectiontype = translator.sectionnames[sectionlevel] translator.body.append(f"\\phantomsection\\stepcounter{{{sectiontype}}}\n") translator.body.append( "\\addcontentsline{toc}{%s}{\\protect\\numberline{\\the%s}{%s}}\n" % (sectiontype, sectiontype, title) ) if translator.table: translator.table.has_problematic = True
def generate(d, overwrite=True, silent=False): """ Borrowed from Sphinx 1.3b3. Generate project based on values in *d*. """ texescape.init() if "mastertoctree" not in d: d["mastertoctree"] = "" if "mastertocmaxdepth" not in d: d["mastertocmaxdepth"] = 2 d["project_fn"] = make_filename(d["project"]) d["project_manpage"] = d["project_fn"].lower() d["now"] = time.asctime() d["project_underline"] = column_width(d["project"]) * "=" d["copyright"] = time.strftime("%Y") + ", " + d["author"] d["author_texescaped"] = texescape.escape( str(d["author"]).translate(str(d["author"]))) d["project_doc"] = d["project"] + " Documentation" d["project_doc_texescaped"] = texescape.escape( str(d["project"] + " Documentation").translate( str(d["project"] + " Documentation"))) if not path.isdir(d["path"]): ensuredir(d["path"]) srcdir = d["sep"] and path.join(d["path"], "source") or d["path"] ensuredir(srcdir) d["exclude_patterns"] = "" # TODO: Work if we want this. # if d['sep']: # builddir = path.join(d['path'], 'build') # # else: # builddir = path.join(srcdir, d['dot'] + 'build') # d['exclude_patterns'] = repr(d['dot'] + 'build') # ensuredir(builddir) ensuredir(path.join(srcdir, d["dot"] + "templates")) ensuredir(path.join(srcdir, d["dot"] + "static")) def write_file(fpath, content, newline=None): if overwrite or not path.isfile(fpath): print(f"Creating file {fpath}.") f = open(fpath, "wt", encoding="utf-8", newline=newline) try: f.write(content) finally: f.close() else: print(f"File {fpath} already exists, skipping.") conf_text = ABLOG_CONF.format(**d) write_file(path.join(srcdir, "conf.py"), conf_text) masterfile = path.join(srcdir, d["master"] + d["suffix"]) write_file(masterfile, ABLOG_INDEX.format(**d)) about = path.join(srcdir, "about" + d["suffix"]) write_file(about, ABLOG_ABOUT.format(**d)) d["post_date"] = datetime.datetime.today().strftime("%b %d, %Y") firstpost = path.join(srcdir, "first-post" + d["suffix"]) write_file(firstpost, ABLOG_POST.format(**d)) if silent: return print(bold("Finished: An initial directory structure has been created."))
def visit_exercise(self, node, name=''): self.body.append('\n\\begin{exercise}') title = texescape.escape(node['title']) if node['title']: self.body.append('[' + title + ']')
def latex_escape(text): return escape(text)