MCPcopy
hub / github.com/sphinx-doc/sphinx / write_documents

Method write_documents

sphinx/builders/latex/__init__.py:299–349  ·  view source on GitHub ↗
(self, _docnames: Set[str])

Source from the content-addressed store, hash-verified

297 self.copy_latex_additional_files()
298
299 def write_documents(self, _docnames: Set[str]) -> None:
300 docsettings = _get_settings(
301 LaTeXWriter, defaults=self.env.settings, read_config_files=True
302 )
303
304 for entry in self.document_data:
305 docname, targetname, title, author, themename = entry[:5]
306 theme = self.themes.get(themename)
307 toctree_only = False
308 if len(entry) > 5:
309 toctree_only = entry[5]
310 with progress_message(__('processing %s') % targetname, nonl=False):
311 doctree = self.env.get_doctree(docname)
312 toctree = next(doctree.findall(addnodes.toctree), None)
313 if toctree and toctree.get('maxdepth') > 0:
314 tocdepth = toctree.get('maxdepth')
315 else:
316 tocdepth = None
317
318 doctree = self.assemble_doctree(
319 docname,
320 toctree_only,
321 appendices=(
322 self.config.latex_appendices if theme.name != 'howto' else []
323 ),
324 )
325 doctree['docclass'] = theme.docclass
326 doctree['contentsname'] = self.get_contentsname(docname)
327 doctree['tocdepth'] = tocdepth
328 self.post_process_images(doctree)
329 self.update_doc_context(title, author, theme)
330 self.update_context()
331
332 with progress_message(__('writing')):
333 docsettings._author = author
334 docsettings._title = title
335 docsettings._contentsname = doctree['contentsname']
336 docsettings._docname = docname
337 docsettings._docclass = theme.name
338
339 doctree.settings = docsettings
340 visitor: LaTeXTranslator = self.create_translator(doctree, self, theme) # type: ignore[assignment]
341 doctree.walkabout(visitor)
342 output = visitor.astext()
343 destination_path = self.outdir / targetname
344 # https://github.com/sphinx-doc/sphinx/issues/4362
345 if (
346 not destination_path.is_file()
347 or destination_path.read_bytes() != output.encode()
348 ):
349 destination_path.write_text(output, encoding='utf-8')
350
351 def get_contentsname(self, indexfile: str) -> str:
352 tree = self.env.get_doctree(indexfile)

Callers

nothing calls this directly

Calls 13

assemble_doctreeMethod · 0.95
get_contentsnameMethod · 0.95
update_doc_contextMethod · 0.95
update_contextMethod · 0.95
_get_settingsFunction · 0.90
progress_messageClass · 0.90
get_doctreeMethod · 0.80
encodeMethod · 0.80
getMethod · 0.45
findallMethod · 0.45
post_process_imagesMethod · 0.45
create_translatorMethod · 0.45

Tested by

no test coverage detected