summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/platex-tools/pxftnright.sty
blob: 2b5d4382b410d60043d93779627735b97b4af890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%
% pxftnright.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the platex-tools bundle.
% https://github.com/aminophen/platex-tools
%
% This package `pxftnright' is based on:
%   * ftnright.sty in latex-tools (2014/10/28 v1.1f)
%
% Problems with ftnright to use with pLaTeX:
%   * \@startcolumn is redefined
%     (incompatible with vertical typesetting)
%   * \@makecol is redefined
%     (bottom float after footnote)
%   * \@makefntext is redefined
%     (incompatible with some pLaTeX classes)
%   * \footnotesep is not suitable for vertical typesetting
%     when used with pLaTeX 2016/11/29 or earlier
%     (rather a problem of \strutbox in pLaTeX2e kernel)
% so, this package provides patches.
%

\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxftnright}
  [2017/02/28 v1.1 footnote layout package for pLaTeX]

%% save \@makefntext definition from pLaTeX class
\@ifpackageloaded{ftnright}{%
  \PackageError{pxftnright}{%
    Package ftnright is already loaded!\MessageBreak
    Load pxftnright earlier}\@ehc
}{}
\let\pxftn@makefntext\@makefntext

%% load ftnright package
\RequirePackage{ftnright}

%% patches for ftnright to work fine with pLaTeX
%% This code is based on pLaTeX2e 2017/04/08 community ed.

\def\@startcolumn{%
 \ifx\@deferlist\@empty
   \global\@fcolmadefalse
   \global\@colroom\@colht
 \else
   \ifvoid\footins\else
     \ftn@amount\ht\footins
     \advance\ftn@amount\dp\footins
     \advance\ftn@amount\skip\footins
   \fi
   \global\advance\@colht-\ftn@amount
   \global\@colroom\@colht
   \@xstartcol
   \global\advance\@colht\ftn@amount
   \global\advance\@colroom\ftn@amount
 \fi
 \if@fcolmade
  \setbox\@cclv\box\@outputbox
  \@makecol
 \else
%%%%% change for pLaTeX (import from \@reinserts in plcore)
  \ifvoid\footins\else\insert\footins{%
    \iftbox\footins\tate\else\yoko\fi
    \unvbox\footins}\fi
%%%%%
 \fi}

\def\@makecol{%
%%%%% change for pLaTeX
  \setbox\@outputbox\box\@cclv
%%%%%
 \if@firstcolumn
  \if@twocolumn \else
    \ifvoid\footins \else
      \@latexerr{ftnright package
                 used in one-column mode}%
   {The ftnright package was designed to
    work with LaTeX's standard^^Jtwocolumn
    option. It does *not* work with the
    multicol package.^^JSo please specify
    `twocolumn' in the
    \noexpand\documentclass command.}%
      \shipout\box\footins \fi\fi
  \ifnum\insertpenalties>\z@
      \@latexerr{ftnright package
                 scrambled footnotes}%
    {There is too much footnote material in
     the first column  and ftnright^^Jis
     unable to cope with this.^^JYou need
     to reduce the amount to get a properly
     formatted page.}%
  \fi
 \fi
%%%%% change for pLaTeX (bottom float first)
  \xdef\@freelist{\@freelist\@midlist}%
  \global \let \@midlist \@empty
  \@combinefloats
  \let\pltx@textbottom\@textbottom %%% pLaTeX
 \if@firstcolumn\else
  \ifvoid\footins\else
    \setbox\@outputbox \vbox {%
      \boxmaxdepth \@maxdepth
      \unvbox \@outputbox
      \@textbottom %%% pLaTeX
      \vskip \skip\footins
      \color@begingroup
        \normalcolor
        \footnoterule
        \unvbox \footins
      \color@endgroup
      }%
      \let\@textbottom\relax %%% pLaTeX
  \fi
 \fi
%%%%%
  \ifvbox\@kludgeins
    \@makespecialcolbox
  \else
   \setbox\@outputbox\vbox to\@colht
     {\boxmaxdepth\maxdepth
      \@texttop
      \dimen@ \dp\@outputbox
      \unvbox \@outputbox
      \iftdir\vbox{\hskip\z@}\fi %%% pLaTeX
      \vskip -\dimen@
      \@textbottom}%
  \fi
  \let\@textbottom\pltx@textbottom %%% pLaTeX
  \global\maxdepth\@maxdepth
}

%% adjust \footnotesep for vertical typesetting
\AtBeginDocument
  {\global\footnotesep\ht\iftdir\tstrutbox\else\strutbox\fi}

%% restore \@makefntext
\let\@makefntext\pxftn@makefntext

\endinput