Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the problem with this minimal example:

\documentclass{report}
\usepackage{zref-abspage}
\makeatletter
\newcounter{footdir@label}
\newtoks\footdir@toks
\newcommand*{\footdir@temp}[3]{%
  \@ifdefinable{#1}{%
    \let#1#2%
    \renewcommand{#2}[1]{%
      \footdir@toks{##1}%
      \footdir@toks\expandafter{%
        \the\expandafter\footdir@toks
        \expandafter
        \zref@labelbyprops\expandafter{\thefootdir@label}{abspage}%
      }%
      \expandafter#1\expandafter{\the\footdir@toks}%
    }%
  }%
}

\footdir@temp\footdir@ORG@footnotetext\@footnotetext{L}%
\makeatother
\begin{document}
Refer to first footnote\footnote{
Fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fillfillfillfi.
} refer to second footnote.\footnote{Another footnote.}


\end{document}

That the \footnoterule and the whole fisrt footnote moves up by one \par?

Edit

It seems that the issue is related to the macro \zref@labelbyprops which itself is related to \protec@write. Comment the line containing \reserved@a in the definition of \protected@write and the issue does not happen:

\documentclass{report}
\usepackage{zref-abspage}
\makeatletter

\long\def \protected@write#1#2#3{%
      \begingroup
       \let\thepage\relax
       #2%
       \let\protect\@unexpandable@protect
       \edef\reserved@a{\write#1{#3}}%
       %\reserved@a
      \endgroup
      \if@nobreak\ifvmode\nobreak\fi\fi
}


\newcounter{footdir@label}
\newtoks\footdir@toks
\newcommand*{\footdir@temp}[3]{%
  \@ifdefinable{#1}{%
    \let#1#2%
    \renewcommand{#2}[1]{%
      \footdir@toks{##1}%
      \footdir@toks\expandafter{%
        \the\expandafter\footdir@toks
        \expandafter
        \zref@labelbyprops{\thefootdir@label}{abspage}%
      }%
      \expandafter#1\expandafter{\the\footdir@toks}%
    }%
  }%
}

\footdir@temp\footdir@ORG@footnotetext\@footnotetext{L}%
\makeatother
\begin{document}
Refer to first footnote\footnote{
Fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fill fill fill fill fill fill fill
fill fill fill fillfillfillfi.
} refer to second footnote.\footnote{Another footnote.}


\end{document}
share|improve this question
    
You should eliminate the line break between the end of the first footnote and its terminating curly brace. –  Mico Jul 16 at 5:30
1  
...using % at the end of the line(s). See What is the use of percent signs (%) at the end of lines? –  Werner Jul 16 at 5:32
    
@Micro: Well, this does not happen with standard LaTeX footnotes. If you comment the code, then the issue does not happen. –  user56799 Jul 16 at 5:34
1  
@user56799: Immediately after the first opening brace { of the first \footnote and on the line ending before the closing brace } of the first \footnote. Without the use of % these lines add an additional space (sometimes referred to as a spurious space), making the line longer than is really necessary. In your particular case it was long enough to actually add a line-break at the end of the line, causing the visually separated footnotes. –  Werner Jul 16 at 5:38
1  
@user56799: Sure. Perhaps you could elaborate on what you're after exactly. That is, what do you want \footdir@temp to do with #1 and #2 and why there's not use for #3? –  Werner Jul 16 at 5:53

1 Answer 1

up vote 2 down vote accepted

When TeX typesets a paragraph, it removes space at the end of the last line: see for example TeX by Topic:

After the last element of the paragraph TeX implicitly inserts the equivalent of

\unskip \penalty10000 \hskip\parfillskip

With a footnote input such as

\footnote{
  Some text.
}

the result is that the space TeX adds for the end-of-line is removed before the footnote is set.

In your modified version, you have material after the end of the text. While it doesn't typeset anything in the output, it prevents the \unskip removing any trailing spaces. So your paragraph ends

<text> <space> <zref-code>

When TeX typesets that, if the length of the <text> is 'unfortunate' then the material added by zref will end up on a new line, which as it doesn't typeset anything is then empty. (Any 'invisible' commands are always tricky!)

Probably the most sensible solution is to add an \unskip and probably a \penalty to your code, e.g.

\newcommand*\footdir@aux{\unskip\penalty\@M}
\newcommand*{\footdir@temp}[3]{%
  \@ifdefinable{#1}{%
    \let#1#2%
    \renewcommand{#2}[1]{%
      \footdir@toks{##1}%
      \footdir@toks\expandafter{%
        \the\expandafter\footdir@toks
        \expandafter\footdir@aux\expandafter
        \zref@labelbyprops\expandafter{\thefootdir@label}{abspage}%
      }%
      \expandafter#1\expandafter{\the\footdir@toks}%
    }%
  }%
}

(I've put everything added into one macro to make the \expandafter chain a bit easier.)

At a technical level, \write operations add a 'whatsit': once these are added to material it's very tricky/impossible to do certain things. (One thing the LaTeX3 team have in experimental form is an approach to dealing with whatsits so they don't get added directly in 'uncontrolled' places for exactly this reason.)

share|improve this answer
    
You don't see the issue if your remove the \write (in your edit) as then there is no whatsit to worry about :-) –  Joseph Wright Jul 16 at 7:25
    
Note of course that each footnote is (with the standard set up) typeset as a paragraph from the TeX point of view. –  Joseph Wright Jul 16 at 7:28
    
Thanks Joseph. That explains it. –  user56799 Jul 16 at 7:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.