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

nested minipage highjacks the footnote #168

Closed
u-fischer opened this issue Aug 19, 2019 · 14 comments
Closed

nested minipage highjacks the footnote #168

u-fischer opened this issue Aug 19, 2019 · 14 comments

Comments

@u-fischer
Copy link
Member

Reference: https://tex.stackexchange.com/q/504688/2388 (here with todonotes)

A nested minipage grabs footnotes from the outer minipage:

\RequirePackage{latexbug}
\documentclass[12pt]{article}
\begin{document}
\section{nested}
\begin{minipage}{6cm}
some text\footnote{footnote A}

\hspace*{3cm}%
\begin{minipage}{3cm}
 nested
\end{minipage}

some text \footnote{footnote B}
\end{minipage}
\end{document}

image

Log file (required) and possibly PDF file

test-utf8.log

This can be surprising for the user if the inner minipage is actually hidden, e.g. in a tikzpicture:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{minipage}{6cm}
some text\footnote{footnote A}

\hspace*{3cm} \begin{tikzpicture}
 \node[draw=red,text width=3cm,align=left]
 {nested};
 \end{tikzpicture}

some text \footnote{footnote B}
\end{minipage}
\end{document}

image

@PhelypeOleinik
Copy link
Member

PhelypeOleinik commented Aug 19, 2019

Not only the footnote goes to the wrong place, but also the inner minipage inherits the width of the outer one, resulting in an overfull box.

Adding \setbox\@mpfootins\box\voidb@x to the initialisation of the minipage to ensure that the insertion box starts empty (thus, only footnotes added to the current minipage are seen) seems to solve the problem:

\makeatletter
\def\@iiiminipage#1#2[#3]#4{%
  \leavevmode
  \@pboxswfalse
  \setlength\@tempdima{#4}%
  \def\@mpargs{{#1}{#2}[#3]{#4}}%
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \let\@footnotetext\@mpfootnotetext
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \setbox\@mpfootins\box\voidb@x% <=================================
      \@minipagerestore
      \@setminipage}
\makeatother

\RequirePackage{latexbug}
\documentclass[12pt]{article}
\begin{document}
\section{nested}
\begin{minipage}{6cm}
some text\footnote{footnote A}

\hspace*{3cm}%
\begin{minipage}{3cm}
 nested
\end{minipage}

some text \footnote{footnote B}
\end{minipage}
\end{document}

image


The outer minipage starts with \@mpfootins empty, and then the footnote A adds stuff to it. When the inner minipage ends, it checks if \@mpfootins is empty, which is not because of footnote A, then it typesets the footnote at the bottom of the inner minipage. Thus initialising every minipage with an empty \@mpfootins should avoid that one minipage sees the contents of the other.

@u-fischer
Copy link
Member Author

@PhelypeOleinik your code solves my example, but if the inner minipage has also a footnote one looses the first:

% patch as a above ....
\documentclass[12pt]{article}
\begin{document}
\section{nested}
\begin{minipage}{6cm}
some text\footnote{footnote A}

\hspace*{3cm}%
\begin{minipage}{3cm}
 nested\footnote{footnote C}
\end{minipage}

some text \footnote{footnote B}
\end{minipage}
\end{document}

image

@PhelypeOleinik
Copy link
Member

@u-fischer Oh :/

The code for \@mpfootnotetext globally sets \@mpfootins, so my local \setbox\@mpfootins\box\voidb@x won't work. I suspect that the reason for that assignment to be global is that both footnotes A and C are labeled "a", then things get confusing.

Changing \global\setbox\@mpfootins to \setbox\@mpfootins in the definition of \@mpfootnotetext, plus the patch above seem to solve the second problem as well. However, having the global assignment will probably require something more elaborate to detect the nested minipages...

@car222222
Copy link
Contributor

Maybe nested minipages were never supported (at least not with footnotes everywhere!) so this is simply a documentation problem?

But a package extending coverage to “recursive minipages” may be a good idea. Good for making pages that contain reduced copies of themselves, I guess.

@blefloch
Copy link
Member

blefloch commented Aug 19, 2019 via email

@FrankMittelbach
Copy link
Member

This is a documented restriction: LaTeX Book page 106, so it works as designed. That does not mean that we can't change it. However, I'm not sure that it is correct that a tikz picture is internally using a minipage instead of a parbox ... is that supposed to support inner footnotes?

@car222222
Copy link
Contributor

I should have RTFM :-).

@u-fischer
Copy link
Member Author

@FrankMittelbach I don't know why tikz or todonotes (which triggered the issue) use minipage. It could be footnotes, but perhaps simply as environments are easier to handle in begin/end code. I never saw a question about the side-effect before and even if one know in theory that a single mp-footnote counter and insert means that nesting could be problematic it is easy to forget that in practice.

@car222222
Copy link
Contributor

So it would be a good idea to at least issue a warning when a nested minipages us spotted. Not that anyone will notice a warning, of course.

@stale
Copy link

stale bot commented Nov 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 28, 2019
@stale
Copy link

stale bot commented Jan 27, 2020

This issue has been automatically marked as stale because it has not had recent activity.

@stale stale bot added the stale label Jan 27, 2020
FrankMittelbach added a commit that referenced this issue Apr 7, 2020
@FrankMittelbach
Copy link
Member

the above commit is a red herring it should have referenced #186

@stale stale bot removed the stale label Oct 9, 2020
@stale
Copy link

stale bot commented Dec 9, 2020

This issue has been automatically marked as stale because it has not had recent activity.

@stale stale bot added the stale label Dec 9, 2020
FrankMittelbach added a commit that referenced this issue Sep 7, 2022
@FrankMittelbach FrankMittelbach added this to Pool (unscheduled issues) in upcoming LaTeX2e releases via automation Sep 7, 2022
@FrankMittelbach FrankMittelbach added this to the Release 2022 Fall milestone Sep 7, 2022
@stale stale bot removed the stale label Sep 7, 2022
@FrankMittelbach FrankMittelbach moved this from Pool (unscheduled issues) to Done in dev in upcoming LaTeX2e releases Sep 7, 2022
@FrankMittelbach
Copy link
Member

I have now added a check and a warning if minipages are nested.

FrankMittelbach added a commit that referenced this issue Sep 16, 2022
* checking code for #168

* add new entry

* only warn if the outer minipage actually contains footnotes
@FrankMittelbach FrankMittelbach added the fixed in dev Fixed in development branch, not in stable release label Sep 16, 2022
upcoming LaTeX2e releases automation moved this from Done in dev to Done Oct 31, 2022
@FrankMittelbach FrankMittelbach removed the fixed in dev Fixed in development branch, not in stable release label Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants