sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.6k stars 2.12k forks source link

Make complex setting values like latex_documents overridable #12438

Open terrorfisch opened 5 months ago

terrorfisch commented 5 months ago

Is your feature request related to a problem? Please describe. I want to override latex specific settings when invoking sphinx-build to embed the generated latex in an external document. I do not want to edit the original conf.py. First I tried a dedidcated conf.py but ran into problems with relative paths so I decided to try the command line settings override.

The --define documentation nicely explains how to override dict and list type values. However, latex_documents is a list of tuples which are not handled correctly.

Describe the solution you'd like I do not have a favourite solution.

My original problem of patching "conf.py" without file modification can also be solved by additional "appendable" python code.

Describe alternatives you've considered

Additional context Parsing of list type values (btw: There is no way to escape the ","): https://github.com/sphinx-doc/sphinx/blob/6471027d1936f0a0a38ef281862f0b29c53618f6/sphinx/config.py#L342

Interpretation of list elements as sequence in the latex builder: https://github.com/sphinx-doc/sphinx/blob/6471027d1936f0a0a38ef281862f0b29c53618f6/sphinx/builders/latex/__init__.py#L150

mgeier commented 5 months ago

First I tried a dedidcated conf.py but ran into problems with relative paths

I know this is fiddly, but I made it work in one instance like this: https://github.com/mgeier/diss/blob/3c5dcb7312b5132efccc4cbc7a55facf654f7c58/sphinx-splines/conf.py#L7-L8 Maybe that helps?

terrorfisch commented 5 months ago

Thank you very much! That looks like it fits my usecase and solves some other problems I have been finding worse solutions for.

EDIT: I had to extend it by

for idx, html_path in enumerate(html_static_path):
    html_path = pathlib.Path(html_path)
    if not html_path.is_absolute():
        html_path = (original_conf_py.parent / html_path).resolve()
        html_static_path[idx] = str(html_path)