如何获取当前页面的脚注数量?

如何获取当前页面的脚注数量?

有吗?(我想要这个,因为7 n.\,1如果页面上有多个注释,我想制作索引格式7\,n

PS. 按照要求说得更清楚一点:能否定义一个宏\fnnonthispage来返回当前页面上的脚注数量?我不知道该如何说得更清楚。

PS II。宏的使用方法如下。第一页有两个注释,因此条目应指定编号;但第二页只有一个注释,因此不应指定编号。如果页面包含部分脚注,也应算作一个。

%compile with: pdflatex file; makeindex file; pdflatex file
\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage{letltxmacro}

\makeindex

% \see{} inserts a see in the next entry, after the pp. 
\def\seeentry{}
% must be global to work within footnote
\def\see#1{\gdef\seeentry{#1}} 
\def\seesep{;\space}
\def\seetext{see\space}

% \index{<entry>|fn} marks the ref. as to a note
\def\fn#1#2{% insert see if \seeentry is not empty
\hyperpage{#2} n.\,#1\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
% ----- here is how the desired macro could be used:
%\hyperpage{#2}%
%\ifnum\fnnonthispage>1
%\space n.\,#1\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
%\else
%\,n.\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
%\fi
}%

% Redefining \index to mark reff. to notes as such.
\LetLtxMacro{\oldindex}{\index}
\renewcommand{\index}[1]{%
\if@noftnote%
\oldindex{#1}%
\else%
\oldindex{#1|fn{\number\value{footnote}}}
\fi%
}

\begin{document}
Cheese.\footnote{\index{cake}cake.}
Whether it be cheese or not.\footnote{What?}
\newpage
Oranges are called Chinese apples in German.\footnote{And in
Danish, of course.\index{Danish}}
\printindex
\end{document}

答案1

这里有一个解决方案。我们检查每个输出页面是否有多个脚注,如果没有,则\mtfnexiste<pagenumber>定义一个宏。

笔记John Kormylo 的上述评论很重要,但我没有在这里关注这一点。请告诉我。

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage{letltxmacro}

\makeindex

% \see{} inserts a see in the next entry, after the pp. 
\def\seeentry{}
% must be global to work within footnote
\def\see#1{\gdef\seeentry{#1}} 
\def\seesep{;\space}
\def\seetext{see\space}

% \index{<entry>|fn} marks the ref. as to a note

\newcounter{mtfn}
\setcounter{mtfn}{1}
\makeatletter
\patchcmd\@outputpage{\stepcounter{page}}{%
\ifnum\value{mtfn}<\value{footnote}
\expandafter\gdef\csname mtfnexiste\thepage\endcsname{x}\fi
\setcounter{mtfn}{\value{footnote}}\stepcounter{mtfn}%
\stepcounter{page}}{}{\errmessage{no}}


\def\fn#1#2{% insert see if \seeentry is not empty
\hyperpage{#2}%
\expandafter\ifx\csname mtfnexiste\@secondoftwo#2\endcsname\relax
\,n.\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
\else
\space n.\,#1\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
\fi
}%
\makeatother

% Redefining \index to mark reff. to notes as such.
\LetLtxMacro{\oldindex}{\index}
\renewcommand{\index}[1]{%
\if@noftnote%
\oldindex{#1}%
\else%
\oldindex{#1|fn{\number\value{footnote}}}
\fi%
}

\begin{document}
Cheese.\footnote{\index{cake}cake.}
Whether it be cheese or not.\footnote{What?}
\newpage
Oranges are called Chinese apples in German.\footnote{And in
Danish, of course.\index{Danish}}
\printindex
\end{document}

更新长脚注的例子它是第一页中的第二个脚注,但索引词在第二页中只有一个脚注,所以问题!

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage{letltxmacro}
\usepackage{lipsum}

\makeindex

% \see{} inserts a see in the next entry, after the pp. 
\def\seeentry{}
% must be global to work within footnote
\def\see#1{\gdef\seeentry{#1}} 
\def\seesep{;\space}
\def\seetext{see\space}

% \index{<entry>|fn} marks the ref. as to a note

\newcounter{mtfn}
\setcounter{mtfn}{1}
\makeatletter
\patchcmd\@outputpage{\stepcounter{page}}{%
\ifnum\value{mtfn}<\value{footnote}
\expandafter\gdef\csname mtfnexiste\thepage\endcsname{x}\fi
\setcounter{mtfn}{\value{footnote}}\stepcounter{mtfn}%
\stepcounter{page}}{}{\errmessage{no}}


\def\fn#1#2{% insert see if \seeentry is not empty
\hyperpage{#2}%
\expandafter\ifx\csname mtfnexiste\@secondoftwo#2\endcsname\relax
\,n.\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
\else
\space n.\,#1\ifx\seeentry\empty\else\seesep\seetext\seeentry\def\seeentry{}\fi%
\fi
}%
\makeatother

% Redefining \index to mark reff. to notes as such.
\LetLtxMacro{\oldindex}{\index}
\renewcommand{\index}[1]{%
\if@noftnote%
\oldindex{#1}%
\else%
\oldindex{#1|fn{\number\value{footnote}}}
\fi%
}

\begin{document}
\lipsum[1-2]
\footnote{bla bla}
\lipsum[1-2]
\footnote{very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
very very long long footnote very very long long footnote
cake\index{cake}}
\lipsum[1-2]
\footnote{last bla bla}
\printindex
\end{document}

相关内容