2

Let's assume that in a huge book of over 500 pages you often typeset long Notes (or other theorem-like environments) with Figures. You want that your Figures possibly stay near the declared places and that if a Figure floats at all, it floats within the Note logically containing it, i.e., between “Note ⟨note number⟩ ⟨(possibly, Note title in parens)⟩” and ■ terminating the Note. You also want that the floating and non-floating figures together maintain the same total order in the output as in the input. We could either nail the last figure of a Note with [H] and put a \FloatBarrier right before it (which makes the figure non-floating) or have the last figure floating but a halmos way too low:

\documentclass{svmono}% V5.10 from https://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs .  For testing purposes, I hope, book would do as well.
\usepackage[latin,USenglish]{babel}%%% solely because lipsum is Latin
\usepackage{amssymb}
% \usepackage{float,afterpage}% also see \flushhere from http://tex.stackexchange.com/a/246315
\usepackage{placeins}
\usepackage{lipsum}
\makeatletter
% typesetting halmos:
\newlength\lastSkipOfEndCenter
\newcommand*{\halmosEndingNonProofAfterCenter}{\setlength\lastSkipOfEndCenter{\lastskip}\removelastskip\nopagebreak\par\nopagebreak\vspace{\dimexpr-\baselineskip-\parskip\relax}\nopagebreak{\unskip\nobreak\hfil\penalty50\hskip1em\null\nobreak\hfil\(\blacksquare\)\parfillskip=\z@\finalhyphendemerits=0\endgraf}\vskip\lastSkipOfEndCenter}
\makeatother
\begin{document}
\chapter{Chapter}
\newcommand{\figureheight}{19ex}% With ≤17ex, the halmos appears way too low below the figure. With 18 ex, the halmos appears of the next page.  With ≥19 ex, Fig. 3 goes to the next page and the halmos appears way too low.
\lipsum[1]
\begin{figure}[htbp]\centering
  \rule{10em}{\figureheight}
  \caption{1}
\end{figure}
\lipsum[1]
\FloatBarrier
\begin{note}% Note 1
  \lipsum[1]

\begin{figure}[htbp]\centering \rule{10em}{\figureheight} \caption{2} \end{figure}

\lipsum[1]

%\FloatBarrier \begin{figure}[htbp]\centering%%% We don't wish to simply use [H] for this figure and [h] elsewhere in the chapter because then the Figures might hypohetically come out in the wrong order. Otherwise, and with \FloatBarrier right before, [H] seems to do the job. Using [H] everywhere in the chapter is not an option because outside this environment, LaTeX does a good automatic job of placing the environment, and a manual placement everywhere would have to be reviewed too often. \rule{10em}{\figureheight} \caption{3} \end{figure}% \FloatBarrier \halmosEndingNonProofAfterCenter \end{note} \lipsum[1]

\begin{figure}[htbp]\centering \rule{10em}{\figureheight} \caption{4} \end{figure}

\lipsum[1] \end{document}

Either of the two solutions probably preserves the order (though, as Skillmons explains in https://tex.stackexchange.com/a/654613, \FloatBarrier is not a panacea); feel free to correct me if I'm wrong. Is there any way to have the last Figure of the Note (in our example, Figure 3) floating (in our example, only above ■) such that the halmos is correctly placed on the last line of the Note, whether it is text or caption (in our example, of Figure 3)? Is there further any way to avoid the page break right before the halmos (to test, set \figureheight to 18ex)?

  • 2
    basic answer is do not use a float. The whole design of floats is they are not part of the document flow and are referenced indirectly. The mechanism used to re-insert a float has no information about the text at that point (and can not be extended to get that information in any reasonable way. TeX boxes can not be deconstructed. – David Carlisle Aug 20 '22 at 19:44
  • % typesetting halmos: why not the ams \qedhere and related commands? – David Carlisle Aug 20 '22 at 19:46
  • you should style figures so the reader knows thy are inserts so it doesn't make sense to ask if the insert is "in" the note. if a float is inserted at the top of a page, it is not "in" the paragraph or list that broke over the page, it is simply a different part of the document. – David Carlisle Aug 20 '22 at 19:51
  • @DavidCarlisle In a non-minimal example, I have two ways to show that a theorem-like block terminates: "q.e.d." for proofs and “■” for non-proofs. Also, I sometimes need to place either of the two on the last line of various math formulas (including multi-line block formulas), on the last line of {center}ed contents, and so on. Therefore, a single command \qedhere wouldn't suit anyway. –  Aug 20 '22 at 19:52
  • amsmath has well tested support for doing the mark at end of proofs including multiline math dsplays and manual control where needed, I wouldn't be too quick to abandon that "Is there further any way to avoid the page break right before the halmos " for example... – David Carlisle Aug 20 '22 at 19:55
  • @DavidCarlisle Considering styling inserts: You probably think of horizontal rules, don't you? That actually makes sense for floating objects, except they take a tiny bit of extra space and interrupt the reading flow when a figure is lucky to be right at the ideal place we wish it to be content-wise. –  Aug 20 '22 at 19:55
  • Considering amsmath's \qedhere: I believe you. Still, we wish to have two different versions of \qedhere: one for q.e.d., the other for ■. Btw., I probably cannot use amsthm (it clashed with svmono the last time I tested it). –  Aug 20 '22 at 19:58
  • not rules, just well placed captions or well chosen vertical space. If you are reading a paragraph on page 2 and it carries on to page 3 you need to instantly skip over the page head and any top floats and pick up the next word. So if reading a note I would skip over a float so your effort to force a float to be "in" the note seems wasted – David Carlisle Aug 20 '22 at 19:59
  • typsetting math in latex without using amsmath would be "unusual" – David Carlisle Aug 20 '22 at 20:00
  • The publisher complained when they saw a paragraph that spanned two pages and was broken by a figure at the top (in your example, at the top of page 3). So now we never have such a situation you described, and the reader is always done reading a paragraph on one page before he/she sees a Figure at the top of the next page. –  Aug 20 '22 at 20:07
  • As for maths, we do use mathtools (i.e., internally, amsmath), but not amsthm. –  Aug 20 '22 at 20:08
  • 1
    If I remember correctly, at AMS we treated a "figure" (probably without a caption) as an unnumbered equation, packing it in a minipage, following the display with \par\nobreak and applying a negative \vspace to place the "halmos". Definitely required manual intervention. – barbara beeton Aug 20 '22 at 20:15
  • @barbarabeeton I guess, then the halmos sticks to the figure, and you mean something like \FloatBarrier\begin{figure}[H]\centering\begin{minipage}{\linewidth}\[…\]\par\nobreak\vspace{-\lastkip}■\end{minipage}\end{figure} ? –  Aug 20 '22 at 20:23
  • @DavidCarlisle The way I read your very first comment, LaTeX is simply missing the concept of “a figure that logically belongs to the text and that, as an exception, can be moved elsewhere if the document looks terrible otherwise”. I use the floats to typeset such figures, although the floats are not meant to be used for the purpose. –  Aug 20 '22 at 20:28
  • yes I read amsthm as amsmath so ignore my comment there. As for not allowing top floats that is fine as a design but just backs up my first comment, do not use the latex float mechansm. – David Carlisle Aug 20 '22 at 20:29
  • @DavidCarlisle With hundreds of pages, we get lots of typesetting issues, so it's difficult to avoid using the floats completely (without them, its sometimes worse). However, I got your message, thank you! –  Aug 20 '22 at 20:32
  • well that is more of less what h is but if it needs to float it floats and as tex boxes are opaque you can not constrain it based on text in the main document flow without rewriting latex or (like luatex) rewriting the engine or both – David Carlisle Aug 20 '22 at 20:33
  • @DavidCarlisle Got it. Alas, I'm not in (Lua)TeX enough to suggest a placement “between H and h” in which the main text is being taken into consideration while placing a float or a halmos after the float or unindenting the first line of a para following a float :-). –  Aug 20 '22 at 20:35
  • @DavidCarlisle Maybe, when I'm acting only as a typesetter for someone else's text in Computer Science, I'd better switch to MS Word, Libreoffice or HTML+MathML next time? I don't need to understand the text thoroughly, while understanding is inherent to the folks (La)TeX has been made for. In MS Word, Libreoffice or HTML+MathML, the figures would always be stuck where the real author wants them, and I'd always be able to blame these programs for lots of vertical white space. –  Aug 20 '22 at 20:45
  • an automatic algorithm only gets you so far, in the latex companion books (which have lots of floats) and thousands of pages, Frank reviewed every float and every two page spread adjusting by hand if needed. if you look at the end notes in the second edition there are some figures on the amount of manual correction, it was many week's work. – David Carlisle Aug 20 '22 at 20:53
  • @DavidCarlisle Many weeks. Wow. –  Aug 20 '22 at 21:03
  • one book with a print run of 15 years and counting..., it's worth getting it right... – David Carlisle Aug 20 '22 at 21:06
  • @DavidCarlisle For YOUR book, yes. Definitely. –  Aug 20 '22 at 21:36
  • @barbarabeeton I made the problem explicit in https://tex.stackexchange.com/questions/654683/how-to-put-a-halmos-into-a-caption-of-a-h-placed-figure ; please feel free to present your solution there if you wish. Thanks in advance! –  Aug 20 '22 at 21:38
  • 1
    The solution I remember did not -- and could not -- use a float. The minipage with the content was embedded in a display, something like \[ \begin{minipage} ... \end{minipage} \]\par\nobreak \vspace{-1.2\baselineskip}\leavevmode \hfill \halmos{\parfillskip=0pt \par} \par <text>. I'll take a look at your explicit example, but the important point is, not a float. – barbara beeton Aug 20 '22 at 22:11
  • 1
    I've taken a look at @DavidCarlisle's answer to your other question, and think that is likely more appropriate to your situation because keeping the floats and placing the halmos in the caption is more likely to maintain the desired order than what I suggested. – barbara beeton Aug 20 '22 at 22:54
  • @barbarabeeton Thank you! –  Aug 20 '22 at 22:55

1 Answers1

3

Here your figures are logically part of your note and you don't want them to float out so I think the cleanest solution is likely to be to use [H] non-floating figures in the note and use \Floatbarrier in the definition of \begin{note} so figures are always set in order.

The worst "bad" thing that will happen is that a note is forced to start a new page if pending floats are flushed, and as there are no floats within the note you know whether the final visual line comes from normal text or a caption, so can place the halmos qed appropriately.

David Carlisle
  • 757,742
  • It turned out that \begin{note}[Note title]\FloatBarrier incurs a line break right after “Note title”, and \FloatBarrier\begin{note} incurs extra vertical space right before “Note 1”. As for using \FloatBarrier in the definition of \begin{note}, to do this we'd have to change the definition of \spn@wtheorem in svmono.cls somehow. –  Aug 22 '22 at 16:03
  • 1
    @GeekestGeek \begin{note}[Note title]\FloatBarrier would be wrong but \FloatBarrier\begin{note} id have thought work or less agressive \makeatletter\def\foo{\ifx\@deferlist\@empty\else\clearpage\fi} ... \foo\begin{note} – David Carlisle Aug 22 '22 at 16:10
  • Indeed, your \foo does not produce extra vertical space. Thanks a lot!!! –  Aug 22 '22 at 17:01