Skip to content
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

Select Extensions on Build Type #3740

Closed
ax3l opened this issue May 12, 2017 · 12 comments
Closed

Select Extensions on Build Type #3740

ax3l opened this issue May 12, 2017 · 12 comments
Labels
Milestone

Comments

@ax3l
Copy link

ax3l commented May 12, 2017

Following #1570, there is currently no way to easily control enabling or disabling a sphinx extension based on the build type in conf.py.

The concrete example I would like is building math via sphinx.ext.imgmath for epub but using sphinx.ext.mathjax for html. The rst macros/"interfaces" are compatible but the output is build-type specific.

This is also troublesome when building on RTD since one can not switch extensions on and off depending on the build type (but can build HTML, pdf and epub on RTD).

@tk0miya tk0miya added internals:config type:proposal a feature suggestion labels May 13, 2017
@tk0miya tk0miya added this to the some future version milestone May 13, 2017
@tk0miya
Copy link
Member

tk0miya commented May 13, 2017

I think this contains two proposal. The first one is switching math extension for builders. The another is switching whole of extensions for builders.

I think the first proposal is understandable and easy to improve. Because math extensions (imgmath, jsmath and mathjax) are used only to represent equations on HTML builders. The common part of the extensions (nodes, directives, representations for other builders and so on) is implemented as a library module named sphinx.ext.mathbase. The difference of extensions are limited on writing phase. So it can be switched easily.

On the other hand, switching extensions by builders is hard. We have many types of extensions; builders, directives, transforms and so on. Some might work on reading phase, and some might on both reading and writing phase. But, in sphinx, the builder is determined at resolving phase.
http://www.sphinx-doc.org/en/stable/extdev/tutorial.html#build-phases

In addition, now we don't have to way to unload extensions.

Anyway, we have to consider the advantage of switching. If it is worthy enough, we should do it.

Any ideas?

@tk0miya tk0miya modified the milestones: 1.7, some future version May 13, 2017
@pashango2
Copy link
Contributor

I have similar problems as well. However, my problem is not just formulas.

  • sphinxcontrib-mermaid
  • sphinxcontrib-plantuml
  • sphinx.ext.graphviz
  • etc, etc, etc ...

It is a common problem that all Sphinx extensions that generate diagrams have.
We need to control the output format with a lot of Sphinx extensions.

The easiest way is to pass the 'buildername' to the conf.py global variable. and leave the extension settings to the user.

Specifically, change here as follows.

Conf_globals = confoverrides or {}.
Conf_globals ['__ buildername__'] = buildername
Self.config = Config (confdir, CONFIG_FILENAME,
                      Conf_globals, self.tags)

This method is not elegant, but it is simple, easy and powerful.

@ax3l
Copy link
Author

ax3l commented May 17, 2017

maybe exposing the builder in general to conf.py would be way to go here? would you like to prepare a PR for that?

@pashango2
Copy link
Contributor

I'm sorry, I made a mistake in correcting it.
To be exact, modify 'sphinx/config.py' and 'sphinx/application.py'.

If sphinx can pass __buildername__ to the global variable of conf.py, We can write as follows.

if __buildername__ == "epub":
    extensions += ['sphinx.ext.imgmath']
else:
    extensions += ['sphinx.ext.mathjax']

Prepare PR if necessary.

@tk0miya
Copy link
Member

tk0miya commented May 18, 2017

It is a common problem that all Sphinx extensions that generate diagrams have.
We need to control the output format with a lot of Sphinx extensions.

Hmm? Is that real problem of yours?
AFAIK the extensions you listed are incompatible for each other. so you can't switch one to another.
For example, sphinxcontrib-mermaid provides mermaid directive. But sphinxcontrib-plantuml does not. It uses plantuml directive to mark up UML diagrams. So you'll see errors even if sphinx support switching extensions.

The easiest way is to pass the 'buildername' to the conf.py global variable. and leave the extension settings to the user.

I'm worry about it breaks the incremental build feature of Sphinx. On the other hand, I still don't understand the advantages.
I understand about math extensions. So I'll hack them in 1.7.

@pashango2
Copy link
Contributor

I apologize for being confused by my poor English ability.
The problem is simple.

Mermaid will output graphics in JavaScript as standard.
When outputting in HTML, output with JavaScript.
When outputting with Epub, output with Png.
I just want to do it.

I'd like to write like this in 'conf.py'.

extensions += ['sphinxcontrib.mermaid']

if __buildername__ == "epub":
    mermaid_output_format = "png"
    import os
    mermaid_cmd = os.path.abspath("../../node_modules/.bin/mermaid.cmd")
else:
    mermaid_output_format = "raw"

I also want to separate the output for each builder with other extensions.

appreciate the reply.

@shimizukawa shimizukawa modified the milestones: 1.7, 1.8 Jan 7, 2018
@wojdyr
Copy link
Contributor

wojdyr commented Apr 30, 2018

a workaround I'm using for this is checking sys.argv in conf.py. For example:

if 'epub' in sys.argv:
    # configuration for epub

@ax3l
Copy link
Author

ax3l commented May 4, 2018

@tk0miya just a ping: did you add something for math extension switching to the 1.7 release and I missed it? :)

@tk0miya
Copy link
Member

tk0miya commented May 5, 2018

Sorry, nothing has changed yet because we determined to postpone this. New target release is 1.8.

@ax3l
Copy link
Author

ax3l commented May 7, 2018

Ah sorry, I missed the modified milestone. Thanks for the heads-up!

@tk0miya
Copy link
Member

tk0miya commented Jul 28, 2018

I just finished migration of math notations to sphinx-core in #4988.
Since 1.8, you can switch math renderer module by *_html_renderer setting.

Thanks,

@tk0miya tk0miya closed this as completed Jul 28, 2018
@ax3l
Copy link
Author

ax3l commented Aug 2, 2018

This is great news, thank you! ✨ 🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants