\ProvidesPackage{mweights}
  [2016/12/09 (Bob Tennent)  Support package for multiple-weight font packages. ]

\def\mweights@init{%
% Define any undefined \mdseries@rm etc. 
% Defined \mdseries@rm etc. assumed to be fully expanded!
\ifdefined\mdseries@rm\else\edef\mdseries@rm{\mddefault}\fi
\ifdefined\bfseries@rm\else\edef\bfseries@rm{\bfdefault}\fi
\ifdefined\mdseries@sf\else\edef\mdseries@sf{\mddefault}\fi
\ifdefined\bfseries@sf\else\edef\bfseries@sf{\bfdefault}\fi
\ifdefined\mdseries@tt\else\edef\mdseries@tt{\mddefault}\fi
\ifdefined\bfseries@tt\else\edef\bfseries@tt{\bfdefault}\fi
% In case any unexpanded macros present in \rmdefault, etc
\edef\rmdef@ult{\rmdefault}%
\edef\sfdef@ult{\sfdefault}%
\edef\ttdef@ult{\ttdefault}%
\edef\bfdef@ult{\bfdefault}%
\edef\mddef@ult{\mddefault}%
}

\DeclareRobustCommand\bfseries{%
\mweights@init
\not@math@alphabet\bfseries\mathbf
\ifx\f@family\rmdef@ult\fontseries\bfseries@rm
\else\ifx\f@family\sfdef@ult\fontseries\bfseries@sf
\else\ifx\f@family\ttdef@ult\fontseries\bfseries@tt
\else\fontseries\bfdefault\fi\fi\fi\selectfont}%

\DeclareRobustCommand\mdseries{%
\mweights@init
\not@math@alphabet\mdseries\relax
\ifx\f@family\rmdef@ult\fontseries\mdseries@rm
\else\ifx\f@family\sfdef@ult\fontseries\mdseries@sf
\else\ifx\f@family\ttdef@ult\fontseries\mdseries@tt
\else\fontseries\mddefault\fi\fi\fi\selectfont}

\DeclareRobustCommand\rmfamily{%
\mweights@init
\not@math@alphabet\rmfamily\mathrm
% change the current series before changing the family
\ifx\f@family\sfdef@ult
    \ifx\f@series\mdseries@sf\fontseries\mdseries@rm
    \else\ifx\f@series\bfseries@sf\fontseries\bfseries@rm
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@rm
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@rm
    \fi\fi\fi\fi
\else\ifx\f@family\ttdef@ult
    \ifx\f@series\mdseries@tt\fontseries\mdseries@rm
    \else\ifx\f@series\bfseries@tt\fontseries\bfseries@rm
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@rm
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@rm
    \fi\fi\fi\fi
\else\fontseries\mdseries@rm
\fi\fi\fontfamily\rmdefault\selectfont}

\DeclareRobustCommand\sffamily{%
\mweights@init
\not@math@alphabet\sffamily\mathsf
% change the current series before changing the family
\ifx\f@family\rmdef@ult
    \ifx\f@series\mdseries@rm\fontseries\mdseries@sf
    \else\ifx\f@series\bfseries@rm\fontseries\bfseries@sf
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@sf
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@sf
    \fi\fi\fi\fi
\else\ifx\f@family\ttdef@ult
    \ifx\f@series\mdseries@tt\fontseries\mdseries@sf
    \else\ifx\f@series\bfseries@tt\fontseries\bfseries@sf
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@sf
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@sf
    \fi\fi\fi\fi
\else\fontseries\mdseries@sf
\fi\fi\fontfamily\sfdefault\selectfont}

\DeclareRobustCommand\ttfamily{%
\mweights@init
\not@math@alphabet\ttfamily\mathtt
% change the current series before changing the family
\ifx\f@family\rmdef@ult
    \ifx\f@series\mdseries@rm\fontseries\mdseries@tt
    \else\ifx\f@series\bfseries@rm\fontseries\bfseries@tt
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@tt
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@tt
    \fi\fi\fi\fi
\else\ifx\f@family\sfdef@ult
    \ifx\f@series\mdseries@sf\fontseries\mdseries@tt
    \else\ifx\f@series\bfseries@sf\fontseries\bfseries@tt
    \else\ifx\f@series\mddef@ult\fontseries\mdseries@tt
    \else\ifx\f@series\bfdef@ult\fontseries\bfseries@tt
    \fi\fi\fi\fi
\else\fontseries\mdseries@tt
\fi\fi\fontfamily\ttdefault\selectfont}

\endinput
