如何从辅助文件中提取变量?

如何从辅助文件中提取变量?

我想使用辅助文件来读取和写入一些信息。


语境

在本例中,我使用此辅助文件来记录脚注格式中使用的宽度。实际上,我希望我的脚注编号右对齐,如下所示:

在此处输入图片描述

所以我需要知道提前(使用以前汇编的信息)最宽脚注编号的宽度(\@widthFootnoteNum对于“正常”脚注,\@mpwidthFootnoteNum对于小页面中的脚注)。

如果我只考虑“正常”脚注,则没有什么特别的问题。 的值在编译结束时\@widthFootnoteNum写入辅助文件(称为),并在下一次编译开始时读取。\jobname.foot

但是,如果我在 minipage 环境中对脚注执行相同的操作,事情就会变得复杂。辅助文件中写入了几个值,我必须读取此文件以找到正确的宽度,然后写入该文件以提供下一次并行编译的正确宽度。

我的测试没有定论...我设法写下了所有必要的信息,但之后我无法读取它。


平均能量损失

考虑以下 MWE:
一个包含 20 个“正常”脚注的简单文件和两个分别minipage包含 2 个和 7 个注释的环境。

\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}

我得到以下辅助文件:

6.704pt
11.40799pt
7.752pt

\@mpwidthFootnoteNum第一个值是第一个 minipage 环境的 的值。第二个值是第二个 minipage 环境
的 的值。第三个值对应于“正常”脚注 的 的值。\@mpwidthFootnoteNum
\@widthFootnoteNum

因此我设法将下次编译所需的所有信息保存在辅助文件中。


问题

问题是我无法在编译时使用这些不同的值,因为辅助文件在同一编译过程中被连续读取和写入。因此每次新的写入都会覆盖该文件。

我们怎样才能解决这个问题?


我尝试过

我考虑过在编译开始时将所有值存储在一种编号列表中,从中可以取出最后一个值来赋值,\@widthFootnoteNum然后取出其他值来分配给不同\@mpwidthFootnoteNum的 minpage。目标是只需读取一次辅助文件。但我不知道该怎么做。

我尝试arrayjob通过将辅助文件放入数组来使用该包,但没有成功。

我还尝试使用两个辅助文件。文件A将用于编写@widthFootnoteNum各种@mpwidthFootnoteNum。在下一次编译开始时,文件A将被复制到一个文件中,它将在编译时读入并给出widthFootnoteNum和的值mpwidthFootnoteNum的值。同样,我还没有做到这一点,因为我似乎无法复制文件A进入文件

最后,我尝试将应采用的不同值存储@mpwidthFootnoteNum在一个语法中ifcase #1 ...,其中#1表示环境的数量minipage。对于每个minipage环境,\@mpwidthFootnoteNum因此采用不同的值。

以下是序言:

\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

这将产生以下辅助文件:

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

这看起来是正确的,但是在编译时,我发现了几个错误。


选择

我尝试eqparbox按照 Werner 的建议使用该软件包,虽然它对于“正常”脚注来说运行良好,但在环境中使用脚注时问题仍然存在minipage,如下图所示:

eqparbox 的小页面 1 问题 eqparbox 的小页面 2 问题

以下是序言:

\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

答案1

以下解决方案将脚注标签的宽度写入辅助文件,如\newfnwidth{0}{4.25006pt}\newfnwidth{0}{8.50012pt}\newfnwidth{1}{6.61023pt}等,其中012等标识我们是在 minipages 之外还是在1st、2nd 等 minipage 之内。处理辅助文件时,在文档开头计算脚注标签的最大长度。与往常一样,您必须运行 LaTeX 两次才能传播信息。

将以下几行添加到序言中。

\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

在此处输入图片描述

\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}

相关内容