% Public repository entry for the IMPE template system.
% This wrapper anchors repository-local paths and then delegates to core.

\RequirePackage{expl3}
\RequirePackage{xparse}
\RequirePackage{import}
\RequirePackage{xstring}

% The 2026 tools bundle may call this latex-lab developer hook from array
% even when tagged-math support is not loaded. Keep ordinary tabular users
% working; latex-lab replaces this no-op definition when it is active.
\providecommand{\UseMathForPositioningText}{}

\makeatletter
\@ifundefined{ifNextSystemInstalled}
  {\newif\ifNextSystemInstalled\NextSystemInstalledfalse}
  {}
\providecommand{\NextSystemRoot}{}
\providecommand{\CurrentFilePath}{}
\ifNextSystemInstalled
  \xdef\NextSystemRoot{}
\else
  \ifx\CurrentFilePath\@empty
    \ifx\import@path\@undefined
      \xdef\NextSystemRoot{../}
    \else
      \StrBefore{\import@path}{package/}[\NextSystemRoot]
      \ifx\NextSystemRoot\@empty
        \edef\NextSystemRoot{\import@path}
      \fi
    \fi
  \else
    \StrBefore{\CurrentFilePath}{package/}[\NextSystemRoot]
    \ifx\NextSystemRoot\@empty
      \edef\NextSystemRoot{\CurrentFilePath}
      \IfEndWith{\NextSystemRoot}{/}{}{
        \edef\NextSystemRoot{\NextSystemRoot/}
      }
    \fi
  \fi
\fi
\makeatother

\providecommand{\CatalogFontRoot}{}
\NewDocumentCommand{\SetCatalogFontRoot}{m}
  {\def\CatalogFontRoot{#1}}
\ifNextSystemInstalled
  \InputIfFileExists{impe.local.tex}{}
    {\InputIfFileExists{nextsystem.local.tex}{}{}}
\fi

\makeatletter
\ifx\CatalogFontRoot\@empty
  \ifNextSystemInstalled
    \edef\CatalogFontRoot{assets/fonts}
  \else
    \ifx\import@path\@undefined
      \edef\CatalogFontRoot{../assets/fonts}
    \else
      \StrBefore{\import@path}{package/}[\CatalogFontRoot]
      \ifx\CatalogFontRoot\@empty
        \edef\CatalogFontRoot{\import@path}
      \fi
      \IfEndWith{\CatalogFontRoot}{/}{}{
        \edef\CatalogFontRoot{\CatalogFontRoot/}
      }
      \edef\CatalogFontRoot{\CatalogFontRoot assets/fonts}
      \StrSubstitute{\CatalogFontRoot}{ }{}[\CatalogFontRoot]
    \fi
  \fi
\fi
\makeatother

\ifNextSystemInstalled
  \input{core/system/impe-system-core.tex}
\else
  \subimport{../core/system/}{impe-system-core.tex}
\fi
