\NeedsTeXFormat{LaTeX2e}


%Package to simplify loading of newpxmath with a text font family such as newpxtext for all latex engines, or for newpxtext and an otf math package.
\def\fileversion{1.536}
\def\filedate{2024/02/09}
\ProvidesPackage{newpx}[%
\filedate\space v\fileversion (Michael Sharpe) latex and unicode latex support for newpxmath and newpxtext, or for newpxtext and an otf math package]

\message{`newpx'v\fileversion,\space\filedate\space Integrated\space loading\space of\space newpxmath\space and\space a\space text\space font
\space for\space all\space latex\space engines\space (msharpe)}

\RequirePackage{fontenc,fontaxes}
\RequirePackage{ifthen,iftex,etoolbox,scalefnt,trimspaces}

\forcsvlist{\listadd\zpl@mathlst}{vecsep,amsthm,nosubscriptcorrection,subscriptcorrection,varbb,vvarbb,nosymbolsc,noamssymbols,amssymbols,uprightscript,uprightGreek,slantedGreek,frenchmath,upint,smallerops,useBImacros,varg,varvw,noOT1,fracspacing,subscriptcorrectionfile,curlybraces}

\RequirePackage{kvoptions}
\def\zpl@scale{1}
\def\newpx@helvratio{1}
\DeclareDefaultOption{
\xifinlist{\CurrentOptionKey}{\zpl@mathlst}
{% true branch for xifinlist
\expandafter\PassOptionsToPackage\expandafter{\CurrentOption}{newpxmath}}
{%  false branch for xifinlist
%\xdef\zpl@Topt{\zpl@Topt \CurrentOption,}
\expandafter\PassOptionsToPackage\expandafter%
{\CurrentOption}{newpxtext}}
\ifthenelse{\equal{scale}{\CurrentOptionKey} \OR \equal{scaled}{\CurrentOptionKey}}
{% true branch for ifthenelse
\xdef\zpl@scale{\CurrentOptionValue}
\xdef\npxmath@scaled{\CurrentOptionValue}
}{ % false branch for ifthenelse
\ifthenelse{\equal{helvratio}{\CurrentOptionKey}}
{% true branch
\xdef\newpx@helvratio{\CurrentOptionValue}
}{}}}
%\newif\ifzpl@otfmath %\zpl@otfmathfalse % default is type1 math
\DeclareBoolOption{otfmath}% creates and inits \ifnewpx@otfmath 
%{\@nameuse{if#1}\iftutex\zpl@otfmathtrue\fi\fi}
\DeclareBoolOption{nohelv}% creates and inits \ifnewpx@nohelv 
\DeclareBoolOption{nott}% creates and inits \ifnewpx@nott 

\DeclareBoolOption{type1}%[true]{}% no effect now
%{%\@nameuse{if#1}\zpl@otftextfalse\fi}

\DeclareBoolOption{type1text}%[true]{} %no effect now
%{% same as type1--use type1 for text
%\@nameuse{if#1}\zpl@otftextfalse\fi}

\DeclareBoolOption{nofontspec}%[true]{} % no effect
%{\@nameuse{if#1}\zpl@nofontspectrue\fi}

\ProcessKeyvalOptions{newpx}

\RequirePackage{xstring}% must load this after \@for
% Needed for \StrLeft and \StrRight

%Enginecheck
%iftex's \iftutex is true for LuaTeX and XeTeX
\newif\ifzpl@otftext
\iftutex\zpl@otftexttrue\fi 
%\def\zpl@Mopt{} % math options to pass
%\def\zpl@Topt{} % text options to pass

%\def\tx@divide#1#2{\strip@pt\dimexpr 1pt * (\dimexpr #1pt) / \dimexpr #2pt\relax\relax}
%\newcommand*{\zpltext@rm}{} % not understood by libertinus-otf
%\newcommand*{\zpltext@sf}{}% not understood by libertinus-otf



\def\zpl@dfltTF{newpxtext} % the default text font package name
\def\zpl@text{\let\zpl@TF=\zpl@dfltTF % the text font package name
\def\zpl@MF{newpxmath} 
%\def\zpl@id{0} % identifier for font properties
%\def\zpl@sc{zpl@scale} % macro name for scale factor in font package 
\def\zpl@minfam{zpltlf} %roman font, tabular lining fd, used in math
}
\zpl@text % set the defaults%

%\newcommand{\PassMathScale}{\ifzpl@iszero\gdef\zpltext@scale{\zplmath@scale}\gdef\zpltext@scaled{s*[\zpltext@scale]}\fi
%\PassOptionsToPackage{scaled=\zpltext@scale}{\zpl@TF}
%}
\ifnewpx@otfmath
\else % t1 math
   \ifthenelse{\not\equal{\sfdefault}{cmss}}%
      {\newpx@nohelvtrue}{}
    \ifthenelse{\not\equal{\ttdefault}{cmtt}}%
      {\newpx@notttrue}{}
    \ifnewpx@nohelv
    \else
      \renewcommand*{\sfdefault}{qhv}
      \@tempdima=\zpl@scale\p@
      \@tempdima=\newpx@helvratio\@tempdima%
      \edef\qhv@scale{\strip@pt\@tempdima}
%    \else
%      \PassOptionsToPackage{nohelv=true}{newtxtext}
    \fi
    \ifnewpx@nott\else%
      \renewcommand*{\ttdefault}{npxtt}
    \fi
%    \ifthenelse{\not\equal{\newpx@helvratio}{.94}}%
%      {\PassOptionsToPackage{helvratio=\newpx@helvratio}%
%      {newtxtext}}{}
%    \iftx@tt\else%
%      \PassOptionsToPackage{nott=true}{newtxtext}\fi

\fi
\ifzpl@otftext
  \ifnewpx@otfmath %
  \typeout{I}
    \usepackage[]{newpxtext} %may not load fontspec
    \usepackage{unicode-math} %loads amsmath
  \else %II: type1 math, otftext
  \typeout{II}
    \renewcommand*{\rmdefault}{\zpl@minfam} % Roman and Bold text for math
    \usepackage[]{newpxmath} % options will be as passed from newpx
    \usepackage[no-math]{fontspec}
    \usepackage{newpxtext}
  \fi %ifzpl@otfmath
  %\show\zpl@otftexttrue
\else % not otftext
  \typeout{IV}
% IV, type1 tex and math
    \renewcommand*{\rmdefault}{\zpl@minfam}% Roman and Bold for math
     \usepackage{newpxmath} % options will be as passed from newpx
    \usepackage{\zpl@TF} % should load tt and sans math before newpx
\fi



\endinput
