\ProvidesPackage{merriweather}[%
   2019/06/02 (Bob Tennent)  Supports Merriweather(Sans) fonts for all LaTeX engines. ] 

\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\ifmerriweather@ttf
\ifxetex
  \merriweather@ttftrue
\else\ifluatex
  \merriweather@ttftrue
\else  % [pdf]LaTeX
  \merriweather@ttffalse
\fi\fi

\newcommand*{\Merriweather@scale}{1}  % not adjustable
\newcommand*{\MerriweatherSans@scale}{1}
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\MerriweatherSans@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\MerriweatherSans@scale}{#1}}

\newif\ifmerriweather@rm \merriweather@rmfalse
\newif\ifmerriweather@sf \merriweather@sffalse
\newif\ifmerriweather@sfdefault \merriweather@sfdefaultfalse
\newif\ifmerriweather@rmlight \merriweather@rmlightfalse
\newif\ifmerriweather@sflight \merriweather@sflightfalse
\newif\ifmerriweather@rmblack \merriweather@rmblackfalse
\newif\ifmerriweather@sfblack \merriweather@sfblackfalse

\DeclareOptionX{sf}{\merriweather@sftrue}
\DeclareOptionX{rm}{\merriweather@rmtrue}
\DeclareOptionX{sfdefault}{\merriweather@sftrue\merriweather@sfdefaulttrue}
\DeclareOptionX{type1}{\merriweather@ttffalse}
\DeclareOptionX{light}{\merriweather@rmlighttrue\merriweather@sflighttrue}
\DeclareOptionX{rmlight}{\merriweather@rmlighttrue}
\DeclareOptionX{sflight}{\merriweather@sflighttrue}
\DeclareOptionX{black}{\merriweather@rmblacktrue\merriweather@sfblacktrue}
\DeclareOptionX{rmblack}{\merriweather@rmblacktrue}
\DeclareOptionX{sfblack}{\merriweather@sfblacktrue}

\ProcessOptionsX\relax

\ifmerriweather@ttf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes,mweights}
\fi

\ifmerriweather@rm\else\ifmerriweather@sf\else
  \merriweather@rmtrue\merriweather@sftrue  % both false -> both true
\fi\fi


% Set main and/or sans fonts:
\ifmerriweather@ttf

  \ifxetex\XeTeXtracingfonts=1\fi
  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .ttf ,
  }
  \ifmerriweather@rm
    \ifmerriweather@rmlight
      \ifmerriweather@rmblack
        \setmainfont
            [ UprightFont    = *-Light ,
              ItalicFont     = *-LightIt ,
              BoldFont       = *-UltraBold , 
              BoldItalicFont = *-UltraBdIt ]
            {Merriweather}
        \newfontfamily\merriweather
            [ UprightFont    = *-Light ,
              ItalicFont     = *-LightIt ,
              BoldFont       = *-UltraBold , 
              BoldItalicFont = *-UltraBdIt ]
            {Merriweather}
      \else
        \setmainfont
            [ UprightFont    = *-Light ,
              ItalicFont     = *-LightIt ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldIt ]
            {Merriweather}
        \newfontfamily\merriweather
            [ UprightFont    = *-Light ,
              ItalicFont     = *-LightIt ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldIt ]
            {Merriweather}
      \fi
    \else
      \ifmerriweather@rmblack
        \setmainfont
            [ UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-UltraBold , 
              BoldItalicFont = *-UltraBdIt ]
            {Merriweather}
        \newfontfamily\merriweather
            [ UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-UltraBold , 
              BoldItalicFont = *-UltraBdIt ]
            {Merriweather}
      \else
        \setmainfont
            [ UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldIt ]
            {Merriweather}
        \newfontfamily\merriweather
            [ UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldIt ]
            {Merriweather}
      \fi
    \fi
  \fi
  \ifmerriweather@sf
    \ifmerriweather@sflight
      \ifmerriweather@sfblack
        \setsansfont
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-ExtraBold , 
              BoldItalicFont = *-ExBoldIt ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-ExtraBold , 
              BoldItalicFont = *-ExBoldIt ]  
            {MerriweatherSans}
      \else
        \setsansfont
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
      \fi
    \else
      \ifmerriweather@sfblack
        \setsansfont
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-ExtraBold , 
              BoldItalicFont = *-ExBoldIt ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-ExtraBold , 
              BoldItalicFont = *-ExBoldIt ]  
            {MerriweatherSans}
      \else
        \setsansfont
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Scale     = \MerriweatherSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
      \fi
    \fi
  \fi
  % grab the \sfdefault in case it changes subsequently:
  \let\merriweathersffamily\sfdefault
  \ifmerriweather@sfdefault
     \renewcommand*\familydefault{\merriweathersffamily}
  \fi
  \newfontfamily\merriweatherlight
      [ UprightFont    = *-Light ,
        ItalicFont     = *-LightIt ,
        BoldFont       = *-Light , 
        BoldItalicFont = *-LightIt ]
      {Merriweather}
  \newfontfamily\merriweathersanslight
      [ Scale     = \MerriweatherSans@scale ,
        UprightFont    = *-Light ,
        ItalicFont     = *-LightItalic ,
        BoldFont       = *-Light ,
        BoldItalicFont = *-LightItalic ]  
      {MerriweatherSans}
  \newfontfamily\merriweatherblack
      [ UprightFont    = *-UltraBold ,
        ItalicFont     = *-UltraBdIt ,
        BoldFont       = *-UltraBold , 
        BoldItalicFont = *-UltraBdIt ]
      {Merriweather}
  \newfontfamily\merriweathersansblack
      [ Scale     = \MerriweatherSans@scale ,
        UprightFont    = *-ExtraBold ,
        ItalicFont     = *-ExBoldIt ,
        BoldFont       = *-ExtraBold ,
        BoldItalicFont = *-ExBoldIt ]  
      {MerriweatherSans}

\else % type1

  \ifmerriweather@rm
    \ifmerriweather@rmlight\def\mdseries@rm{light}\else\def\mdseries@rm{regular}\fi
    \ifmerriweather@rmblack\def\bfseries@rm{ultrabold}\else\def\bfseries@rm{bold}\fi
  \else
    \def\mdseries@rm{m}\def\bfseries@rm{b}
  \fi
  \ifmerriweather@sf
    \ifmerriweather@sflight\def\mdseries@sf{light}\else\def\mdseries@sf{regular}\fi
    \ifmerriweather@sfblack\def\bfseries@sf{extrabold}\else\def\bfseries@sf{bold}\fi
  \else
    \def\mdseries@sf{m}\def\bfseries@sf{b}
  \fi



  \def\merriweatherfamily{Merriweather-OsF}
  \def\merriweathersffamily{MerriweatherSans-OsF}

  \ifmerriweather@rm
    \renewcommand*\rmdefault{\merriweatherfamily}
  \fi

  \ifmerriweather@sf
    \renewcommand*\sfdefault{\merriweathersffamily}
  \fi

  \ifmerriweather@sfdefault
    \renewcommand*\familydefault{\merriweathersffamily}
  \fi
  
  \renewcommand*\seriesdefault{\mdseries@rm}

  \newcommand*\merriweather{\fontfamily{\merriweatherfamily}\selectfont}
  \newcommand*\merriweathersans{\fontfamily{\merriweathersffamily}\selectfont}
  \newcommand*\merriweatherlight{\fontfamily{\merriweatherfamily}\fontseries{light}\selectfont}
  \newcommand*\merriweathersanslight{\fontfamily{\merriweathersffamily}\fontseries{light}\selectfont}
  \newcommand*\merriweatherblack{\fontfamily{\merriweatherfamily}\fontseries{ultrabold}\selectfont}
  \newcommand*\merriweathersansblack{\fontfamily{\merriweathersffamily}\fontseries{extrabold}\selectfont}

\fi

% turn off defaults in case other fonts are selected:
\ifmerriweather@ttf
  \defaultfontfeatures{}
\fi

\endinput

