44

This question led to a new package:
fnpct

Following up on my question on the kerning of footnote marks after punctuation marks, I'd like to know if there is a way to achieve the kerning of footnote marks over a comma or full stop automatically or with a better macro than the one I provided there. I'm going to repeat my result and the macro I suggested.

Here the footnote marks are moved to the left by a little less than a third of the width of the punctuation marks and the normal footnote marks (that is, those that come after any other symbol or letter) are moved right by the same amount, as inspired by http://www.read.seas.harvard.edu/~kohler/latex.html and shown in my comment:

package default compensation

This is achieved with the following code:

\documentclass{article}
% URW Classico is a font that makes the issue apparent
\renewcommand{\sfdefault}{uop}
\renewcommand{\familydefault}{\sfdefault}
% define punctuation-aware footnote macro
\let\origfootnote\footnote
\renewcommand{\footnote}[1]{\kern.06em\origfootnote{#1}}
\newcommand{\punctfootnote}[1]{\kern-.06em\origfootnote{#1}}
% define a very small 
\setlength{\textwidth}{150pt}
\setlength{\textheight}{5\baselineskip}
\begin{document}
\noindent The three little pigs built their houses out of
straw,\punctfootnote{not to be confused with hay}
sticks\footnote{or lumber according to some sources} and
bricks.\punctfootnote{probably fired clay bricks}
\end{document}

Using LuaLaTeX is an option for me. I'm also aware of the existing question regarding automatic kerning but I know too little to adapt the LuaLaTeX code there to my problem.

2 Answers 2

46
+100

Edit - using the new package:

With the package fnpct now available just use \usepackage{fnpct} and make sure the punctuation marks follow the footnotes:

\documentclass{article}
% for demonstration purposes only: make the page small!
\usepackage[
  paperwidth=.5\textwidth,
  paperheight=15\baselineskip,
  margin=5pt,
  bottom=1.5cm]{geometry}

\usepackage{fnpct}

\begin{document}
  \noindent The three little pigs built their houses
  out of straw\footnote{not to be confused with hay},
  sticks\footnote{or lumber according to some sources}
  and bricks\footnote{probably fired clay bricks}.

  % without `fnpct' for comparison:
  \setfnpct{dont-mess-around}\setcounter{footnote}{0}
  \noindent The three little pigs built their houses
  out of straw\footnote{not to be confused with hay},
  sticks\footnote{or lumber according to some sources}
  and bricks\footnote{probably fired clay bricks}.
\end{document}

enter image description here


The original answer:

The following code is an attempt using expl3. It uses the values of your answer to your related question: skip back .06em if a dot or comma follows else insert .06em.

\documentclass{article}

\renewcommand\familydefault{\sfdefault}
\usepackage{xparse}

\ExplSyntaxOn
% save definition of \footnote
\cs_new_eq:NN \fnpct_orig_footnote:w \footnote

% redefine \footnote
\RenewDocumentCommand \footnote { om }
  { \fnpct_dot_or_comma:nn { #1 } { #2 } }

% internal footnote function:
\cs_new:Npn \fnpct_dot_or_comma:nn #1#2
  {
    % if a dot follows remove it, insert dot, skip back
    % and then insert footnote
    \peek_meaning_remove:NTF .
      {
        . \skip_horizontal:n { -.06em }
        \IfNoValueTF { #1 }
          { \fnpct_orig_footnote:w { #2 } }
          { \fnpct_orig_footnote:w [ #1 ] { #2 } }
      }
      {
        % else do the same with comma
        \peek_meaning_remove:NTF ,
          {
            , \skip_horizontal:n { -.06em }
            \IfNoValueTF { #1 }
              { \fnpct_orig_footnote:w { #2 } }
              { \fnpct_orig_footnote:w [ #1 ] { #2 } }
          }
          {
            % else insert space and then footnote
            \skip_horizontal:n { .06em }
            \IfNoValueTF { #1 }
              { \fnpct_orig_footnote:w { #2 } }
              { \fnpct_orig_footnote:w [ #1 ] { #2 } }
          }
      }
  }
\ExplSyntaxOff

\setlength\textwidth{150pt}
\setlength\textheight{5\baselineskip}

\begin{document}

\noindent The three little pigs built their houses
out of straw\footnote{not to be confused with hay},
sticks\footnote{or lumber according to some sources} and
bricks\footnote{probably fired clay bricks}.

\end{document}
17
  • 1
    Should be made into a package BTW. fixfoot or something.
    – Christian
    Commented May 17, 2012 at 12:25
  • 1
    Wow, amazing! That package grew pretty fast and it even got a decent documentation and all. I'm impressed :) I'm sure to keep using this package and I'll contact you immediately when I notice something noteworthy. No news is good news I guess :)
    – Christian
    Commented May 22, 2012 at 22:10
  • 4
    This is amazing work! I almost can't keep up with looking at the changes. I would feel bad for having caused all this work for you if it wasn't for such an awesome result. Let us hope many people stumble upon this package and subtly improve the typesetting of their footnotes! This might also be the one footnote package. To configure them all and in the \setfnpct bind them. To show some gratitude, let me award you a post-hoc bounty :)
    – Christian
    Commented May 25, 2012 at 7:10
  • 1
    Thanks :) There'll be an update in a few days (I'm adding the possibility to add further punctuation marks to the automatism)
    – cgnieder
    Commented May 25, 2012 at 7:13
  • 1
    Sounds like a good idea :)
    – Christian
    Commented May 25, 2012 at 7:14
3

To achieve your goal, it seems that you have to hack into the \footnotecommand to check the previous character. I am not able to show you workable tex-code, but in the package footmisc Robin Fairbairns has coded an option called multiple. That option add a comma in between multiple footnote marks, in case you have multiple footnote at the same place. This implies that you have to know that the previous character is footnote mark. Maybe you can adapt the code for your purpose.

The code is commented under section 6.1 in the manual, and it is advanced ... I'm not a TeX-guru, and unable to decode the code.

Your link https://tex.stackexchange.com/a/10457/9632 gives answers to the question: Is it possibility to kern two character pairs in LaTeX. LuaLaTeX and fontspec seems to be the easiest solution. And in this answer; https://tex.stackexchange.com/a/53594/9632 ; you will find some luacode to adjust kerning on the fly.

On the other hand, maybe it is less work (but less fun) to do it manually, when you do the very last proofreading.

3
  • I don't understand the code either but it doesn't necessarily have to parse backwards – parsing forwards would do just as well. Your second link is one that refers to the first one and I can't figure out how to adapt this for my problem either :/
    – Christian
    Commented May 17, 2012 at 12:17
  • 1
    @Christian Sorry, this was the best I could come up with. My programming skills are very limited (i.e. nil). I tried, at least. =:-)
    – Sveinung
    Commented May 17, 2012 at 20:25
  • 1
    All ideas are welcome. You never know which ones work in advance. Oh and TeX is a nightmare of a language. I wouldn't judge my own programming skills to be nil but most advanced TeX packages look little better than /dev/random to me I must say.
    – Christian
    Commented May 18, 2012 at 10:14

You must log in to answer this question.

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