6

I would like to use an auxiliary file to read and write some information.


Context

In this case, I am using this auxiliary file to record the widths used in the footnote formatting. Indeed, I want my footnote numbers to be right-aligned, like this :

enter image description here

So I need to know in advance (using information from previous compilations) the width of the widest footnote number (\@widthFootnoteNum for a "normal" footnote, \@mpwidthFootnoteNum for a footnote in a minipage).

If I only take into account "normal" footnotes, I have no particular problem. The value of \@widthFootnoteNum is written in an auxiliary file (called \jobname.foot) at the end of the compilation and read at the beginning of the next compilation.

However, if I do the same thing with footnotes in a minipage environment, things get complicated. Several values are written to the auxiliary file and I have to read this file to find the correct widths and write to it to give the correct widths for the next compilation in parallel.

My tests are not conclusive... I manage to write all the necessary information, but I can't read it afterwards.


MWE

Consider the following MWE:
A simple file containing 20 "normal" footnotes and two minipage environments containing 2 and 7 notes.

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Numbers={Proportional}]{LibertinusSerif}
\usepackage{etoolbox}


\makeatletter
\newcommand*\@symbolesnum[1]{% new numerotation for minipage footnote
    \ifcase#1\unskip \or \unskip * \or \unskip † \or \unskip ‡ \or \unskip ** \or \unskip †† \or \unskip ‡‡ \or \unskip *** \or \unskip ††† \or \unskip ‡‡‡ \or \unskip **** \or \unskip †††† \or \unskip ‡‡‡‡ \or \unskip ***** \or \unskip ††††† \or \unskip ‡‡‡‡‡ \else\@ctrerr \fi%
}

\newlength{\@widthCurrentFootnoteNumTemp} % width of the current footer number
\newlength{\@maxWidthFootnoteNumTemp} % maximum footnote number width
\newlength{\@widthFootnoteNum} % width set after reading the auxiliary file 

\AtBeginDocument{% Creating and opening the auxiliary file
    \newwrite\auxFootnoteOutput% 
    \immediate\openout\auxFootnoteOutput=\jobname.foot%
    \setlength{\@maxWidthFootnoteNumTemp}{0pt}%
}

\AtEndDocument{%
    \immediate\write\auxFootnoteOutput{\the\@maxWidthFootnoteNumTemp}% Writing the value of \@widthFootnoteNum
    \immediate\closeout\auxFootnoteOutput% Closing the auxiliary file
}

% For each footnote, the width of the footnote number is measured by \@widthCurrentFootnoteNumTemp. 
% This width is compared to \@maxWidthFootnoteNumTemp. 
% If \@widthCurrentFootnoteNumTemp is greater than \@maxWidthFootnoteNumTemp then \@maxWidthFootnoteNumTemp will take the value of \@widthCurrentFootnoteNumTemp. 
% Thus, the width \@maxWidthFootnoteNumTemp corresponds to the width of the widest footnote number.

\renewcommand\@makefntext[1]{% 
    \settowidth{\@widthCurrentFootnoteNumTemp}{{\footnotesize\liningnums{\@thefnmark}}}%
    \ifdim \@maxWidthFootnoteNumTemp < \@widthCurrentFootnoteNumTemp%
        \global\setlength{\@maxWidthFootnoteNumTemp}{\@widthCurrentFootnoteNumTemp}%
    \fi%
    \makebox[\@widthFootnoteNum][r]{\liningnums{\@thefnmark}}.\enspace% right aligned footnote number using "\@widthFootnoteNum"
    #1%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Idem for minipage :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newlength{\@mpwidthCurrentFootnoteNumTemp}
\newlength{\@mpmaxWidthFootnoteNumTemp}
\newlength{\@mpwidthFootnoteNum}

\def\thempfootnote{\@symbolesnum{\c@mpfootnote}}

\AtBeginEnvironment{minipage}{%
    \setlength{\@mpmaxWidthFootnoteNumTemp}{0pt}%
    %
    \renewcommand\@makefntext[1]{%
        \settowidth{\@mpwidthCurrentFootnoteNumTemp}{{\footnotesize\liningnums{\@thefnmark}}}%
        \ifdim \@mpmaxWidthFootnoteNumTemp < \@mpwidthCurrentFootnoteNumTemp%
            \global\setlength{\@mpmaxWidthFootnoteNumTemp}{\@mpwidthCurrentFootnoteNumTemp}%
        \fi%
        \makebox[\@mpwidthFootnoteNum][r]{\liningnums{\@thefnmark}}\enspace% right aligned footnote number using the value of "\@mpwidthFootnoteNum" for this particular minipage
        #1%
    }
}

\AtEndEnvironment{minipage}{% write the maximum width for the current mini-page
    \immediate\write\auxFootnoteOutput{\the\@mpmaxWidthFootnoteNumTemp}
}
\makeatother

\begin{document}
Lorem ipsum dolor sit amet\footnote{A footnote.}, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris\footnote{A footnote.}. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit\footnote{A footnote.}. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas\footnote{A footnote.}. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed\footnote{A footnote.}. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.

Sed nec augue pellentesque, commodo diam quis, vehicula libero\footnote{A footnote.}. In hac habitasse platea dictumst. Phasellus tincidunt ligula vitae arcu tempor, eu facilisis augue fringilla. Curabitur id pulvinar ipsum, et gravida nisl. Aenean eget faucibus dolor, vel fermentum metus\footnote{A footnote.}. Quisque risus purus, porta vel eleifend nec, tempus sit amet diam. Sed sit amet commodo odio. Curabitur in tempor lorem. Sed venenatis malesuada odio, ac scelerisque nisi finibus ac. Aliquam cursus aliquet eleifend.

Duis in nisi vitae augue lacinia sodales sed vel libero. Duis vehicula, justo commodo ultrices blandit, purus sem ultrices velit, in imperdiet ligula sem vel sem\footnote{A footnote.}. Nam diam turpis, pulvinar ac lorem at, sagittis cursus nibh. Sed id gravida enim, id rutrum felis. Nam aliquet leo vel venenatis volutpat. Integer laoreet tincidunt mi, in faucibus nunc. Fusce porta et lorem id consectetur. Praesent ac vehicula metus, quis hendrerit tellus\footnote{A footnote.}. Maecenas consequat eleifend ante, non vehicula risus aliquet vitae. Duis et velit elit. Mauris nec lorem vel lorem rhoncus congue vitae in arcu.

Lorem ipsum dolor sit amet\footnote{A footnote.}, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris\footnote{A footnote.}. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit\footnote{A footnote.}. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas\footnote{A footnote.}. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed\footnote{A footnote.}. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.

Sed nec augue pellentesque, commodo diam quis, vehicula libero\footnote{A footnote.}. In hac habitasse platea dictumst. Phasellus tincidunt ligula vitae arcu tempor, eu facilisis augue fringilla. Curabitur id pulvinar ipsum, et gravida nisl. Aenean eget faucibus dolor, vel fermentum metus\footnote{A footnote.}. Quisque risus purus, porta vel eleifend nec, tempus sit amet diam. Sed sit amet commodo odio. Curabitur in tempor lorem. Sed venenatis malesuada odio, ac scelerisque nisi finibus ac. Aliquam cursus aliquet eleifend.

Duis in nisi vitae augue lacinia sodales sed vel libero. Duis vehicula, justo commodo ultrices blandit, purus sem ultrices velit, in imperdiet ligula sem vel sem\footnote{A footnote.}. Nam diam turpis, pulvinar ac lorem at, sagittis cursus nibh. Sed id gravida enim, id rutrum felis. Nam aliquet leo vel venenatis volutpat. Integer laoreet tincidunt mi, in faucibus nunc. Fusce porta et lorem id consectetur. Praesent ac vehicula metus, quis hendrerit tellus\footnote{A footnote.}. Maecenas consequat eleifend ante, non vehicula risus aliquet vitae. Duis et velit elit. Mauris nec lorem vel lorem rhoncus congue vitae in arcu.

\begin{minipage}{\textwidth}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus\footnote{A footnote.}. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.
\end{minipage}

\begin{minipage}{\textwidth}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa\footnote{A footnote.}. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus\footnote{A footnote.}. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus\footnote{A footnote.}. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet\footnote{A footnote.}. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed\footnote{A footnote.}. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a\footnote{A footnote.}.
\end{minipage}
\end{document}

I get the following auxiliary file:

6.704pt
11.40799pt
7.752pt

The first value is the value of \@mpwidthFootnoteNum for the first minipage environment.
The second value is the value of \@mpwidthFootnoteNum for the second minipage environment.
The third value corresponds to the value of \@widthFootnoteNum for the "normal" footnote.

So I manage to save all the information needed for the next compilation in an auxiliary file.


The issue

The problem is that I can't use these different values when compiling, because the auxiliary file is successively read and written during the same compilation. So the file is overwritten with each new write.

How can we get around this?


What I tried

I thought of storing all the values at the beginning of the compilation in a kind of numbered list from which one could take out the last value to assign it to \@widthFootnoteNum and take out the other values to assign them to the different \@mpwidthFootnoteNum of the different minpage. The goal is to have to read the auxiliary file only once. But I don't know how to do it.

I tried to use the arrayjob package by putting the auxiliary file in an array, but without success.

I also tried to use two auxiliary files. A file A would be used to write the various @widthFootnoteNum and @mpwidthFootnoteNum during compilation. At the start of the next compilation, file A would be copied to a file B, which would be read in at the time of compilation and would give the values of the widthFootnoteNum and mpwidthFootnoteNum calculated at the time of the next compilation. Again, I haven't managed to do this, as I can't seem to copy file A into file B.

Finally, I tried to store the different values that @mpwidthFootnoteNum should take in a syntax ifcase #1 ... where #1 represents the number of the minipage environment. For each minipage environment, \@mpwidthFootnoteNum thus takes a different value.

Here is the preamble:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Numbers={Proportional}]{LibertinusSerif}
\usepackage{etoolbox}

\makeatletter
\begingroup
\catcode`<=1 \catcode`>=2
\catcode`{=12 \catcode`}=12 \catcode`#=12
\gdef\curlyBracketL<{>
\gdef\curlyBracketR<}>
\gdef\hashtag<#>
\endgroup

\newcommand*\@symbolesnum[1]{% new numerotation for minipage footnote
    \ifcase#1\unskip \or \unskip * \or \unskip † \or \unskip ‡ \or \unskip ** \or \unskip †† \or \unskip ‡‡ \or \unskip *** \or \unskip ††† \or \unskip ‡‡‡ \or \unskip **** \or \unskip †††† \or \unskip ‡‡‡‡ \or \unskip ***** \or \unskip ††††† \or \unskip ‡‡‡‡‡ \else\@ctrerr \fi%
}

\newlength{\@widthCurrentFootnoteNumTemp} % width of the current footer number
\newlength{\@maxWidthFootnoteNumTemp} % maximum footnote number width
\newlength{\@widthFootnoteNum} % width set after reading the auxiliary file 

\AtBeginDocument{% Creating and opening the auxiliary file
    \IfFileExists{\jobname.foot}{\input{\jobname.foot}}{}%
    \newwrite\auxFootnoteOutput% 
    \immediate\openout\auxFootnoteOutput=\jobname.foot%
    \immediate\write\auxFootnoteOutput{\unexpanded{\makeatletter}}%
    \immediate\write\auxFootnoteOutput{%
        \unexpanded{\newcommand*{\@mpwidthFootnoteNum}[1]} \curlyBracketL \unexpanded{\ifcase} \hashtag 1 \unexpanded{\unskip}%
    }
    \setlength{\@maxWidthFootnoteNumTemp}{0pt}%
}

\AtEndDocument{%
    \immediate\write\auxFootnoteOutput{%
        \unexpanded{\else 1em \fi} \curlyBracketR%
    }%
    \immediate\write\auxFootnoteOutput{\unexpanded{\setlength} { \unexpanded{\@widthFootnoteNum} }{\the\@maxWidthFootnoteNumTemp}}% Writing the value of \@widthFootnoteNum
    \immediate\write\auxFootnoteOutput{\unexpanded{\makeatother}}
    \immediate\closeout\auxFootnoteOutput% Closing the auxiliary file
}

% For each footnote, the width of the footnote number is measured by \@widthCurrentFootnoteNumTemp. 
% This width is compared to \@maxWidthFootnoteNumTemp. 
% If \@widthCurrentFootnoteNumTemp is greater than \@maxWidthFootnoteNumTemp then \@maxWidthFootnoteNumTemp will take the value of \@widthCurrentFootnoteNumTemp. 
% Thus, the width \@maxWidthFootnoteNumTemp corresponds to the width of the widest footnote number.

\renewcommand\@makefntext[1]{% 
    \settowidth{\@widthCurrentFootnoteNumTemp}{{\footnotesize\liningnums{\@thefnmark}}}%
    \ifdim \@maxWidthFootnoteNumTemp < \@widthCurrentFootnoteNumTemp%
        \global\setlength{\@maxWidthFootnoteNumTemp}{\@widthCurrentFootnoteNumTemp}%
    \fi%
    \makebox[\@widthFootnoteNum][r]{\liningnums{\@thefnmark}}.\enspace% right aligned footnote number using "\@widthFootnoteNum"
    #1%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Idem for minipage :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{mpNum}
\setcounter{mpNum}{0}

\newlength{\@mpwidthCurrentFootnoteNumTemp}
\newlength{\@mpmaxWidthFootnoteNumTemp}

\def\thempfootnote{\@symbolesnum{\c@mpfootnote}}

\AtBeginEnvironment{minipage}{%
    \stepcounter{mpNum}%
    \setlength{\@mpmaxWidthFootnoteNumTemp}{0pt}%
    %
    \renewcommand\@makefntext[1]{%
        \settowidth{\@mpwidthCurrentFootnoteNumTemp}{{\footnotesize\liningnums{\@thefnmark}}}%
        \ifdim \@mpmaxWidthFootnoteNumTemp < \@mpwidthCurrentFootnoteNumTemp%
            \global\setlength{\@mpmaxWidthFootnoteNumTemp}{\@mpwidthCurrentFootnoteNumTemp}%
        \fi%
        \makebox[\@mpwidthFootnoteNum{\thempNum}][r]{\liningnums{\@thefnmark}}\enspace% doesn't work. \@mpwidthFootnoteNum is defined in the auxiliary file
        #1%
    }
}

\AtEndEnvironment{minipage}{% write the maximum width for the current mini-page
    \immediate\write\auxFootnoteOutput{%
        \unexpanded{\or \unskip} \the\@mpmaxWidthFootnoteNumTemp%
    }
}
\makeatother

This gives the following auxiliary file:

\makeatletter 
\newcommand *{\@mpwidthFootnoteNum }[1] {\ifcase  #1 \unskip 
\or \unskip  6.704pt
\or \unskip  11.40799pt
\else 1em \fi  }
\setlength  { \@widthFootnoteNum  }{7.752pt}
\makeatother

This seems correct, but when compiling, I have several errors.


Alternative

I tried using the eqparbox package as advised by Werner and while it works fine for "normal" footnotes, the problem persists with footnotes in a minipage environment, as you can see from the following images:

Problem minipage 1 with eqparbox Problem minipage 2 with eqparbox

Here is the preamble:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Numbers={Proportional}]{LibertinusSerif}
\usepackage{etoolbox}
\usepackage[showframe]{geometry}
\usepackage{eqparbox}

\makeatletter
\newcommand*\@symbolesnum[1]{% new numerotation
    \ifcase#1\unskip \or \unskip * \or \unskip † \or \unskip ‡ \or \unskip ** \or \unskip †† \or \unskip ‡‡ \or \unskip *** \or \unskip ††† \or \unskip ‡‡‡ \or \unskip **** \or \unskip †††† \or \unskip ‡‡‡‡ \or \unskip ***** \or \unskip ††††† \or \unskip ‡‡‡‡‡ \else\@ctrerr \fi%
}

\renewcommand\@makefntext[1]{% 
    \eqmakebox[footnote][r]{\liningnums{\@thefnmark}}.\enspace%
    #1%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For minipage :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\thempfootnote{\@symbolesnum{\c@mpfootnote}}
\newcounter{mpNum}
\setcounter{mpNum}{0}

\AtBeginEnvironment{minipage}{%
    \stepcounter{mpNum}%
    \renewcommand\@makefntext[1]{%
        \eqmakebox[mpfootnote][r]{\liningnums{\@thefnmark}}\enspace% doesn't work
%       \eqmakebox[mpfootnote\thempNum][r]{\liningnums{\@thefnmark}}\enspace% doesn't work
        #1%
    }%
}
\makeatother
12
  • Without understanding your problem fully, can't you define at least one max-variable instead of processing an .aux file? // E.g. in pseudocode 1) max=0; 2) if width>max : max=width; etc.
    – MS-SPO
    Commented Jul 31, 2021 at 12:45
  • I don't reallyunderstand what you mean. The maximum width is obtained by measuring all the widths of the footnote numbers. At the end of the compilation, this value is written to the auxiliary file. At the beginning of the next compilation, the auxiliary file is read and the value of the maximum width is used to format the footnotes of the current compilation. So this width must be known from the beginning of the compilation, which is the case thanks to the use of an auxiliary file.
    – B Legrand
    Commented Jul 31, 2021 at 14:34
  • Does this answer your question? Detecting stale aux file in a custom package
    – Teepeemm
    Commented Aug 5, 2021 at 19:53
  • 1
    As an aside: You could use eqparbox to extract the maximum width for you, rather than reinventing the wheel.
    – Werner
    Commented Aug 5, 2021 at 21:18
  • 3
    The big idea with the usual aux file is that you don't write a bare number. You write it as a command: \maxFootnoteWidthIs{9.40799pt}. Then you when the aux file is read in at the beginning/end of the document, you have defined that command. That automatically reads it in, and you just need to process it.
    – Teepeemm
    Commented Aug 5, 2021 at 21:36

1 Answer 1

5
+100

The following solution writes the width of the footnote labels to the aux file, as \newfnwidth{0}{4.25006pt}, \newfnwidth{0}{8.50012pt}, \newfnwidth{1}{6.61023pt} etc, where 0, 1, 2 etc identifies whether we are outside of minipages or within the 1st, 2nd etc minipage. The maximum of the lengths of footnote labels is computed at the beginning of the document, when processing the aux file. As usual, you have to run LaTeX twice to propagate the information.

Add the following lines to the preamble.

\makeatletter
% maximal length of footnote label
% assumes that \idfnwidth is set to a value identifying the context
% (0 = outside minipage, 1,2,3,... inside minipage)
% Depending on \idfnwidth, \maxfnwidth expands to the macro name
% \maxfnwidth-0, \maxfnwidth-1, \maxfnwidth-2, ...
\newcommand\maxfnwidth{\csname maxfnwidth-\idfnwidth\endcsname}

% \ensuredefmaxfnwidth{N}
% set \idfnwidth to N and define the length \maxfnwidth-N (if undefined)
\newcommand\ensuredefmaxfnwidth[1]{%
  \edef\idfnwidth{#1}%
  \expandafter\expandafter\expandafter\ifx\maxfnwidth\relax
     \expandafter\expandafter\expandafter\newlength\maxfnwidth
  \fi
}

% \newfnwidth{N}{W}
% is read from aux file
% sets \maxfnwidth-N to the maximum of W and \maxfnwidth-N
\newcommand\newfnwidth[2]{%
  \ensuredefmaxfnwidth{#1}%
  \ifdim\maxfnwidth<#2
     \global\maxfnwidth=#2
  \fi
}

% \fnwidth{footnote mark}
% writes the command "\newfnwidth{\idfnwidth}{width of footnote mark}"
% to the aux file
\newlength\thisfnwidth
\newcommand\fnwidth[1]{%
  \settowidth\thisfnwidth{#1}%
  \protected@write\@auxout{}{\string\newfnwidth{\idfnwidth}{\the\thisfnwidth}}%
}

% \@makefntext{footnote text}
% Writes the width of the footnote mark to the aux file
% and typesets the footnote
\renewcommand\@makefntext[1]{%
  \fnwidth{\@thefnmark}%
  \makebox[\maxfnwidth][r]{\@thefnmark}.\enspace#1%
}

% initialize \idfnwidth and \maxfnwidth-0
\ensuredefmaxfnwidth{0}

% counter for identifying minipages
\newcounter{fnwidth}

% at the beginning of each minipage, increment the counter
% and initialize \maxfnwidth
\AtBeginEnvironment{minipage}{%
  \stepcounter{fnwidth}%
  \ensuredefmaxfnwidth{\arabic{fnwidth}}%
}
\makeatother

enter image description here

\documentclass{article}

\makeatletter
\newcommand*\@symbolesnum[1]{% new numerotation for minipage footnote
    \ifcase#1\unskip \or \unskip * \or \unskip † \or \unskip ‡ \or \unskip ** \or \unskip †† \or \unskip ‡‡ \or \unskip *** \or \unskip ††† \or \unskip ‡‡‡ \or \unskip **** \or \unskip †††† \or \unskip ‡‡‡‡ \or \unskip ***** \or \unskip ††††† \or \unskip ‡‡‡‡‡ \else\@ctrerr \fi
}
\def\thempfootnote{\@symbolesnum{\c@mpfootnote}}

% maximal length of footnote label
% assumes that \idfnwidth is set to a value identifying the context
% (0 = outside minipage, 1,2,3,... inside minipage)
% Depending on \idfnwidth, \maxfnwidth expands to the macro name
% \maxfnwidth-0, \maxfnwidth-1, \maxfnwidth-2, ...
\newcommand\maxfnwidth{\csname maxfnwidth-\idfnwidth\endcsname}

% \ensuredefmaxfnwidth{N}
% set \idfnwidth to N and define the length \maxfnwidth-N (if undefined)
\newcommand\ensuredefmaxfnwidth[1]{%
  \edef\idfnwidth{#1}%
  \expandafter\expandafter\expandafter\ifx\maxfnwidth\relax
     \expandafter\expandafter\expandafter\newlength\maxfnwidth
  \fi
}

% \newfnwidth{N}{W}
% read from aux file
% sets \maxfnwidth-N to the maximum of W and \maxfnwidth-N
\newcommand\newfnwidth[2]{%
  \ensuredefmaxfnwidth{#1}%
  \ifdim\maxfnwidth<#2
     \global\maxfnwidth=#2
  \fi
}

% \fnwidth{footnote mark}
% writes the command "\newfnwidth{\idfnwidth}{width of footnote mark}"
% to the aux file
\newlength\thisfnwidth
\newcommand\fnwidth[1]{%
  \settowidth\thisfnwidth{#1}%
  \protected@write\@auxout{}{\string\newfnwidth{\idfnwidth}{\the\thisfnwidth}}%
}

% \@makefntext{footnote text}
% Writes the width of the footnote mark to the aux file
% and typesets the footnote
\renewcommand\@makefntext[1]{%
  \fnwidth{\@thefnmark}%
  \makebox[\maxfnwidth][r]{\@thefnmark}.\enspace#1%
}

% initialize \idfnwidth and \maxfnwidth-0
\ensuredefmaxfnwidth{0}

% counter for identifying minipages
\newcounter{fnwidth}

% at the beginning of each minipage, increment the counter
% and initialize \maxfnwidth
\AtBeginEnvironment{minipage}{%
  \stepcounter{fnwidth}%
  \ensuredefmaxfnwidth{\arabic{fnwidth}}%
}
\makeatother

\begin{document}
Lorem ipsum dolor sit amet\footnote{A footnote.},
consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris\footnote{A footnote.}. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit\footnote{A footnote.}. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas\footnote{A footnote.}. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed\footnote{A footnote.}. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.

Sed nec augue pellentesque, commodo diam quis, vehicula libero\footnote{A footnote.}. In hac habitasse platea dictumst. Phasellus tincidunt ligula vitae arcu tempor, eu facilisis augue fringilla. Curabitur id pulvinar ipsum, et gravida nisl. Aenean eget faucibus dolor, vel fermentum metus\footnote{A footnote.}. Quisque risus purus, porta vel eleifend nec, tempus sit amet diam. Sed sit amet commodo odio. Curabitur in tempor lorem. Sed venenatis malesuada odio, ac scelerisque nisi finibus ac. Aliquam cursus aliquet eleifend.

Duis in nisi vitae augue lacinia sodales sed vel libero. Duis vehicula, justo commodo ultrices blandit, purus sem ultrices velit, in imperdiet ligula sem vel sem\footnote{A footnote.}. Nam diam turpis, pulvinar ac lorem at, sagittis cursus nibh. Sed id gravida enim, id rutrum felis. Nam aliquet leo vel venenatis volutpat. Integer laoreet tincidunt mi, in faucibus nunc. Fusce porta et lorem id consectetur. Praesent ac vehicula metus, quis hendrerit tellus\footnote{A footnote.}. Maecenas consequat eleifend ante, non vehicula risus aliquet vitae. Duis et velit elit. Mauris nec lorem vel lorem rhoncus congue vitae in arcu.

Lorem ipsum dolor sit amet\footnote{A footnote.}, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris\footnote{A footnote.}. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit\footnote{A footnote.}. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas\footnote{A footnote.}. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed\footnote{A footnote.}. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.

Sed nec augue pellentesque, commodo diam quis, vehicula libero\footnote{A footnote.}. In hac habitasse platea dictumst. Phasellus tincidunt ligula vitae arcu tempor, eu facilisis augue fringilla. Curabitur id pulvinar ipsum, et gravida nisl. Aenean eget faucibus dolor, vel fermentum metus\footnote{A footnote.}. Quisque risus purus, porta vel eleifend nec, tempus sit amet diam. Sed sit amet commodo odio. Curabitur in tempor lorem. Sed venenatis malesuada odio, ac scelerisque nisi finibus ac. Aliquam cursus aliquet eleifend.

Duis in nisi vitae augue lacinia sodales sed vel libero. Duis vehicula, justo commodo ultrices blandit, purus sem ultrices velit, in imperdiet ligula sem vel sem\footnote{A footnote.}. Nam diam turpis, pulvinar ac lorem at, sagittis cursus nibh. Sed id gravida enim, id rutrum felis. Nam aliquet leo vel venenatis volutpat. Integer laoreet tincidunt mi, in faucibus nunc. Fusce porta et lorem id consectetur. Praesent ac vehicula metus, quis hendrerit tellus\footnote{A footnote.}. Maecenas consequat eleifend ante, non vehicula risus aliquet vitae. Duis et velit elit. Mauris nec lorem vel lorem rhoncus congue vitae in arcu.

\begin{center}
\begin{minipage}{\dimexpr\textwidth-2cm}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus\footnote{A footnote.}. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a.
\end{minipage}
\end{center}

\begin{center}
\begin{minipage}{\dimexpr\textwidth-2cm}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare, risus sit amet lacinia lacinia, lacus erat tristique est, et consequat nunc dolor id lorem. Suspendisse lobortis, metus vitae semper volutpat, nulla metus mollis tortor, non finibus sem quam id mauris. Fusce ut velit ac magna aliquet ullamcorper vitae nec massa\footnote{A footnote.}. Nunc suscipit ipsum tortor, sed facilisis nisi ultrices finibus\footnote{A footnote.}. Cras efficitur felis felis, sit amet aliquam dolor posuere et. Curabitur ut condimentum lorem. Etiam ac nisi augue. Nullam congue purus et metus fringilla malesuada. Praesent faucibus fermentum mi eget fringilla. Morbi velit ipsum, lacinia sed dolor id, fermentum auctor velit. Donec quis ante eget enim tempor ultrices.

Pellentesque ultrices efficitur ipsum ut bibendum. Sed ut vestibulum mi. Sed neque neque, efficitur nec sem eget, pulvinar ultricies lectus\footnote{A footnote.}. Nam ullamcorper dolor sed nulla ultricies varius. Donec mattis cursus dolor eu vehicula. Fusce molestie at ipsum vel commodo\footnote{A footnote.}. Vivamus eu malesuada metus. Praesent sed cursus ex. Fusce justo eros, elementum quis libero et, vestibulum pretium tortor. In rhoncus ex eu posuere placerat. Aenean fringilla sem a nisi aliquet egestas. Fusce vestibulum leo nibh, vel sollicitudin mauris interdum sed.

Curabitur tincidunt augue et rutrum laoreet\footnote{A footnote.}. Morbi pharetra lacus ac mi finibus condimentum. Nunc id venenatis neque. Fusce sed purus quis magna accumsan euismod a ac augue. Integer venenatis vulputate lacus, vel dapibus augue hendrerit sed. Donec eget mattis arcu, nec hendrerit ante. Donec rutrum est ut massa blandit, id semper metus tincidunt. Suspendisse nec vulputate risus, nec efficitur ex. Donec condimentum risus ligula, at consectetur erat lacinia sed\footnote{A footnote.}. Aenean vel euismod purus. Vestibulum interdum neque vitae erat rhoncus fermentum. Aenean convallis nisl velit, sit amet volutpat dui vulputate a\footnote{A footnote.}.
\end{minipage}
\end{center}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .