Adding :caption: is easy.
In setup() add 'caption': directives.unchanged to the options. And in run() add if 'caption' in options: caption=options['caption'] before format_template().
Feel free to open a PR (preferably with a test -- sphinx has been having many backcompat issues in recent versions so we should try to make sure things stay in a working state...) :-)
Referencing plots is not explicitly mentioned in the docs, but since the plot_directive generates a figure, which can be labelled by putting a label in front of it, I would expect the plot to catch the label and the ref to be working. There is even code for moving
the reference from the "htmlonly" (or "latexonly") code to the actual figure node itself
The culprit is mark_plot_labels. It looks for tagnames html_only and latex_only, but they are actually named only. So it was never actually doing anything.
I modified the code such that it adds the :name: option to the figure in the template. I printed the result to console. The :name: is there as expected, but the ref does not work. If I paste the code, generated by the template engine, into the actual source, the ref is working.
Why does a label inside the only directive generated by the template engine not work?
I believe the root causation is how the only directive handles references, as pointed out at sphinx-doc/sphinx#2150.
If we add :name: along with other options, it will be rendered twice (one within only:: html and the other within only:: not html), which will cause the Duplicate explicit target name warning eventually.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
quantenschaum commented on Oct 10, 2017
quantenschaum commented on Oct 10, 2017
:numref: works with the following template in conf.py where the only directives have been removed.
quantenschaum commented on Oct 10, 2017
Adding :caption: is easy.
In setup() add 'caption': directives.unchanged to the options. And in run() add if 'caption' in options: caption=options['caption'] before format_template().
anntzer commented on Oct 10, 2017
Feel free to open a PR (preferably with a test -- sphinx has been having many backcompat issues in recent versions so we should try to make sure things stay in a working state...) :-)
quantenschaum commented on Oct 10, 2017
When I try to add 'name' to the options in setup(), I get
So it seems, as if there was already a name option, but supplying :name: does not work either.
tacaswell commented on Oct 11, 2017
Is this documented to work and does not or would you like this to work as described?
quantenschaum commented on Oct 11, 2017
Referencing plots is not explicitly mentioned in the docs, but since the plot_directive generates a figure, which can be labelled by putting a label in front of it, I would expect the plot to catch the label and the ref to be working. There is even code for moving
but it seems to fail.
quantenschaum commented on Oct 11, 2017
The culprit is mark_plot_labels. It looks for tagnames html_only and latex_only, but they are actually named only. So it was never actually doing anything.
After fixing this, it fails, because there is no document.settings.env.labels. Where is it now?
quantenschaum commented on Oct 11, 2017
I modified the code such that it adds the :name: option to the figure in the template. I printed the result to console. The :name: is there as expected, but the ref does not work. If I paste the code, generated by the template engine, into the actual source, the ref is working.
Why does a label inside the only directive generated by the template engine not work?
tushuhei commented on Apr 28, 2021
I believe the root causation is how the only directive handles references, as pointed out at sphinx-doc/sphinx#2150.
If we add :name: along with other options, it will be rendered twice (one within only:: html and the other within only:: not html), which will cause the Duplicate explicit target name warning eventually.
eudoxos commented on May 21, 2022
Anyone has a workaround for this, besides the hack in sfstoolbox/theory#5 ?
github-actions commented on May 23, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!