Labels and conditionals

55 views
Skip to first unread message

Mario S. Mommer

unread,
Mar 8, 2018, 10:24:32 AM3/8/18
to sphinx...@googlegroups.com
Hello,

with Sphinx v1.5.5, I want to reference a figure by number. At the same
time, I want to have different image formats for html or for latex.
While I can get each feature to work, I haven't been successful at
getting the combination to work.

The following works, of course:

=============
Dear reader, behold :numref:`Fig %s <fooBar>`.

.. _fooBar:

.. figure:: docgraphs/dot/dot.png
:figwidth: 80 %
:width: 80 %
:align: center

=============

With conditionals it looks like follows (and does not work)

=============
Dear reader, behold :numref:`Fig %s <fooBar>`.

.. _fooBar:

.. only:: latex

.. figure:: docgraphs/dot/dot.png
:figwidth: 80 %
:width: 80 %
:align: center

.. only:: html

.. figure:: docgraphs/dot/dot.svg
:figwidth: 80 %
:width: 100 %
:align: center

================

It says "WARNING: undefined label:foobar"

An alternative does not work, either:

=============
Dear reader, behold :numref:`Fig %s <fooBar>`.

.. only:: latex

.. _fooBar:

.. figure:: docgraphs/dot/dot.png
:figwidth: 80 %
:width: 80 %
:align: center

.. only:: html

.. _fooBar:

.. figure:: docgraphs/dot/dot.svg
:figwidth: 80 %
:width: 100 %
:align: center

================

Here it says fist

WARNING: Duplicate explicit target name: foobar

and then

WARNING: undefined label: foobar

How can I place the labels correctly? Any ideas / advice?

Regards, and thanks,

Mario

Takayuki Shimizukawa

unread,
Jun 10, 2018, 1:43:01 AM6/10/18
to sphinx...@googlegroups.com
Hi Mario,

You can use `dot.*` as a filename.
```
Dear reader, behold :numref:`Fig %s <fooBar>`.

.. _fooBar:

.. figure:: docgraphs/dot/dot.*
   :figwidth: 80 %
   :width: 80 %
   :align: center
```

This provides `dot.svg` for html and `dot.png` for latex.
Please refer supported_image_types attribute in the bellow page. You can get the supported image format for each builders.

Regards,

--
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.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages