[Tex/LaTex] How to enable protrusion for footnotes with \fnsymbol using microtype

footnotesmicrotypeprotrusion

In microtype package (v.2.5 beta 06) and footnote protrusion, custom protrusion for footnote numbers is enabled. However, as soon as I edit the footnote characters to the ones generated by \fnsymbol and alter the corresponding character to be protruded, it stops working. Here's an MWE for the footnote with numbers:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\geometry{a5paper,showframe}
\usepackage[protrusion=true,factor=2000]{microtype}
\SetProtrusion[context=footnote]{encoding=T1}{1={,650}}    

\makeatletter
\newcommand*\new@makefnmark{\hbox{\@textsuperscript{\normalfont
    \microtypecontext{protrusion=footnote}\@thefnmark}}}
\renewcommand*\@footnotemark{%
    \leavevmode \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
    \new@makefnmark \ifhmode\spacefactor\@x@sf\fi \relax}
\makeatother

\begin{document}
Here's some text to show the behaviour of footnote marker at%
%
\footnote{A footnote}
%
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.
\end{document}

Here's an MWE for the footnote with the symbols defined by \fnsymbol:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\geometry{a5paper,showframe}
\usepackage[protrusion=true,factor=2000]{microtype}
\SetProtrusion[context=footnote]{encoding=T1}{*={,650}}    
%\SetProtrusion[context=footnote]{encoding=T1}{\ast={,650}}    
%\SetProtrusion[context=footnote]{encoding=T1}{\textasteriskcentered={,650}}    
% None of the above work

\makeatletter
\newcommand*\new@makefnmark{\hbox{\@textsuperscript{\normalfont
    \microtypecontext{protrusion=footnote}\@thefnmark}}}
\renewcommand*\@footnotemark{%
    \leavevmode \ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
    \new@makefnmark \ifhmode\spacefactor\@x@sf\fi \relax}
\makeatother

\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\begin{document}
Here's some text to show the behaviour of footnote marker at%
%
\footnote{A footnote}
%
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.
\end{document}

However, given the definition of \@fnsymbol I know for a fact that the symbol for the first footnote is *:

\fnsymbol=macro:
#1->\expandafter \@fnsymbol \csname c@#1\endcsname

\@fnsymbol=macro:
#1->\ensuremath {\ifcase #1\or *\or \dagger \or \ddagger \or \mathsection \or     mathparagraph \or \|\or **\or \dagger \dagger \or \ddagger \ddagger \else \@ctr
err \fi }

So my question is, how do I configure microtype correctly to get this to work? Note that I am using microtype v2.5. Below are the errors I get from running the nonworking MWE:

Package microtype Warning: I cannot find a protrusion list for font
(microtype)                `OT1/lmr/m/n/7' (context: `footnote'). Switching off
(microtype)                protrusion for this font on input line 20.


Package microtype Warning: I cannot find a protrusion list for font
(microtype)                `OT1/lmr/m/n/5' (context: `footnote'). Switching off
(microtype)                protrusion for this font on input line 20.


Package microtype Warning: I cannot find a protrusion list for font
(microtype)                `OT1/lmr/m/n/10' (context: `footnote'). Switching off
(microtype)                protrusion for this font on input line 20.

Best Answer

First, let us make it work with hyperref. hyperref redefines \@footnotemark itself, so instead of overwriting it, we just patch it with the etoolbox package.

\usepackage{etoolbox}
...
\makeatletter
\newcommand*\new@makefnmark{\hbox{\@textsuperscript{\normalfont
    \microtypecontext{protrusion=footnote}\@thefnmark}}}
\patchcmd{\@footnotemark}
  {\@makefnmark}
  {\new@makefnmark}{}{}
\makeatother

Next, let us protrude the footnote markers. We define the fonts that we want to protrude. I chose the default set alltext, plus the font of the footnote symbols:

\DeclareMicrotypeSet{alltextAndFootnotes}{%
  encoding = {OT1,T1,T2A,LY1,OT4,QX,T5,TS1,EU1,EU2}, %% alltext
  font     = {OMS/lmsy/m/n/scriptsize},
}

Next, we tell microtype that this is the set of fonts we want to protrude:

\microtypesetup{protrusion=alltextAndFootnotes}

Now we can define the actual protrusion:

\SetProtrusion[context=footnote]{encoding=OMS, family=lmsy,series=m, shape=n, size=scriptsize}{%
  "03={,650},%% *
  "78={,650},%% \mathsection
  "79={,650},%% \dagger
  "7A={,650},%% \ddagger
  "7B={,650},%% \mathparagraph
  "6B={,650},%% \|
  }

This would already be enough, but microtype complains that it has no protrusion settings for T1/lmr/m/n/7 and for OT1/lmr/m/n/7 etc., so let us provide some:

\SetProtrusion[context=footnote,load=lmr-T1,factor = 700]
  {encoding=T1, family=lmr, series=m, shape=n, size=scriptsize}
  {  }
\SetProtrusion[context=footnote,load=cmr-OT1,factor = 700]
  {encoding=OT1, family=lmr, series=m, shape=n}
  {  }

We just use the default protrusion settings for T1-encoded Latin Modern Roman, and OT1-encoded Computer Modern, scaled a little down. Change to your liking.

Complete MWE:

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{etoolbox}

\usepackage{geometry}
\geometry{a5paper,showframe}

\usepackage[colorlinks]{hyperref}


\usepackage[protrusion=alltext,factor=2000]{microtype}

\DeclareMicrotypeSet{alltextAndFootnotes}{%
  encoding = {OT1,T1,T2A,LY1,OT4,QX,T5,TS1,EU1,EU2}, %% alltext
  font     = {OMS/lmsy/m/n/scriptsize},
}

\microtypesetup{protrusion=alltextAndFootnotes}
\SetProtrusion[context=footnote]{encoding=OMS, family=lmsy,series=m, shape=n, size=scriptsize}{%
  "03={,650},%% *
  "78={,650},%% \mathsection
  "79={,650},%% \dagger
  "7A={,650},%% \ddagger
  "7B={,650},%% \mathparagraph
  "6B={,650},%% \|
  }
\SetProtrusion[context=footnote,load=lmr-T1,factor = 700]
  {encoding=T1, family=lmr, series=m, shape=n, size=scriptsize}
  {  }
\SetProtrusion[context=footnote,load=cmr-OT1,factor = 700]
  {encoding=OT1, family=lmr, series=m, shape=n}
  {  }

\makeatletter
\newcommand*\new@makefnmark{\hbox{\@textsuperscript{\normalfont
    \microtypecontext{protrusion=footnote}\@thefnmark}}}
\patchcmd{\@footnotemark}
  {\@makefnmark}
  {\new@makefnmark}{}{}
\makeatother

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

%% --------------------------------------------------------------
%% --------------------------------------------------------------
\begin{document}
Here's some text to show the behaviour of footnote marker at%
\footnote{A footnote}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{B}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{C}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{D}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{E}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{F}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{G}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{H}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.

Here's some text to show the behaviour of footnote marker at%
\footnote{I}
the end of a line, which disappears when the code for setting  microtypecontext is used in fnmark redefinition.
\end{document}

which gives

sample output