Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide commands with the flafter functionality #1354

Open
user227621 opened this issue May 24, 2024 · 1 comment
Open

Provide commands with the flafter functionality #1354

user227621 opened this issue May 24, 2024 · 1 comment
Labels
category base (latex) enhancement long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually

Comments

@user227621
Copy link
Contributor

user227621 commented May 24, 2024

Brief outline of the enhancement

LaTeX provides the flafter package, which prevents floats from being placed before their call-out. As this is implemented as a package, this feature cannot be activated for just parts of a document, as it cannot be deactivated or reactivated later.

As far as I understand, the flafter package only changes a single line in \@addtocurcol (from \@addtotoporbot to \@addtobot):

\def \@addtocurcol {%
   \@insertfalse
   \@setfloattypecounts
   \ifnum \@fpstype=8
   \else
     \ifnum \@fpstype=24
     \else
       \@flsettextmin
       \advance \@textmin \@textfloatsheight
       \@reqcolroom \@pageht
       \ifdim \@textmin>\@reqcolroom
         \@reqcolroom \@textmin
       \fi
       \advance \@reqcolroom \ht\@currbox
       \ifdim \@colroom>\@reqcolroom
         \@flsetnum \@colnum
         \ifnum \@colnum>\z@
           \@bitor\@currtype\@deferlist
          \@testwrongwidth\@currbox
           \if@test
           \else
             \@bitor\@currtype\@botlist
             \if@test
               \@addtobot
             \else
               \ifodd \count\@currbox
                 \advance \@reqcolroom \intextsep
                 \ifdim \@colroom>\@reqcolroom
                   \global \advance \@colnum \m@ne
                   \global \advance \@textfloatsheight \ht\@currbox
                   \global \advance \@textfloatsheight 2\intextsep
                   \@cons \@midlist \@currbox
                   \if@nobreak
                     \nobreak
                     \@nobreakfalse
                     \everypar{}%
                   \else
                     \addpenalty \interlinepenalty
                   \fi
                   \vskip \intextsep
                   \box\@currbox
                   \penalty\interlinepenalty
                   \vskip\intextsep
                   \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
                   \outputpenalty \z@
                   \@inserttrue
                 \fi
               \fi
               \if@insert
               \else
                 \@addtotoporbot % <--------------------------------------------
               \fi
             \fi
           \fi
         \fi
       \fi
     \fi
   \fi
   \if@insert
   \else
     \@resethfps
     \@cons\@deferlist\@currbox
   \fi
}%

Would it be possible to provide two commands that switch on and switch off the restriction to place floats after thier call-out?

You could e. g. change the definition of \@addtocurcol like this

...
               \else
                 \@addtocurcol@action % <--------------------------------------------
               \fi
...

and provide two commands that execute \let\@addtocurcol@action\@addtotoporbot and \let\@addtocurcol@action\@addtobot. (The flafter package could of course still be provided, it would then only have to execute the latter command.)

Minimal example showing the desired new behaviour

\documentclass{article}

\makeatletter

\def \@addtocurcol {%
   \@insertfalse
   \@setfloattypecounts
   \ifnum \@fpstype=8
   \else
     \ifnum \@fpstype=24
     \else
       \@flsettextmin
       \advance \@textmin \@textfloatsheight
       \@reqcolroom \@pageht
       \ifdim \@textmin>\@reqcolroom
         \@reqcolroom \@textmin
       \fi
       \advance \@reqcolroom \ht\@currbox
       \ifdim \@colroom>\@reqcolroom
         \@flsetnum \@colnum
         \ifnum \@colnum>\z@
           \@bitor\@currtype\@deferlist
          \@testwrongwidth\@currbox
           \if@test
           \else
             \@bitor\@currtype\@botlist
             \if@test
               \@addtobot
             \else
               \ifodd \count\@currbox
                 \advance \@reqcolroom \intextsep
                 \ifdim \@colroom>\@reqcolroom
                   \global \advance \@colnum \m@ne
                   \global \advance \@textfloatsheight \ht\@currbox
                   \global \advance \@textfloatsheight 2\intextsep
                   \@cons \@midlist \@currbox
                   \if@nobreak
                     \nobreak
                     \@nobreakfalse
                     \everypar{}%
                   \else
                     \addpenalty \interlinepenalty
                   \fi
                   \vskip \intextsep
                   \box\@currbox
                   \penalty\interlinepenalty
                   \vskip\intextsep
                   \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi
                   \outputpenalty \z@
                   \@inserttrue
                 \fi
               \fi
               \if@insert
               \else
                 \@addtocurcol@action % <---------------------------------------
               \fi
             \fi
           \fi
         \fi
       \fi
     \fi
   \fi
   \if@insert
   \else
     \@resethfps
     \@cons\@deferlist\@currbox
   \fi
}%

\let\@addtocurcol@action\@addtotoporbot

\newcommand\off{\let\@addtocurcol@action\@addtotoporbot}
\newcommand\on{\let\@addtocurcol@action\@addtobot}
% use more elaborate command names in a real implementation, of course

\makeatother

\begin{document}

\on % prevent floats from being placed before their call-out

Text.

\begin{table}
\caption{...}
\end{table}

\newpage

\off % lift the restriction

Text.

\begin{table}
\caption{...}
\end{table}

\end{document}
@FrankMittelbach
Copy link
Member

This is a sensible extension but it will have to wait until we start putting hooks and sockets into the output routine and adjust it to fully support tagging.

@josephwright josephwright added the long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category base (latex) enhancement long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually
Projects
Status: Pool (unscheduled issues)
Development

No branches or pull requests

3 participants