0

Context

I'm creating a LaTeX class for popular mathematic articles in which images play a central role. As a result, the following requirements have been set for:

  • the online versions of articles (standalone PDF ones),
  • the paper versions of the articles (volumes of collections made of selections of online articles published during the year).

Online versions of articles

  • Composition is done on an endless page (thanks to the standalone class) in order to :
    • show the figures where they are discussed: it's not a good idea for them to be far away, as this could confuse the target readers, who may be teenagers or even children,
    • avoid vertical blanks.
  • Theorems and similar are presented in boxes (based on tcolorbox). These can contain figures which, because of the endless page, can both be floats and be in TeX boxes without generating the error “Float(s) lost”.

Here is an example of such theorems and the like containing figures:

enter image description here

Paper versions of the articles

  • Composition is of course not on an endless page (e.g. book class used), and figures are therefore necessarily floating.
  • Theorems and the like can of course not be presented in boxes, as this is incompatible with the floating status of the figures they may contain (“Float(s) lost” error). To compensate for this, it is planned to delimit these theorems and the like, hence not by boxes, but by objects that visually mark only their beginnings and ends, visually as close as possible to those of the boxes in the online versions of the articles).

This is the difficult part and what I've tried so far is to put before (resp. after) these theorems contents the same kind of boxes as for the online version (based on tcolorbox), but empty and without bottom (resp. top) rules; and, by trial and error, I moved the content thanks to \vspace*.

This method, everything but robust, can be found in the following example where:

  • the frame color and the font, not the same as above, don't matter,
  • the \pagebreak[2] for the page breaks to be encouraged between the theorems and hence, finger crossed, discouraged between the top/bottom box and the theorem's content.
\documentclass{book}
\usepackage[textwidth=12cm]{geometry}
\usepackage{tcolorbox}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{etoolbox}

\newcommand{\dummytext}{%
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua.
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua.
}

\tcbuselibrary{skins,hooks}

\newcounter{theorem}

\ExplSyntaxOn
\NewTColorBox[use~ counter=theorem]{theorem_start}{ O{} m }{%
  , bottomrule=0pt
  , outer~ arc=1.5mm
  , standard~ jigsaw
  , sharp~ corners=south
  , fonttitle=\bfseries
  , opacityback=0
  , IfEmptyF={#2}{after~ title={\c_space_tl(#2)}}
  , after~ title~ pre={\c_space_tl \thetcbcounter}
  , #1
}
\NewTColorBox{theorem_end}{  }{%
  , toprule=0pt
  , outer~ arc=1.5mm
  , enlarge~ top~ initially~ by=-7mm
  , opacityback=0
  , standard~ jigsaw
  , sharp~ corners=north
}

\NewDocumentEnvironment{theorem}{O{}m}{
  \pagebreak[2]
  \begin{theorem_start}[title=Theorem,#1]{#2}
  \end{theorem_start}
  \setlength\leftmargini{5.5mm}
  \vspace*{-9mm}
  \begin{quote}
    \itshape
}{
  \end{quote}
  \begin{theorem_end}
  \end{theorem_end}
}

\NewDocumentEnvironment{lemma}{O{}m}{
  \pagebreak[2]
  \begin{theorem_start}[
    , title=Lemma
    , colback=white
    , coltitle=black
    % , interior~ titled~ engine=empty
    , titlerule=0mm
    , attach~ title~ to~ upper={.\\}
    % , title~ engine=empty
    , #1
    ]{#2}
  \end{theorem_start}
  \setlength\leftmargini{5.5mm}
  \vspace*{-11mm}
  \begin{quote}
}{
  \end{quote}
  \begin{theorem_end}
  \end{theorem_end}
}

\NewDocumentEnvironment{axiom}{O{}m}{
  \pagebreak[2]
  \begin{theorem_start}[
  , detach~ title
  , attach~ title~ to~ upper={.\c_space_tl}
  , coltitle=black
  , title=Axiom
  , #1
  ]{#2}
  \tl_gset:Ne \g_tmpa_tl {\tcbtitletext\csuse{tcb@insert@after@title}.}
  \end{theorem_start}
  \setlength\leftmargini{5.5mm}
  \vspace*{-11.5mm}
  \begin{quote}
    \hspace*{
      \widthof{\bfseries\g_tmpa_tl}
    }
}{
  \end{quote}
  \begin{theorem_end}
  \end{theorem_end}
}
\ExplSyntaxOff

\begin{document}
\begin{theorem}{}
  \dummytext{}
\end{theorem}
\begin{lemma}{}
  \dummytext{}
\end{lemma}
\begin{axiom}{}
  \dummytext{}
\end{axiom}
\end{document}

(On the following image, the very thin horizontal rules don't matter.)

enter image description here

Question

Do you see a better, more robust, method than the previous one?

6
  • If the images belong with the theorems, it is IMHO a non-starter to have the images float and the theorems not. Either don't use floats period. Or use floating tcolorboxes which include both the theorem and the (non-floating) picture. I'm betting the second will be problematic, so I'd try the first. Just forget floats. You will get sub-optimal page-breaking in some cases, so deal with these cases manually. If it is actually OK for the theorems and images to get separated - just not ideal - that's a different matter.
    – cfr
    Commented May 9 at 1:42
  • ... figures are therefore necessarily floating. Yes. So don't use figures. The only reason to use a figure is because you want the content to float. If you don't want it to float, the solution is simple.
    – cfr
    Commented May 9 at 1:44
  • Note that you cannot have an endless page in TeX. Nor can you have one several miles long. There is a hard limit set by the maximum dimension TeX can handle. If your standalone output exceeds that limit, you will have to break the page or shorten the content. Note also that there are differences between the standalone package and the standard classes which might or might not matter to you.
    – cfr
    Commented May 9 at 1:49
  • @cfr I tried to deal without floats but, since the images can be very numerous, it was a nightmare so the solution is not that simple. Theorems and images are not separated with the “endless pages”, precisely to make the (online) articles easier to read for young people (who are supposed to read them on their smartphone); for the paper versions of the articles, it is actually OK - but as you said, just not ideal - for the theorems and images to get separated. Commented May 9 at 17:05
  • @cfr About “endless” pages, I should have said that I'm aware there is a hard limit set by the maximum dimension TeX can handle, and that's unfortunate this limitation cannot be avoided nowadays. For the articles which exceed the limit, we will either split them into two parts or insert a ling to the paper version of them. Commented May 9 at 17:09

0

You must log in to answer this question.

Browse other questions tagged .