sphinx-doc / sphinx

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

LaTeX: figure with ``:align:`` in topic appears below the topic box #3701

Open jfbu opened 7 years ago

jfbu commented 7 years ago

The picture says it all:

capture d ecran 2017-05-03 a 23 33 30

Expected results

The figure appears inside the topic box.

Reproducible project / your project

.. topic:: This is a topic

   I will now try to insert some figure in this topic box. Oops... no figure
   here!

   .. figure:: more.png
      :align: left

      This is the caption.

      This is some legend. What am I doing here?

This is some text *after* the topic. There shouldn't be anything below it.

Environment info

Relates: #3289.

This is other demonstration that LaTeX package wrapfig can not be used for robust automated placement of objects such as figures with text flow around them. Use of wrapfigure environment is triggered by :align: option.

I propose there is some config variable to not use wrapfigure environment at all.

Here is result of adding to the tex file:

\renewenvironment{wrapfigure}[2]{\begin{figure}[H]}{\end{figure}}

capture d ecran 2017-05-03 a 23 42 43

Of course alignment is lost. But this was just proof of concept. Actually LaTeX writer does not even need to use figure LaTeX float with H, it can do its own "here" placement routine and do the caption with \sphinxcaptionof macro recently added to sphinx.sty for the caption, even if in deeply nested list item.

There is really no way to let wrapfig package work robustly for Sphinx. Although it does work in some circumstances, it is trapped by too many constructs, particularly lists. LaTeX2e does not, as far as I know have any robust solution for automated flow of text around objects in a way handling page breaks etc...

jfbu commented 7 years ago

@tk0miya could you check https://github.com/jfbu/sphinx/commit/f545805bd9949929a5c1f5defc5a36cd898c7d2f, as far as I understand LaTeX writer visit_figure there is lot of never executed branches due to the fact that when align attribute exists, the wrapfigure is used. Hence this commit removes the non executed branches. I will merge in stable if ok.

annanyearian commented 1 year ago

Ticket can probably be closed, seems above is no longer applicable to current version? Generated latex for me doesn't contain wrapfigure when using alignment.

Though in my case I wish it did as I need to find a method of wrapping text. Found this ticket while searching for a solution.

Nope. A misunderstanding on my part. Docs suggest that text is supposed to wrap around both images and figures when aligned. While latex generates only wrapfigure for figures and not images.

jfbu commented 1 year ago

@annanyearian The problem is still there as the :align: triggers usage of wrapfigure environment which behaves as reported in the topic box. Sadly wrapfigure LaTeX environment is utterly fragile and basically is for manually edited LaTeX sources. We also see here that the caption is set to the width of the figure which is inappropriate for very narrow graphics.