2

This is a follow up question of Is it possible to declare that the footnote number is right aligned but uses a dynamic width?.

I tried to implement the solution given by @wipet on the original question in LaTeX rather that TeX. And as far as I can tell I understod the principle, but could get it to work: It seems like the info is written to the aux file correctly as

\@namedef{page@of@footnote@0}{1} \@namedef{max@footnote@on@page@1}{0} 
\@namedef{page@of@footnote@1}{1} \@namedef{max@footnote@on@page@1}{1} 
\@namedef{page@of@footnote@2}{2} \@namedef{max@footnote@on@page@2}{2} 
\@namedef{page@of@footnote@100}{3} \@namedef{max@footnote@on@page@3}{100}

but I can’t access it with

\csuse{max@footnote@on@page@\csuse{page@of@footnote@\thefootnote}}

(the result is an empty string).

Full Code

\documentclass{scrbook}

\usepackage{etoolbox}

\newlength{\fnotemargin}
\setlength{\fnotemargin}{4.5mm}
\deffootnote{\fnotemargin}{1em}{%
   \makebox[\fnotemargin][l]{\thefootnotemark}%
}

\makeatletter

\preto{\footnote}{%
   \protected@write\@auxout{}{%
      \string\@namedef{page@of@footnote@\thefootnote}{\thepage}
      \string\@namedef{max@footnote@on@page@\thepage}{\thefootnote}
   }%
   \def\thispagesmaxfootnote{%
      \csuse{max@footnote@on@page@\csuse{page@of@footnote@\thefootnote}}%
   }%
   (max. fnote on this page = \thispagesmaxfootnote)% FOR TESTING
   \ifnum\thispagesmaxfootnote>99\relax
      \setlength{\fnotemargin}{4.5mm}
   \fi
}

\makeatother

\begin{document}
   Test\footnote{Test}\par
   Test\footnote{Test}
   \newpage
   Test\footnote{Test}
   \newpage
   \setcounter{footnote}{100}
   Test\footnote{Test}
\end{document}

Question
So the question is why I do get the wrong results although the information is written in the aux file?

5
  • The aux-file is read inside a group. tex.stackexchange.com/questions/137495/…. Beside this I wouldn't use \thefootnote in a csname -- you can't know what it exactly does. Oct 28, 2016 at 8:39
  • @UlrikeFischer: Thanks I thought that but didnt test. It works with \csgdef. And what do you suggest instead of \thefootnote? neither \value{footnote} nor \c@footnote worked ...
    – Tobi
    Oct 28, 2016 at 14:11
  • \the\value{footnote} or \the\c@footnote or \number\c@footnote should work. Oct 28, 2016 at 15:02
  • @UlrikeFischer: Great! I didn’t know I could use \the in combination with value. Would you like to post an answer? Otherwise I’d post a CW one …
    – Tobi
    Oct 29, 2016 at 8:31
  • Or even better: post it as answer to the original question and we close this one as duplicate …
    – Tobi
    Oct 29, 2016 at 8:34

1 Answer 1

1

This is what the full code should read (I added some comments/explanations in the MWE itself):

\documentclass{scrbook}

\usepackage{etoolbox}

% a new length for the footnote margin
\newlength{\fnotemargin}
% the "normal" (narrow) value should be 4.5mm
\setlength{\fnotemargin}{4.5mm}

% now we define how the footnotes look
% - first argument: margin for footnotes = the above defined length
% - second argument: the par intent for footnotes = 1em
% - third argument: how the number should be printed in the apparatus
%       = a box of with \fnotemargin containing the mark left aligned
\deffootnote{\fnotemargin}{1em}{%
   \makebox[\fnotemargin][l]{\thefootnotemark}%
}

% make @ available as part of macro names
\makeatletter

% with \preto we prepend some code to \footnote, it will be executed every time \footnote is used
\preto{\footnote}{%
   % wirte the following (third argument) to the *.aux file (this will be used later)
   \protected@write\@auxout{}{%
      % \string protects the following macro to be written verbatim in the file
      % The first line defines a macro named page@of@footnote@n where n is the current
      % (at time of writing to file) footnote value. This the definition is the current
      % page number.
      \string\csgdef{page@of@footnote@\the\value{footnote}}{\thepage}
      % the second line defines a macro named max@footnote@on@page@m (m = current page
      % number) to be the current footnote number.
      \string\csgdef{max@footnote@on@page@\thepage}{\the\value{footnote}}
      % When later (second/further TeX run) the auxfile is read all these defenition will be
      % executed. Then we have one macro for every footnote (\page@of@footnote@n)
      % containing the info on which page it appears and multiple definitions
      % for each page -- where the last one wins -- max@footnote@on@page@m containing
      % the information about the highest footnote number on that page.
      % (Note: The use of \csname (variants of it) allows us to use numbers as part of
      % macro names which is prohibited normally.)
   }%
   % now we define the macro \thispagesmaxfootnote to contain the value of the
   % highes footnote on this page. Ths information is taken from the definitions
   % written to the *.aus file in the previous TeX run.
   \edef\thispagesmaxfootnote{%
      0\csuse{max@footnote@on@page@\csuse{page@of@footnote@\the\value{footnote}}}%
   }%
%   (max. fnote on this page = \thispagesmaxfootnote)% FOR TESTING
   % lastly we test wether the footnote value is grater than 99 (the couter is off by
   % one at this pointcompared with the printed value; thus <98 instead of <99).
   \ifnum\thispagesmaxfootnote>98\relax
      % if TRUE we set the wide margin
%      (set wide margin)% FOR TESTING
      \setlength{\fnotemargin}{7.5mm}%
   \else
      % if FALSE we set the narrow margin
%      (set norrow margin)% FOR TESTING
      \setlength{\fnotemargin}{4.5mm}%
   \fi
}

% for cases where the footnote number is reset in each chapter for instance the
% above definition must be expaned to make the information macro cotain 
% the chapter number too. I.e. page@of@footnote@\the\value{footnote}
% could be changed to page@of@footnote@\the\value{chapter}@\the\value{footnote}

% deactivate @ as part of macro names
\makeatother

\begin{document}
   Test\footnote{Test}\par
   Test\footnote{Test}
   \newpage
   Test\footnote{Test}
   \newpage
   \setcounter{footnote}{100}
   Test\footnote{Test}
\end{document}

Note: If the footnote counter is reset to 1 in every chapter, you must add a chapter identifier to the the aux macro, like the:

   \preto{\footnote}{%
      \protected@write\@auxout{}{%
         \string\csgdef{page@of@footnote@chap\the\value{chapter}@fn\the\value{footnote}}{\thepage}
         \string\csgdef{max@footnote@on@page@\thepage}{\the\value{footnote}}
      }%
      \edef\thispagesmaxfootnote{%
         0\csuse{max@footnote@on@page@\csuse{page@of@footnote@chap\the\value{chapter}@fn\the\value{footnote}}}%
      }%
      \ifnum\thispagesmaxfootnote>98\relax
         \setlength{\fnotemargin}{1.75em}%
      \else
         \setlength{\fnotemargin}{1.25em}%
      \fi
   }

You must log in to answer this question.

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