# Unintended effects of a solution to arranging footnotes

A solution to arranging footnotes in a particular manner has three unintended effects. Can these be fixed/undone?

This is the initial problem:

Paragraph short footnotes following multiline footnotes; prevent footnotes being paragraphed if they go onto a second line

The user wipet gave an excellent solution in TeX here. David Carlisle demonstrated how to use that answer within LaTeX here.

If I use that in a LaTeX, preamble, however, in addition to arranging the footnotes as intended, it also makes three unwanted changes.

1. Footnote text is now the same size as body text (rather than smaller).
2. Footnote line spacing is now the same as body text (rather than single-space); that is, setspace now changes footnote line spacing as well.
3. The typeface of the footnote numbers, both in the body text and in the footnote block, is now Computer Modern regardless of the font specified for the document (by fontspec).

A MWE to illustrate the effects is:

\documentclass[12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text,Numbers=OldStyle]{Arial}

\newcount\specfootnum % for global counting the footnotes
\newcount\fnotenum    % for footnote marks
\newif\ifrepeat

\tracingpages=1

\edef\tmp{\indent\llap{\fnmark\kern2pt}}%
\expandafter\gdef\csname specfoot:\the\specfootnum
\expandafter\endcsname\expandafter{\tmp#1}%
\setbox0=\hbox{\tmp#1}%
\ifdim\wd0<.45\hsize \dimen0=.5\baselineskip
\else \ifdim\wd0>\hsize \setbox0=\vbox{\tmp\strut#1\strut\par\kern0pt}\dimen0=\ht0
\else\dimen0=\baselineskip
\fi\fi
\insert\footins{\floatingpenalty=20000
\vbox to\dimen0{\vss\penalty\specfootnum}\penalty0}%
}
\def\fnmark{$^{\the\fnotenum}$}

\catcode@=11
\def\pagecontents{\ifvoid\topins\else\unvbox\topins\fi
\dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
\ifvoid\footins\else % footnote info is present
\vskip\skip\footins \footnoterule \printspecfoot \fi
\ifr@ggedbottom \kern-\dimen@ \vfil \fi
}

\gdef \@makecol {%
\ifvoid\footins
\setbox\@outputbox \box\@cclv
\else
\setbox\@outputbox \vbox {%
\boxmaxdepth \@maxdepth
\unvbox \@cclv
\vskip \skip\footins
\color@begingroup
\normalcolor
\footnoterule
\footnoterule \printspecfoot
\ifx\@textbottom\relax\else\kern-\dimen@ \vfil \fi
\color@endgroup
}%
\fi
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global \let \@midlist \@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox \vbox to\@colht {%
\@texttop
\dimen@ \dp\@outputbox
\unvbox \@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global \maxdepth \@maxdepth
}

\catcode@=12

\def\printspecfoot{\bgroup\def\tmp{}%
\setbox0=\vbox{\repeattrue \unvbox\footins
\loop \unpenalty \setbox0=\lastbox
\ifvoid0 \repeatfalse
\else \setbox0=\vbox{\unvbox0 \xdef\tmp{\the\lastpenalty,\tmp}}\fi
\ifrepeat \repeat
}%
\dimen1=\hsize \rm
\expandafter\printspecfootA\tmp,
}
\def\printspecfootA#1,{\ifx,#1,\egroup\else
\ifdim\dimen1<.45\hsize
\setbox0=\hbox{\csname specfoot:#1\endcsname}%
\ifdim\wd0<.5\hsize
\vskip-\baselineskip \vskip-\parskip
\noindent\hskip.5\hsize \hskip-.5\parindent \box0 \par
\dimen1=\hsize
\else
\noindent\unhbox0 \newdimenone
\fi
\else \csname specfoot:#1\endcsname \newdimenone \fi
\global\expandafter\let\csname specfoot:#1\endcsname=\relax
\expandafter \printspecfootA\fi
}
\def\newdimenone{$$\global\dimen1=\predisplaysize \abovedisplayskip=0pt \belowdisplayskip=0pt \abovedisplayshortskip=0pt \belowdisplayshortskip=0pt$$\advance\dimen1 by-2em\vskip-\baselineskip
}

%%% the test:

\raggedbottom

\begin{document}

This is text in Arial to illustrate that the footnote number in the body text is in Computer Modern.\footnote{As it also is down here.} The footnotes do arrange themselves as intended.\footnote{In this way.} But the footnote text is both the same size as the body text and has the same spacing.\footnote{As you can see in this footnote, which is long enough to extend over two lines and illustrate the point. Neither of these effects are intended.}

\end{document}


This renders for me as:

Can you see why this would have these three effects? And how can they be undone (they are unintended and unwanted)?

I added two instances of \footnotesize in the definition of \printspecfootA, added the unicode-math package and invoked \setmathfont{Arial}, since the footnote mark is defined in math mode as \def\fnmark{$^{\the\fnotenum}$}.

EDITED to handle the setspace issue, though it required the use of negative \vspace. I did this by adding \singlespacing upon entry into the \printspecfoot group. However, I had to also add an associated negative \vspace to overcome added vertical space between the footnote-line and the actual footnotes. Why I had to do this I neither understand nor like.

\documentclass[12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage{fontspec,unicode-math}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text,Numbers=OldStyle]{Arial}
\setmathfont{Arial}

\newcount\specfootnum % for global counting the footnotes
\newcount\fnotenum    % for footnote marks
\newif\ifrepeat

\tracingpages=1

\edef\tmp{\indent\llap{\fnmark\kern2pt}}%
\expandafter\gdef\csname specfoot:\the\specfootnum
\expandafter\endcsname\expandafter{\tmp #1}%
\setbox0=\hbox{\tmp#1}%
\ifdim\wd0<.45\hsize \dimen0=.5\baselineskip
\else \ifdim\wd0>\hsize \setbox0=\vbox{\tmp\strut#1\strut\par\kern0pt}\dimen0=\ht0
\else\dimen0=\baselineskip
\fi\fi
\insert\footins{\floatingpenalty=20000
\vbox to\dimen0{\vss\penalty\specfootnum}\penalty0}%
}
\def\fnmark{$^{\the\fnotenum}$}

\catcode@=11
\def\pagecontents{\ifvoid\topins\else\unvbox\topins\fi
\dimen@=\dp\@cclv \unvbox\@cclv % open up \box255
\ifvoid\footins\else % footnote info is present
\vskip\skip\footins \footnoterule \printspecfoot \fi
\ifr@ggedbottom \kern-\dimen@ \vfil \fi
}

\gdef \@makecol {%
\ifvoid\footins
\setbox\@outputbox \box\@cclv
\else
\setbox\@outputbox \vbox {%
\boxmaxdepth \@maxdepth
\unvbox \@cclv
\vskip \skip\footins
\color@begingroup
\normalcolor
\footnoterule
\footnoterule \printspecfoot
\ifx\@textbottom\relax\else\kern-\dimen@ \vfil \fi
\color@endgroup
}%
\fi
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global \let \@midlist \@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox \vbox to\@colht {%
\@texttop
\dimen@ \dp\@outputbox
\unvbox \@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global \maxdepth \@maxdepth
}

+
\catcode@=12

\def\printspecfoot{\vspace{-12pt}\bgroup\singlespacing\def\tmp{}%
\setbox0=\vbox{\repeattrue \unvbox\footins
\loop \unpenalty \setbox0=\lastbox
\ifvoid0 \repeatfalse
\else \setbox0=\vbox{\unvbox0 \xdef\tmp{\the\lastpenalty,\tmp}}\fi
\ifrepeat \repeat
}%
\dimen1=\hsize \rm
\expandafter\printspecfootA\tmp,
}
\def\printspecfootA#1,{\ifx,#1,\egroup\else
\ifdim\dimen1<.45\hsize
\setbox0=\hbox{\footnotesize\csname specfoot:#1\endcsname}%
\ifdim\wd0<.5\hsize
\vskip-\baselineskip \vskip-\parskip
\noindent\hskip.5\hsize \hskip-.5\parindent \box0 \par
\dimen1=\hsize
\else
\noindent\unhbox0 \newdimenone
\fi
\else \footnotesize\csname specfoot:#1\endcsname \newdimenone \fi
\global\expandafter\let\csname specfoot:#1\endcsname=\relax
\expandafter \printspecfootA\fi
}
\def\newdimenone{$$\global\dimen1=\predisplaysize \abovedisplayskip=0pt \belowdisplayskip=0pt \abovedisplayshortskip=0pt \belowdisplayshortskip=0pt$$\advance\dimen1 by-2em\vskip-\baselineskip
}

%%% the test:

\raggedbottom

\begin{document}

This is text in Arial to illustrate that the footnote number in the body text is in Computer Modern.\footnote{As it also is down here.} The footnotes do arrange themselves as intended.\footnote{In this way.} But the footnote text is both the same size as the body text and has the same spacing.\footnote{As you can see in this footnote, which is long enough to extend over two lines and illustrate the point. Neither of these effects are intended.}

\end{document}


• That works for me, thank you. It solves 2 of the 3 unintended consequences. The footnote block still takes its linespacing from setspace, however (I should perhaps have set it to 'doublespacing' to illustrate that more clearly). Curious to know if that is fixable as well. (And just in case this all seems arbitrary and arcane, it is in fact the closest I've seen LaTeX come to implementing what is an extremely common footnote-placement rule in well typeset humanities publications. If it can be made to work well it will be useful to lots of people.) – Jacob Aug 3 '17 at 11:47
• @Jacob I didn't notice that setspace was involved. I have revised my answer, adding a \singlespacing at the onset of the \printspecfoot group, but also had to add a negative \vspace for some reason. – Steven B. Segletes Aug 3 '17 at 12:02
• Thanks! That seems to work. Believing you that negative \vspace is not the ideal answer (though not understanding why - I take your word for it), I've added a bounty to see if others have another approach. If none come forward I'll accept your answer. – Jacob Aug 5 '17 at 11:56