images icon indicating copy to clipboard operation
images copied to clipboard

Figure directives

Open thedrow opened this issue 5 years ago • 10 comments

Can we add support for figure directives as well as image directives?

thedrow avatar Jun 08 '20 08:06 thedrow

Could you elaborate a little?

There is the numfig configuration option which adds numbers to all "figures", tables etc. if they have a caption.

There is also the figure directive.

Do you just wish the lightbox2 css applied to images inserted/loaded through the figure: whatever.jpg directive?

jonascj avatar Jun 08 '20 10:06 jonascj

Great idea, I could easily have wished for that myself in the past. Feel free to implement it and make a PR, otherwise I'll have a look at it a few weeks from now.

jonascj avatar Jun 09 '20 19:06 jonascj

How time flies when you have a baby and a 3-year-old! Please accept my apologies for not attending to the PRs and issues in a timely fashion. I'll attend to them at the latest on August 29th and 30th (I have another project with deadline on August 28th).

jonascj avatar Aug 20 '20 10:08 jonascj

@jonascj I think the main concern of adding lightbox to figures is that lightbox label does not have a translatable text, i.e. if you add a caption to your LB image, you won't be able to translate the phrase

icq8680 avatar Sep 09 '20 16:09 icq8680

Any news?

SilverRainZ avatar Nov 15 '20 15:11 SilverRainZ

@SilverRainZ No, I haven't looked into it yet. You are welcome to submit a PR if you can find a way to implement it. See also #20 :-)

jonascj avatar Jan 06 '21 23:01 jonascj

Some findings and/or realizations which might be worth remembering, going forward with this:

  • Typical HTML markup for a figure (after building):
<figure class="align-default" id="id1">                                         
    <span id="some-fig-label"></span>                                               
    <img  alt="_images/python.png" src="_images/python.png" />
    <figcaption>                                                                    
    <p>
        <span class="caption-number">Fig. 1 </span>
        <span class="caption-text">The Python logo.</span>
        <a class="headerlink" href="#id    1" title="Permalink to this image">¶</a>
    </p>          
    </figcaption>                                                                   
</figure>

All that is needed to turn this into a lightbox2 image is to wrap the <img> tag in <a data-lightbox="[unique id]" data-title="The Python logo." href="_images/python.png">.

  • EDIT: ~~At present neither .. image:: nor .. thumbnail:: directives can have a label and be referenced. The reason being neither have a title or caption associated with them. So if referenced what should the reference show? Fig. <num> is not meaningful since it has no number. The Python logo is not meaningful either since it has no title.~~

At present .. thumbnail:: can not be referenced in any way (afaik). Adding an explicit target above a thumbnail directive will result in a warning, i.e. this will not work with thumbnails (but it works with .. image::):

.. _target whatever:

.. thumbnail:: whatever.jpg

An image of whatever can be seen here: :ref:`Whatever <target whatever>`.
  • There seem to be two somewhat equivalent objectives / solutions: 1) Make the .. thumbnail:: directive numbered so it can be referenced, 2) Wrap the .. figure:: directive's <img> tag in a lightbox link (see above).

jonascj avatar Jul 28 '21 21:07 jonascj

#27 Indicates there is currently no way of referencing .. thumbnail:: directives, explicit targets do not work (see above or #27). That is a bug imo and we should at least fix that.

At the same time I think we should make the .. thumbnail:: directive behave like .. figure::, if numfig = True thumbnails should be numbered just as figures (maybe with a sphinxcontrib.images configuration option to turn on/off this feature). I suppose it could be done two ways: 1) Utilize the figure directive when producing thumbnails, 2) create/register a counter with the .. thumbnail:: directive.

jonascj avatar Jul 30 '21 20:07 jonascj