summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/xltabular/xltabular.sty
blob: 6752047c5e5b251319702a7e7e85b8cdb7cf7669 (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
%%
%% This file is distributed under the terms of the LaTeX Project Public
%% License from CTAN archives in directory  macros/latex/base/lppl.txt.
%% Either version 1.3 or, at your option, any later version.
%%
% Copyright 2018-2020 Herbert Voss    <hvoss@tug.org>
%                     Rolf Niepraschk <Rolf.Niepraschk@gmx.de>
%%
\ProvidesPackage{xltabular}[2020/11/04 v0.2e `xltabular' package (hv,RN)]
\RequirePackage{tabularx}
\let\XLT@i@tabularx=\tabularx
\let\XLT@i@endtabularx=\endtabularx
\let\XLT@i@TX@endtabularx=\TX@endtabularx
%
\RequirePackage{ltablex}
\keepXColumns% xltabular behaves like tabularx
%
\let\XLT@ii@tabularx=\tabularx
\let\XLT@ii@TX@endtabularx=\TX@endtabularx
\let\XLT@longtable=\longtable
\let\XLT@LT@start=\LT@start
\let\XLT@LT@array=\LT@array
\@ifundefined{scr@LT@array}{%
  \AtBeginDocument{%
    \@ifundefined{adl@LT@array}{}{\let\XLT@adl@LT@array=\adl@LT@array}
  }
}{\let\XLT@scr@LT@array=\scr@LT@array}%

%
% restore original tabularx
\renewenvironment{tabularx}%
{\let\TX@endtabularx=\XLT@i@TX@endtabularx\XLT@i@tabularx}
{\XLT@i@endtabularx}
%
% define a new tabularx like the one from "ltablex" 
%
\newenvironment{xltabular}[1][x]%
{%
  \par
  \if l#1%
    \LTleft\z@ \LTright\fill
  \else\if r#1%
    \LTleft\fill \LTright\z@
  \else\if c#1%
    \LTleft\fill \LTright\fill
  \fi\fi\fi
  \let\TX@endtabularx=\XLT@ii@TX@endtabularx
  \let\endtabularx\endxltabular
  \XLT@ii@tabularx}
{\def\@currenvir{tabularx}}

\def\LT@caption{%
  \noalign\bgroup
  \@ifnextchar[{\XLT@LT@caption}{\XLT@@LT@caption}
}
\def\XLT@LT@caption[#1]{%
  % increasing the counter only if opt. parameter is not empty
  \ifx\relax#1\relax\@tempswafalse\else\@tempswatrue\fi
  \XLT@@@LT@caption[#1]
}
\def\XLT@@LT@caption{% allways increasing the counter
  \@tempswatrue
  \XLT@@@LT@caption
}
\def\XLT@@@LT@caption{%
  % Eventually increasing the counter
  \if@tempswa\refstepcounter{\LTcaptype}\fi
  % global assignments because we are inside a group
  \global\let\@currentlabel=\@currentlabel
  \@ifundefined{cref@currentlabel}{}{% from package "cleveref"
    \global\let\cref@currentlabel=\cref@currentlabel
  }
  \ifXLT@HypRef
    % revert to the patched version
    \global\let\LT@start=\XLT@Hy@LT@start
    \hyper@makecurrent{\LTcaptype}%
    \global\let\Hy@LT@currentHref\@currentHref
  \fi
  % continue with the original definition of \LT@caption 
  \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n
}

%
\providecommand*\LTcaptype{table}% support of package "caption"
\def\longtable{%
  \ifXLT@HypRef
    % revert to the unpatched version if \caption is not used
    \global\let\LT@start=\XLT@LT@start
  \fi
  \XLT@longtable
}

\newif\ifXLT@HypRef
\AtBeginDocument{%
  \let\XLT@refstepcounter=\refstepcounter
  \@ifpackageloaded{hyperref}{\XLT@HypReftrue}{\XLT@HypReffalse}%
  \ifXLT@HypRef
    % save the patched version
    \let\XLT@Hy@LT@start=\LT@start
    % revert to the unpatched versions
    \@ifundefined{scr@LT@array}{%
      \@ifundefined{adl@LT@array}{%
        % hyperref has \LT@array patched directly
        \let\LT@array=\XLT@LT@array
      }{%
        % hyperref has \adl@LT@array patched, not \LT@array
        \let\adl@LT@array=\XLT@adl@LT@array
      }%
    }{%
      % hyperref has \scr@LT@array patched, not \LT@array
      \let\scr@LT@array=\XLT@scr@LT@array
    }%
  \fi
  \def\LT@array{%
    % make the call of \refstepcounter inside of \XLT@LT@array ineffective
    \renewcommand*\refstepcounter[2][]{%
      % make next calls effective again
      \let\refstepcounter=\XLT@refstepcounter
    }%
    \XLT@LT@array
  }%
}
%
\endinput
%%
%% End of file `xltabular.sty'.