

% ifxptex.sty
% Copyright 2017 Yue ZHANG
% License: Knuth License (https://ctan.org/license/knuth)

\csname ENDINPUTIFXPTEXDOTSTY\endcsname

\let\ENDINPUTIFXPTEXDOTSTY=\endinput

\begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname ProvidesPackage\endcsname\relax
  \else
    \ProvidesPackage{ifxptex}[2017/12/27 v0.2 Detect pTeX and its derivatives]%
  \fi

\edef\IFXPTEXDOTSTYRESTORECATCODE{\catcode`\noexpand\@=\the\catcode`\@\relax}

\catcode`\@=11\relax

\def\ifxptex@ifprimitive#1{%
  \begingroup
    \edef\ifxptex@temp@meaning{\meaning#1}%
    \edef\ifxptex@temp@string{\string#1}%
    \expandafter
  \endgroup
  \ifx\ifxptex@temp@meaning\ifxptex@temp@string}

\newif\ifxptex
\newif\ifxeptex
\newif\ifxuptex
\newif\ifxeuptex
\newif\ifxaptex

\ifxptex@ifprimitive \tate               \xptextrue  \fi
\ifxptex@ifprimitive \epTeXinputencoding \xeptextrue \fi
\ifxptex@ifprimitive \ucs                \xuptextrue \fi
\ifxptex@ifprimitive \ngbanner           \xaptextrue \fi

\newif\ifxpTeX
\newif\ifxepTeX
\newif\ifxupTeX
\newif\ifxeupTeX
\newif\ifxApTeX

\ifxptex
  \ifxaptex
    \xApTeXtrue
  \else
    \ifxuptex
      \ifxeptex
        \xeupTeXtrue\xeuptextrue
      \else
        \xupTeXtrue
      \fi
    \else
      \ifxeptex
        \xepTeXtrue
      \else
        \xpTeXtrue
      \fi
    \fi
  \fi
\fi

\newif\ifxuniuptex
\newif\ifxunieuptex

\newif\ifxUniupTeX
\newif\ifxUnieupTeX

\ifxuptex  \ifnum\ucs"3000="3000\relax \xuniuptextrue  \fi \fi
\ifxeuptex \ifnum\ucs"3000="3000\relax \xunieuptextrue \fi \fi

\ifxupTeX  \ifnum\ucs"3000="3000\relax \xUniupTeXtrue  \fi \fi
\ifxeupTeX \ifnum\ucs"3000="3000\relax \xUnieupTeXtrue \fi \fi

\def\ifxptex@newrequiretex@error#1{% can be easily redefined
  \errmessage{#1 is required}}

\def\ifxptex@newrequiretex#1#2{%
  \expandafter\def\csname RequireX#1\endcsname{%
    \relax
    \csname ifx#1\endcsname
    \else
      \ifxptex@newrequiretex@error{#2}%
    \fi}}

\ifxptex@newrequiretex{ptex}{pTeX / e-pTeX / upTeX / e-upTeX / ApTeX}
\ifxptex@newrequiretex{eptex}{e-pTeX / e-upTeX}
\ifxptex@newrequiretex{uptex}{upTeX / e-upTeX / ApTeX}
\ifxptex@newrequiretex{euptex}{e-upTeX}
\ifxptex@newrequiretex{aptex}{ApTeX}

\ifxptex@newrequiretex{pTeX}{pTeX}
\ifxptex@newrequiretex{epTeX}{e-pTeX}
\ifxptex@newrequiretex{upTeX}{upTeX}
\ifxptex@newrequiretex{eupTeX}{e-upTeX}
\ifxptex@newrequiretex{ApTeX}{ApTeX}

\ifxptex@newrequiretex{uniuptex}{Unicode upTeX / Unicode e-upTeX / ApTeX}
\ifxptex@newrequiretex{unieuptex}{Unicode e-upTeX}

\ifxptex@newrequiretex{UniupTeX}{Unicode upTeX}
\ifxptex@newrequiretex{UnieupTeX}{Unicode e-upTeX}

\IFXPTEXDOTSTYRESTORECATCODE

\endinput
