New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injecting arbitrary LaTeX code dynamically before \begin{document}
#8081
Comments
Why do you need to insert "raw" LaTeX code to the preamble part? Why don't you create a .sty file (.cls file) and load it?
|
There are two reasons behind this:
I would like to add the LaTeX extra code only if some nodes are inserted into the doctree. |
Indeed. It seems the |
…g tex file This postpones the evaluation of LaTeX packages via ``app.add_latex_package()`` to just before writing .tex file. That allows extensions to add LaTeX packages during reading and resolving phase.
…g tex file This postpones the evaluation of LaTeX packages via ``app.add_latex_package()`` to just before writing .tex file. That allows extensions to add LaTeX packages during reading and resolving phase.
…g tex file This postpones the evaluation of LaTeX packages via ``app.add_latex_package()`` to just before writing .tex file. That allows extensions to add LaTeX packages during reading and resolving phase.
…g tex file This postpones the evaluation of LaTeX packages via ``app.add_latex_package()`` to just before writing .tex file. That allows extensions to add LaTeX packages during reading and resolving phase.
…ge_in_latter_phase Close #8081: latex: Allow to add LaTeX package until writing tex file
…inx-doc#8081 This is cosmetic as the blank line starting varwidth environment used for merged table cells in latex output changed nothing to PDF. Nevertheless I extended a unit test to have a multi-paragraph merged cell using varwidth. What is important is that \sphinxAtStartPar line itself is never followed by blank line.
When writing a Sphinx extension or, even when using native Sphinx directives, some specific packages or commands must be declared ahead, before the
\begin{document}
. From my knowledge, it is currently impossible to dynamically add LaTeX code into the header from an extension or a directive.A usecase is for exemple the
hlist
refactoring #8072. This proposal would use a new LaTeX environment\hlist
that relies on several packages (multicol
,regexpatch
...). IMHO adding them directly insphinx.sty
isn't a good solution because you could add some unused packages if the user doesn't use anyhlist
in its documentation. The same would apply for many other case.So I propose a way for extensions or even Sphinx directives to dynamically include some LaTeX code based on the usage.
My current way of doing it is the following:
While this snippet works, I would prefer having a more convenient way of doing it with some guards that could perform some checks automatically. We could imagine a method such as:
I am not sure though when this should be done. After the
doctree
is resolved?The text was updated successfully, but these errors were encountered: