使用 TeX 解决方案在 LaTeX 中放置脚注

使用 TeX 解决方案在 LaTeX 中放置脚注

我如何使用LaTeX 中的 TeX 代码片段?

我想实现一个特定的脚注安排:

多行脚注后面的短段落脚注;如果脚注进入第二行,则防止脚注被分段

用户擦拭对这个问题给出了一个很好的答案---用 TeX 编写的。

我想在 LaTeX 文档中使用它。可以吗?如何操作?

(答案LaTeX 文档中的 TeX ?不要回答我的问题)。

答案1

我没有改动 wipet 的代码,只是把它添加到 latex 通常执行的位置,\unvbox\footins而不是普通 TeX 执行相同操作的位置。

在此处输入图片描述

\documentclass{article}

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

\tracingpages=1

\def\footnote{\global\advance\fnotenum by1 \fnmark\footnoteA}  
\def\footnoteA#1{\global\advance\specfootnum by1
   \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:

\textheight=120pt
\raggedbottom

\begin{document}


  Lorem ipsum dolor sit amet, consectetuer%
\footnote{First text.}
  adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,   
  adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu%
\footnote{Second text.}
  libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
  vehicula augue eu neque. Pellentesque habitant morbi tristique  
  senectus et netus et malesuada fames ac turpis egestas. Mauris ut  
  leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna%
\footnote{Third text.}
  fringilla ultrices.  Phasellus eu tellus sit amet tortor gravida  
  placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
  nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.  
  Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
  Curabitur auctor semper nulla. Donec varius orci eget risus. Duis%
\footnote{Next text.}
  nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis
  eget orci sit amet orci dignissim rutrum.

  Morbi auctor lorem non justo. Nam lacus%
\footnote{Nulla malesuada porttitor diam. Donec felis
erat, congue non, volutpat at, lobortis vitae, tincidunt tristique, libero.}
  libero, pretium at, lobortis vitae, ultricies et, tellus. Donec
  aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,%
\footnote{Short text.}
  vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit%
\footnote{Next short text.}
  mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla.%
\footnote{Intersting short text.}
  Cum sociis natoque penatibus et magnis dis parturient montes, 
  nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper
  vestibulum turpis. Pellentesque cursus luctus mauris.%
\footnote{The last footnote.}

\end{document}

相关内容