%%
%% 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-2024 Herbert Voss    <hvoss@tug.org>
%                     Rolf Niepraschk <Rolf.Niepraschk@gmx.de>
%%
\ProvidesPackage{xltabular}[2024/11/13 v0.2h `xltabular' package (hv,RN)]
\RequirePackage{tabularx}
\RequirePackage{etoolbox}
\let\XLT@i@tabularx=\tabularx
\let\XLT@i@endtabularx=\endtabularx
\let\XLT@i@TX@endtabularx=\TX@endtabularx
%
\RequirePackage{ltablex}
\keepXColumns% xltabular behaves like tabularx
%
\newif\ifXLT@normalPB \XLT@normalPBtrue
\newcommand*\normalLTpagebreak{\global\XLT@normalPBtrue}
\newcommand*\specialLTpagebreak{\global\XLT@normalPBfalse}
%
\let\XLT@ii@tabularx=\tabularx
\let\XLT@ii@TX@endtabularx=\TX@endtabularx
\let\XLT@longtable=\longtable
% prevents problematic behavior of longtable at page breaks (\XLT@normalPBfalse)
\patchcmd{\LT@start}{\vfil \break}{\ifXLT@normalPB \vfil \break \fi}{}{}
\patchcmd{\LT@start}{\penalty \z@}{\ifXLT@normalPB \penalty \z@ \fi}{}{}
\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}}

\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
%}

\endinput
%%
%% End of file `xltabular.sty'.

