2

Is there one? (I want this because I want to make the index format 7 n.\,1 if there is more than one note on the page and 7\,n.

PS. More clearly stated, as requested: could one define a macro \fnnonthispage that returned the number of footnotes on the current page? I don't know how to say it more clearly.

PS II. Here is how the macro might be used. On the first page, there are two notes, so the entry should specify the number; but of p. 2, there is only one, and so there the number should not be specified. If a page contains a partial footnote, that should also count as one.

%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}
15
  • Just use \thefootnote?
    – user30471
    Commented Feb 25, 2016 at 11:18
  • @Andrew, but that won't tell me whether there will be more footnotes before the end of the page. I mean the number of footnotes, not the number of the footnote.
    – Toothrot
    Commented Feb 25, 2016 at 11:34
  • you can write to external file .aux for example.
    – touhami
    Commented Feb 25, 2016 at 14:14
  • 1
    @touhami, thanks. If you prefer it, I can give a minimal example first. But you'd have to give me some time.
    – Toothrot
    Commented Feb 25, 2016 at 14:32
  • 2
    The key problem is what happens if a footnote occurs in a paragraph which gets split at the end of a page. The footnote counter should get incremented before the everypage hook. To get a reliable number you would have to use \protected@write{auxout} to record ever footnote and what page it occurred on, then count them up the next \begin{document}. (Doesn't cleverref already do something iike that?) Commented Feb 26, 2016 at 4:26

1 Answer 1

2

Here is a solution. We check if there is more than one footnote at every output page, if no a macro \mtfnexiste<pagenumber> is defined.

Note John Kormylo's comment above is important but I did not take care of the point here. Let me know.

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

Update exemple of long footnote it is the 2 nd footnote in first page but the indexed word is in second page with only one footnote in it so the problem!

\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}
4
  • Thank you very much. How does this (not) handle partial notes?
    – Toothrot
    Commented Feb 26, 2016 at 11:03
  • please see update.
    – touhami
    Commented Feb 26, 2016 at 12:30
  • 1
    aha, so the part that carries over from p.1 doesn't count as a footnote on p. 2, I see.
    – Toothrot
    Commented Feb 26, 2016 at 12:59
  • 1
    one can work around, if you want I can see this later.
    – touhami
    Commented Feb 26, 2016 at 13:11

You must log in to answer this question.

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