LaTeX / lectures / otagofonts.sty
\def\filedate{20 January 2023}
% Set up official Otago fonts based on what’s available. Fall back to close
% facsimiles where possible.
% Version History
% v1.0   Initial version, rebuilt from deprecated lecturecommon package.
% v1.1   Refactored font checking mechanism.
% v1.2   Fixed sans-serif scaling, added Noto Sans.

\ProvidesPackage{otagofonts}[2023/01/20 Otago standard fonts v1.2]

\RequirePackage{amsmath} % needs to be loaded before mathspec



% Try a few different fonts that are either the official Otago font, or a reasonable
% facsimile thereof. Effectively done via a bunch of nested ifs. I did try using
% etoolbox's list looping macros, but the tricky part was making it generic for all
% three categories of font (primary, sans, mono), and I could only successfully make
% work for the first one encountered. The set of fonts is limited, so this is OK.
% Note: Explicitly specify Mapping=tex-text only for the primary and sans fonts,
% otherwise curly quotes will automatically appear in the mono font. Since
% this is pretty much exclusively used for code listings, this is a bad thing.

% Primary font (body text, maths).
\PackageInfo{otagofonts}{Looking for suitable primary font}

    \PackageInfo{otagofonts}{Trying #1...}
        % The following line is equivalent to:
        %   \setmainfont{fontname}[options]
        %   \setmathsfont(Latin,Digits){fontname}
        %   \setmathrm{fontname}
        \PackageInfo{otagofonts}{Using #1 for primary font}%

\docsvlist{Minion Pro,Crimson Pro,Crimson Text,Times New Roman}

    % Hack to prevent digits in hyperlinks from being set in the main font instead of the mono font.
    % Note: doesn't matter if this is executed multiple times. Only works if you use \setprimaryfont
    % or \setmathsfont first. From
        Could not find any suitable primary font.\MessageBreak%
        Falling back to LaTeX default.\MessageBreak%
        Recommended fonts:\MessageBreak%
        \space\space Minion Pro (official, commercial)\MessageBreak%
        \space\space Crimson Pro (
        \space\space Crimson Text (

% Sans-serif font.
\PackageInfo{otagofonts}{Looking for suitable sans-serif font}

% font-specific defaults
\defaultfontfeatures[Open Sans Light]{BoldFont={Open Sans}}
\defaultfontfeatures[Noto Sans Light]{BoldFont={Noto Sans}}
\defaultfontfeatures[Roboto Light]{BoldFont={Roboto}}

    \PackageInfo{otagofonts}{Trying #1...}
        % Scale=Match{Upper|Lower}case doesn't work very well for the sans fonts.
        % By experimentation Scale=0.912 seems a good compromise, and eliminates the
        % weird upscaling of sans fonts in Texlive 2020, which didn't seem to affect
        % the serif or monospace fonts (?!?!).
        \PackageInfo{otagofonts}{Using #1 for sans-serif font}%

\docsvlist{Open Sans Light,Noto Sans Light,Roboto Light,Arial}

    \PackageWarning{otagofonts}{Could not find any suitable sans-serif font.\MessageBreak%
        Falling back to LaTeX default.\MessageBreak%
        Recommended fonts:\MessageBreak%
        \space\space Open Sans (\MessageBreak%
        \space\space Roboto (

% Monospaced font, mainly for code listings.
\PackageInfo{otagofonts}{Looking for suitable monospaced font}

% font-specific defaults
\defaultfontfeatures[Iosevka Light]{RawFeature={+ss03;-calt}}

    \PackageInfo{otagofonts}{Trying #1...}
        \PackageInfo{otagofonts}{Using #1 for monospaced font}%

\docsvlist{Iosevka Light,Letter Gothic 12 Pitch,Inconsolata}

    \PackageWarning{otagofonts}{Could not find any suitable monospaced font.\MessageBreak%
        Falling back to LaTeX default.\MessageBreak%
        Recommended fonts:\MessageBreak%
        \space\space Iosevka (, but complex!)\MessageBreak%
        \space\space Inconsolata (

\else % assume PDFLaTeX otherwise


    Otago-compatible fonts are not yet supported for LaTeX\MessageBreak%
    or PDFLaTeX. XeLaTeX is preferred%

% Gill Sans to come...
% \renewcommand{\sfdefault}{}
% \renewcommand{\ttdefault}{blg}