def depart_title(translator: LaTeXTranslator, node: nodes.title) -> None: """ Depart a :class:`docutils.nodes.title` node. :param translator: :param node: The node itself. """ translator.in_title = 0 if isinstance(node.parent, nodes.table): translator.table.caption = translator.popbody() else: translator.body.append(translator.context.pop())
def visit_title(translator: LaTeXTranslator, node: nodes.title) -> None: """ Visit a :class:`docutils.nodes.title` node. :param translator: :param node: The node itself. """ if isinstance(node.parent, addnodes.seealso): # the environment already handles this raise nodes.SkipNode elif isinstance(node.parent, nodes.section): if translator.this_is_the_title: if len(node.children) != 1 and not isinstance( node.children[0], nodes.Text): logger.warning(__("document title is not a single Text node"), location=node) if not translator.elements["title"]: # text needs to be escaped since it is inserted into # the output literally translator.elements["title"] = translator.escape(node.astext()) translator.this_is_the_title = 0 raise nodes.SkipNode else: short = '' if node.traverse(nodes.image): short = f"[{translator.escape(' '.join(clean_astext(node).split()))}]" try: translator.body.append( fr'\{translator.sectionnames[translator.sectionlevel]}{short}{{' ) except IndexError: # just use "subparagraph", it's not numbered anyway translator.body.append( fr'\{translator.sectionnames[-1]}{short}{{') # breakpoint() translator.context.append( f'}}\n{translator.hypertarget_to(node.parent)}') elif isinstance(node.parent, nodes.topic): translator.body.append(r'\sphinxstyletopictitle{') translator.context.append('}\n') elif isinstance(node.parent, nodes.sidebar): translator.body.append(r'\sphinxstylesidebartitle{') translator.context.append('}\n') elif isinstance(node.parent, nodes.Admonition): translator.body.append('{') translator.context.append('}\n') elif isinstance(node.parent, nodes.table): # Redirect body output until title is finished. translator.pushbody([]) else: logger.warning( __("encountered title node not in section, topic, table, admonition or sidebar" ), location=node, ) translator.body.append("\\sphinxstyleothertitle{") translator.context.append('}\n') translator.in_title = 1