How to pass a custom variable from sphinx conf file into a latex document

544 views
Skip to first unread message

Pieter Claeys

unread,
Jun 21, 2019, 5:06:30 AM6/21/19
to sphinx-users
I would need to extend / modify the default latex generated document with a few extra variable fields (reason: I need to easily generate a few variations of a document with different title pages).

I already figured out to use latex_maketitle  where I can define some custom latex code.

However, if I would want a 'favoritecolor' variable somewhere in the conf.py file; and use that in the latex code to display 'favoritecolor' on the title screen: How should I do that?  I am newbie in latex code.


As an extra bonus, I would even like to set 'favoritecolor' at command-line and pass that to sphinx . But I seems you can only override a specific number of sphinx parameters (like project, release) using the -D argument. Any other ways to achieve my usecase?

Komiya Takeshi

unread,
Jun 22, 2019, 7:33:22 AM6/22/19
to sphinx...@googlegroups.com
Hi,

AFAIK, there are no proper way to do that via configurations. I think
you need to create your own Sphinx extension and modify LaTeX macros
from it.
Both custom variable in conf.py and `-D` argument for sphinx-build
command are need to add new config value.
And then you'll modify latex_maketitle configuration on config-inited
event (it is happened after initialization of configurations).

As a first step, please read the document for extension developers:
https://www.sphinx-doc.org/en/master/extdev/index.html

Thanks,
Takeshi KOMIYA

2019年6月21日(金) 18:06 Pieter Claeys <pi3...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To post to this group, send email to sphinx...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sphinx-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/5ce3ef94-c568-4c39-9100-b7fa9c815d67%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages