% \iffalse meta-comment
%
% Copyright (C) 2019-2023 by Jan Hajer
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse

%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{hep-math-font}[2025/09/01 v1.4 selection of math fonts for latin modern]
%<documentation>\ProvidesFile{hep-math-font-documentation.tex}[2025/09/01 v1.4 hep-math-Font documentation]
%
%<*documentation>
\documentclass{ltxdoc}

\renewcommand*\theCodelineNo{\rmfamily\tstyle\footnotesize\arabic{CodelineNo}}
\AtBeginEnvironment{macrocode}{\renewcommand*{\ttdefault}{clmt}}
\renewcommand*{\MacroFont}{\codestyle}
\AtBeginDocument{\DeleteShortVerb{\|}}
\AtBeginDocument{\MakeShortVerb{\"}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges

\usepackage{hologo}
\usepackage{fonttable}

\usepackage[parskip,oldstyle,font=10pt]{hep-paper}
\bibliography{bibliography}
\acronym{CM}{computer modern}
\acronym{LM}{latin modern}
\acronym{NFSS}{new font selection scheme}
\acronym{PU}{PDF Unicode}
\acronym{TU}{\hologo{TeX} Unicode}
\acronym{LGR}{local Greek}
%</documentation>

%<*driver>
\expandafter\newif\csname ifshort\endcsname
\shortfalse
\begin{document}
\DocInput{hep-math-font-implementation.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{698}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2021/09/01}{Initial version of the style file.}
% \changes{v1.1}{2022/11/01}{Bug fixes.}
% \changes{v1.2}{2023/07/01}{Bug fixes.}
% \changes{v1.3}{2024/11/01}{Bug fixes.}
% \changes{v1.4}{2025/09/01}{Bug fixes.}
%
% \ifshort
%<*documentation>
% \fi
%
\GetFileInfo{hep-math-font.sty}

\title{The \software{hep-math-font} package\thanks{This document corresponds to \software{hep-math-font}~\fileversion.}}
\subtitle{Extended Greek and sans-serif math}
\author{Jan Hajer \email{jan.hajer@tecnico.ulisboa.pt}}
\date{\filedate}

% \ifshort
\begin{document}
% \fi

\newgeometry{vscale=.8, vmarginratio=3:4, includeheadfoot, left=11em, marginparwidth=4.6cm, marginparsep=3mm, right=7em}

\maketitle

\begin{abstract}
The \software{hep-math-font} package adjust the math fonts to be italic sans-serif if the document is sans-serif.
Additionally Greek letters are redefined to be always italic and upright in math and text mode, respectively.
Some math font macros are adjusted to give more consistently the naively expected results.
\end{abstract}

The package is loaded using "\usepackage{hep-math-font}".

If the document "\familydefault" font is switched to the sansserif "\sfdefault" font the math font is adjusted accordingly using fonts compatible to \LM and \CM.
\DescribeMacro{warning}
In order to be able to easily switch large chucks of math from serif to sans-serif documents the meaning of "\mathrm" and "\mathsf" is adjusted in this case so that the first generates upright sans-serif math and the second serif math.
This is is neither the literal meaning of the macros nor the best behaviour if a single large document is written in sans-serif.
However, it simplifies working in an environment where one copies pieces of math between serif and sans-serif documents \eg publications \vs talks and funding applications.

Using the \software{fixmath} \cite{fixmath} and \software{textalpha} \cite{textalpha} packages Greek letter are adjusted so that they are always italic and upright in math and text mode, respectively.
Greek letters can be written by using their unicode characters, with code following the \software{alphabeta} package \cite{alphabeta}.

\DescribeMacro{symbols}
The "symbols"=\meta{family} class option sets the family of the symbol fonts.
"symbols=ams" loads the two \hologo{AmS} fonts \cite{amsfonts} and the \software{bm} bold fonts.
The default "symbols=true" replaces additionally the blackboard font with the \software{dsfont} \cite{dsfont}.
"symbols=minion" switches the symbol fonts to the Adobe MinionPro companion font from the \software{MnSymbol} package \cite{MnSymbol}.
"symbols=false" deactivates loading any additional symbol fonts, effectively restricting the package to only switch the math font according to the sans-serif property of the main text.

\section{Macros}

\DescribeMacro{\text}
\DescribeMacro{\mathrm}
The "\mathrm"\marg{math}  macro and the "\text"\marg{text} macro from \software{amstext} \cite{amstext} are adjusted to produce upright Greek letters, \ie ($ \text A  \text b  \text \Gamma \text \delta \text{\textbf A} \text{\textbf b} \text{\textbf \Gamma} \text{\textbf \delta}$), by adjusting the code from the \software{alphabeta} \cite{alphabeta} package.

\DescribeMacro{\mathbf}
Bold math, via "\mathbf" is improved with the \software{bm} package \cite{bm}, \ie ($ A  b  \Gamma \delta \mathbf A \mathbf b \mathbf \Gamma \mathbf \delta$).
Macros switching to "bfseries" such as "\section"\marg{text} are ensured to also typeset math in bold.

\DescribeMacro{\mathsf}
The math sans-serif alphabet is redefined to be italic sans-serif if the main text is serif and italic serif if the main text is sans-serif, \ie ($\mathsf A \mathsf b \mathsf \Gamma \mathsf \delta \mathbf{\mathsf A} \mathbf{\mathsf b} \mathbf{\mathsf \Gamma} \mathbf{\mathsf \delta}$).
Ensuring that the distinction between these fonts is also kept if the \prefix{sans}{serif} option of the document is switched.

\DescribeMacro{\mathscr}
The "\mathcal" font \ie ($\mathcal{ABCD}$) is accompanied by the "\mathscr" font \ie ($\mathscr{ABCD}$).

\DescribeMacro{\mathbb}
The "\mathbb" font is improved by the \software{doublestroke} package \cite{dsfont} and adjusted depending on the \prefix{sans}{serif} option of the document \ie ($\mathbb{Ah1}$).

\DescribeMacro{\mathtt}
The "\mathtt" macro switches to \LM typewriter font \ie ($\mathtt A \mathtt b \mathtt \Gamma \mathbf{\mathtt A} \mathbf{\mathtt b} \mathbf{\mathtt \Gamma}$).

\DescribeMacro{\mathfrak}
Finally, the "\mathfrak" font is also available \ie ($\mathfrak{AaBb12}$).

Details about the font handling in \hologo{TeX} can be found in \ccite{fntguide}.

\section{Math alphabet allocation} \label{sec:allocation}

\bgroup
\makeatletter
\renewcommand*{\arraystretch}{0}
\setlength{\tabcolsep}{0pt}
\nodecimals
\nohexoct
\fntcolwidth=0pt
\setlength\arrayrulewidth{0pt}

\begin{figure}
\begin{panels}[t]{4}
\fonttable{rm-\ifhepmathfont@serif lmr\else lmss\fi10}
\caption{Text}
\panel
\fontrange{0}{127}
\fonttable{\ifhepmathfont@serif lm\else cmss\fi mi10}
\caption{Math}\vspace{2ex}
\fonttable{\ifhepmathfont@serif lm\else cmss\fi sy10}
\caption{Symbol}
\panel
\fontrange{0}{127}
\fonttable{\ifhepmathfont@serif\else ss\fi msam10}
\caption{AMS a}\vspace{2ex}
\fontrange{0}{79}
\fonttable{\ifhepmathfont@serif\else ss\fi msbm10}
\fontrange{96}{127}
\fonttable{\ifhepmathfont@serif\else ss\fi msbm10}
\caption{AMS b}
\panel
\fontrange{0}{8}
\fonttable{eufm10}
\fontrange{32}{127}
\fonttable{eufm10}
\caption{Euler fraktur}\vspace{2ex}
\fontrange{64}{95}
\fonttable{eusm10}
\caption{Euler caligraphy}\vspace{2ex}
\fonttable{MnSymbolS10}
\caption{Minion caligraphy}\vspace{2ex}
\fonttable{ds\ifhepmathfont@serif rom\else ss\fi10}
\caption{Doublestroke}
\end{panels}
\caption{Basic math fonts}
\end{figure}

\begin{figure}
\hspace*{-2cm}%
\begin{panels}[t]{.3}
\fontrange{0}{127}
\fonttable{cm\ifhepmathfont@serif\else ss\fi ex10}
\caption{Computer modern}
\panel{.22}
\fontrange{0}{143}
\fonttable{MnSymbolE5}
\caption{Mn Symbol E 1}
\panel{.6}
\fontrange{144}{215}
\fonttable{MnSymbolE5}
\caption{Mn Symbol E 2}\vspace{2ex}
\begin{minipage}{.48\linewidth}
\fontrange{0}{127}\fonttable{MnSymbolF10}
\caption{Mn Symbols F}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\fontrange{0}{47}\fonttable{\ifhepmathfont@serif\else ss\fi esint10}
\caption{Extended set of integrals}
\end{minipage}
\end{panels}
\caption{Math extension fonts}
\end{figure}

\begin{figure}
\begin{panels}[t]{.26}
\fonttable{MnSymbolA10}
\caption{Mn Symbol A}
\panel{.26}
\fonttable{MnSymbolB10}
\caption{Mn Symbol B}
\panel{.26}
\fonttable{MnSymbolC10}
\caption{Mn Symbol C}
\panel{.2}
\fonttable{MnSymbolD10}
\caption{Mn Symbol D}
\end{panels}
\makeatother
\caption{Minion symbol fonts}
\end{figure}
\egroup

Of the 16 available math alphabets, \hologo{TeX} loads four by default
\begin{enumdescript}[start=0,label=\arabic*)]
\item{OT1} \label{it:math text} Text (latin, upper case greek, numerals, text symbols)

The text font \ref{it:math text}\strut\ of \CM is \textbf{cmr10} "\OT1/cmr/m/n/10", which is replaced by \LM to be \textbf{rm-lmr10} "\OT1/lmr/m/n/10", the "sansserif" option uses \textbf{rm-lmss10} "\OT1/lmss/m/n/10".
\item{OML} \label{it:math italic} Math Italic (latin, greek, numerals, text symbols)

The italic math font \ref{it:math italic} of \CM is \textbf{cmmi10} "\OML/cmm/m/it/"\allowbreak"10", and is replaced by \LM to be \textbf{lmmi10} "\OML/lmm/m/it/10", the "sansserif" options uses \textbf{cmssmi10} "\OML/cmssrm/m/it/10" from the \software{sansmathfonts} package \cite{sansmathfonts}.
\item{OMS} \label{it:math symbol} Symbol ("\mathcal", operators)

The symbol font \ref{it:math symbol}\strut\ of \CM is \textbf{cmsy10} "\OMS/cmsy/m/n/10", and is replaced by \LM to be \textbf{lmsy10} "\OMS/lmsy/m/n/10", the "sansserif" options uses \textbf{cmsssy10} "\OMS/cmsssy/m/n/10" from the \software{sansmathfonts} package \cite{sansmathfonts}.
\item{OMX} \label{it:math extension} Math Extension (big operators, delimiters)

The extension font \ref{it:math extension}\strut\ of \CM is \textbf{cmex10} "\OMX/cmex/m/n/5", and is replaced by the \software{exscale} package \cite{exscale} to be \textbf{cmex10} "\OMX/cmex/m/n/10", the "sansserif" option loads \textbf{cmssex10} "\OMX/cmssex/m/n/10".
\end{enumdescript}

The \software{amssymb} (\software{amsfonts}) packages \cite{amssymb} load two more symbol fonts
\begin{enumdescript}[start=4,label=\arabic*)]
\item{msam10} \label{it:math ams a} "\U/msa/m/n/10" AMS symbol font A (special math operators)
\item{msbm10} \label{it:math ams b} "\U/msb/m/n/10" AMS symbol font B ("\mathbb", negated operators)
\end{enumdescript}
The "sansserif" option replaces them with \textbf{ssmsam10} "\U/ssmsa/m/n/10" and \textbf{ssmsbm10} "\U/ssmsb/m/n/10" from the \software{sansmathfonts} package \cite{sansmathfonts}, respectively.

The \software{bm} package \cite{bm} loads the bold version for the fonts \labelcref{it:math text,it:math italic,it:math symbol}.

Other math alphabets are only loaded on demand, \eg "\mathsf" uses a sans-serif font and "\mathbf" without the \software{bm} package uses a bold font.
The "\mathscr" macro uses the script font from the \software{mathrsfs} package \cite{mathrsfs}
\begin{enumdescript}[start=9,label=\arabic*)]
\item{rsfs10} "\U/rsfs/m/n/10" Math script font (capital letters)
\end{enumdescript}
The "\mathbb" macro loads the double stroke font from the \software{dsfont} package \cite{dsfont}, this can be prevented with the "symbols=ams" option.
\begin{enumdescript}[start=10,label=\arabic*)]
\item{dsrom10} "\U/dsrom/m/n/10" Double stroke font
\end{enumdescript}
The "\mathfrak" macro loads the fractur font from the \software{amssymb} package \cite{amssymb}
\begin{enumdescript}[start=11,label=\arabic*)]
\item{eufm10} "\U/euf/m/n/10" Math fraktur (Basic Latin)
\end{enumdescript}

The \software{hep-math-font} package uses nine of the available 16 math alphabets.
This number can be reduced by three using "\newcommand{\bmmax}{0}" from the \software{bm} package \cite{bm} and brought down to the default of four with the option "symbols=false".

The "symbols=minion" options replaces the fonts \labelcref{it:math symbol,it:math extension,it:math ams a,it:math ams b} with corresponding fonts from the \software{MnSymbol} package \cite{MnSymbol}.
Additionally, two more symbol alphabets are allocated, the \software{bm} package \cite{bm} loads one more font and now "\mathcal" triggers the use of one additional alphabet.
Hence, the minion option uses three to four more math alphabets than a usual setup.

% \ifshort
\printbibliography

\end{document}
%
%</documentation>
% \fi
%
% \StopEventually{
% \printbibliography
% \PrintChanges
%}
%
% \appendix
%
% \section{Implementation}
%
%<*package>
%
% Use the \software{kvoptions} package \cite{kvoptions}.
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
  family=hepmathfont,
  prefix=hepmathfont@
}
%    \end{macrocode}
%
% \begin{macro}{symbols}
% Provide the "symbols" option allowing to switch the symbol font.
%    \begin{macrocode}
\DeclareStringOption[true]{symbols}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ProcessKeyvalOptions*
%    \end{macrocode}
%
% Define conditionals based on the "symbols" package option using the \software{pdftexcmds} package \cite{pdftexcmds}.
%    \begin{macrocode}
\RequirePackage{pdftexcmds}
\newif\ifhepmathfont@symbols
\ifnum
  \pdf@strcmp{\hepmathfont@symbols}{false}=0
\else
  \hepmathfont@symbolstrue
\fi
\newif\ifhep@ams
\ifnum\pdf@strcmp{\hepmathfont@symbols}{ams}=0 \hep@amstrue\fi
\newif\ifhep@minion
\ifnum\pdf@strcmp{\hepmathfont@symbols}{minion}=0 \hep@miniontrue\fi
%    \end{macrocode}
% Check if document is set to sans-serif using the \software{xstring} package \cite{xstring}.
%    \begin{macrocode}
\newif\ifhepmathfont@serif
\RequirePackage{xstring}
\IfStrEq{\familydefault}{\sfdefault}{%
  \hepmathfont@seriffalse}{\hepmathfont@seriftrue%
}
%    \end{macrocode}
%
% \subsection{Lualatex}
%
% Check for Lualatex using the \software{iftex} package \cite{iftex}.
%    \begin{macrocode}
\RequirePackage{iftex}
\iftutex
%    \end{macrocode}
% Load the \software{unicode-math} package \cite{unicode-math}.
%    \begin{macrocode}
  \AtBeginDocument{
    \let\mathbf\symbf
    \let\mathrm\symup
    \let\mathsf\symsf
    \let\mathbfrm\symbfup
    \let\mathbfsf\symbfsf
  }
%    \end{macrocode}
% Unicode implementation of Greek letters.
%    \begin{macrocode}
  \AtBeginDocument{
    \renewcommand*{\Gamma}{Γ}
    \renewcommand*{\Delta}{Δ}
    \renewcommand*{\Lambda}{Λ}
    \renewcommand*{\Phi}{Φ}
    \renewcommand*{\Pi}{Π}
    \renewcommand*{\Psi}{Ψ}
    \renewcommand*{\Sigma}{Σ}
    \renewcommand*{\Theta}{Θ}
    \renewcommand*{\Upsilon}{Υ}
    \renewcommand*{\Xi}{Ξ}
    \renewcommand*{\Omega}{Ω}
    \renewcommand*{\alpha}{α}
    \renewcommand*{\beta}{β}
    \renewcommand*{\gamma}{γ}
    \renewcommand*{\delta}{δ}
    \renewcommand*{\epsilon}{ε}
    \renewcommand*{\zeta}{ζ}
    \renewcommand*{\eta}{η}
    \renewcommand*{\theta}{θ}
    \renewcommand*{\iota}{ι}
    \renewcommand*{\kappa}{κ}
    \renewcommand*{\lambda}{λ}
    \renewcommand*{\mu}{μ}
    \renewcommand*{\nu}{ν}
    \renewcommand*{\xi}{ξ}
    \renewcommand*{\pi}{π}
    \renewcommand*{\rho}{ρ}
    \renewcommand*{\sigma}{σ}
    \renewcommand*{\varsigma}{ς}
    \renewcommand*{\tau}{τ}
    \renewcommand*{\upsilon}{υ}
    \renewcommand*{\phi}{φ}
    \renewcommand*{\chi}{χ}
    \renewcommand*{\psi}{ψ}
    \renewcommand*{\omega}{ω}
  }
%    \end{macrocode}
%
% \subsection{PdfLatex}
%
%    \begin{macrocode}
\else
%    \end{macrocode}
%
% \subsubsection{Serif}
%
%    \begin{macrocode}
  \newcommand*\mathbfrm[1]{\mathbf{\mathrm{#1}}}
  \newcommand*\mathbfsf[1]{\mathbf{\mathsf{#1}}}
%    \end{macrocode}
%
% If the "sansserif" package option is active use code adjusted from the \software{sansmathfonts} package \cite{sansmathfonts}.
% Ensure that "\mathsf" is italic as well as sans-serif and sans for sans and sans-serif documents, respectively.
%    \begin{macrocode}
  \ifhepmathfont@serif
%    \end{macrocode}
% \begin{macro}{\mathsf}
% Declare "\mathsf" for serif documents.
%    \begin{macrocode}
    \newcommand*\hep@font@sf{cmssm}
    \DeclareMathAlphabet{\mathsf}{OML}{\hep@font@sf}{m}{it}
    \SetMathAlphabet{\mathsf}{bold}{OML}{\hep@font@sf}{b}{it}
    \newcommand*\hep@textfont@sf{lmss}
    \DeclareMathAlphabet{\mathsftext}{OT1}{\hep@textfont@sf}{m}{n}
    \SetMathAlphabet{\mathsftext}{bold}{OT1}{\hep@textfont@sf}{bx}{n}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Sans serif}
%
% Define fonts for sans-serif documents.
%    \begin{macrocode}
  \else
%    \end{macrocode}
%    \begin{macrocode}
    \newcommand*\hep@font@sf{lmr}
    \newcommand*\hep@font@text{lmss}
    \newcommand*\hep@font@math{cmssm}
    \newcommand*\hep@font@symbol{cmsssy}
    \newcommand*\hep@font@extra{cmssex}
%    \end{macrocode}
% Declare font substitutions.
%    \begin{macrocode}
    \DeclareFontSubstitution{OML}{\hep@font@math}{m}{it}
    \ifhepmathfont@symbols\ifhep@minion\else
      \DeclareFontSubstitution{OMS}{\hep@font@symbol}{m}{n}
      \DeclareFontSubstitution{OMX}{\hep@font@extra}{m}{n}
    \fi\fi
%    \end{macrocode}
% Declare the symbol fonts.
%    \begin{macrocode}
    \DeclareSymbolFont{operators}{OT1}{\hep@font@text}{m}{n}
    \DeclareSymbolFont{letters}{OML}{\hep@font@math}{m}{it}
    \ifhepmathfont@symbols\ifhep@minion\else
      \DeclareSymbolFont{symbols}{OMS}{\hep@font@symbol}{m}{n}
      \DeclareSymbolFont{largesymbols}{OMX}{\hep@font@extra}{m}{n}
    \fi\fi
%    \end{macrocode}
% Set bold symbol fonts.
%    \begin{macrocode}
    \SetSymbolFont{operators}{bold}{OT1}{\hep@font@text}{b}{n}
    \SetSymbolFont{letters}{bold}{OML}{\hep@font@math}{b}{it}
    \ifhepmathfont@symbols\ifhep@minion\else
      \SetSymbolFont{symbols}{bold}{OMS}{\hep@font@symbol}{b}{n}
    \fi\fi
%    \end{macrocode}
% Adjust the fonts loaded by the \software{amsfonts} \cite{amsfonts} and \software{esint} \cite{esint} packages.
%    \begin{macrocode}
    \ifhepmathfont@symbols\ifhep@minion\else
      \DeclareSymbolFont{AMSa}{U}{ssmsa}{m}{n}
      \DeclareSymbolFont{AMSb}{U}{ssmsb}{m}{n}
    \fi\fi
    \ifhepmathfont@symbols\RequirePackage{alphabeta}\fi %fix compilation error
    \AtBeginDocument{%
      \@ifpackageloaded{esint}{%
        \DeclareSymbolFont{largesymbolsA}{U}{ssesint}{m}{n}
      }{}
    }
%    \end{macrocode}
% \begin{macro}{\mathrm}
% \begin{macro}{\mathnormal}
% \begin{macro}{\mathcal}
% Declare the symbol font alphabets.
%    \begin{macrocode}
    \DeclareSymbolFontAlphabet{\mathrm}{operators}
    \DeclareSymbolFontAlphabet{\mathnormal}{letters}
    \ifhep@minion\else
      \DeclareSymbolFontAlphabet{\mathcal}{symbols}
    \fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\mathit}
% Declare "\mathit".
%    \begin{macrocode}
    \DeclareMathAlphabet{\mathit}{OML}{\hep@font@text}{m}{it}
    \SetMathAlphabet\mathit{bold}{OML}{\hep@font@text}{bx}{it}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\mathsf}
% Declare "\mathsf" for sans-serif documents to produce serif.
%    \begin{macrocode}
    \DeclareMathAlphabet{\mathsf}{OML}{\hep@font@sf}{m}{it}
    \SetMathAlphabet{\mathsf}{bold}{OML}{\hep@font@sf}{bx}{it}
%    \end{macrocode}
% \end{macro}
% End of "sansserif".
%    \begin{macrocode}
  \fi
%    \end{macrocode}
%
% \subsection{Greek letters}
%
% Load the \software{fixmath} \cite{fixmath} and \software{alphabeta} \cite{alphabeta} packages ensuring that upper Greek letters in math mode are italic and providing upright Greek letters in text mode, respectively.
%    \begin{macrocode}
  \ifhepmathfont@symbols
    \RequirePackage{amssymb}
    \RequirePackage{amstext}
    \RequirePackage{fixmath}
    \RequirePackage{alphabeta}
%    \end{macrocode}
% Define the "hep@greek" macro ensuring that both "\text" and "\mathrm" produce upright Greek letters using the \software{amssymb} \cite{amssymb} and \software{amstext} \cite{amstext} packages.
%    \begin{macrocode}
    \newcommand*\hep@greek[2]{%
      \TextOrMath{#1}{\ifnum\fam=0 \text{#1}\else#2\fi}%
    }
    \AtBeginDocument{
      \renewcommand*{\alpha}{\hep@greek{\textalpha}{\mathalpha}}
      \renewcommand*{\beta}{\hep@greek{\textbeta}{\mathbeta}}
      \renewcommand*{\gamma}{\hep@greek{\textgamma}{\mathgamma}}
      \renewcommand*{\delta}{\hep@greek{\textdelta}{\mathdelta}}
      \renewcommand*{\epsilon}{\hep@greek{\textepsilon}{\mathepsilon}}
      \renewcommand*{\zeta}{\hep@greek{\textzeta}{\mathzeta}}
      \renewcommand*{\eta}{\hep@greek{\texteta}{\matheta}}
      \renewcommand*{\theta}{\hep@greek{\texttheta}{\maththeta}}
      \renewcommand*{\iota}{\hep@greek{\textiota}{\mathiota}}
      \renewcommand*{\kappa}{\hep@greek{\textkappa}{\mathkappa}}
      \renewcommand*{\lambda}{\hep@greek{\textlambda}{\mathlambda}}
      \renewcommand*{\mu}{\hep@greek{\textmu}{\mathmu}}
      \renewcommand*{\nu}{\hep@greek{\textnu}{\mathnu}}
      \renewcommand*{\xi}{\hep@greek{\textxi}{\mathxi}}
      \renewcommand*{\pi}{\hep@greek{\textpi}{\mathpi}}
      \renewcommand*{\rho}{\hep@greek{\textrho}{\mathrho}}
      \renewcommand*{\sigma}{\hep@greek{\textsigma}{\mathsigma}}
      \renewcommand*{\finalsigma}{\hep@greek{\textfinalsigma}{\mathvarsigma}}
      \renewcommand*{\tau}{\hep@greek{\texttau}{\mathtau}}
      \renewcommand*{\upsilon}{\hep@greek{\textupsilon}{\mathupsilon}}
      \renewcommand*{\phi}{\hep@greek{\textphi}{\mathphi}}
      \renewcommand*{\chi}{\hep@greek{\textchi}{\mathchi}}
      \renewcommand*{\psi}{\hep@greek{\textpsi}{\mathpsi}}
      \renewcommand*{\omega}{\hep@greek{\textomega}{\mathomega}}
      \renewcommand*{\digamma}{\hep@greek{\textdigamma}{\mathdigamma}}
      \renewcommand*{\varpi}{\hep@greek{\textpisymbol}{\mathvarpi}}
      \renewcommand*{\varrho}{\hep@greek{\textrhosymbol}{\mathvarrho}}
      \renewcommand*{\rhosymbol}{\hep@greek{\textrhosymbol}{\mathvarrho}}
      \renewcommand*{\vartheta}{\hep@greek{\textthetasymbol}{\mathvartheta}}
      \renewcommand*{\varepsilon}{\hep@greek{\textepsilon}{\mathvarepsilon}}
      \renewcommand*{\epsilonsymbol}{%
        \hep@greek{\textepsilonsymbol}{\mathepsilon}%
      }
      \renewcommand*{\varphi}{\hep@greek{\textphi}{\mathvarphi}}
      \renewcommand*{\phisymbol}{\hep@greek{\textphisymbol}{\mathphi}}
      \ifdefined\mathvarbeta
        \renewcommand*{\varbeta}{\hep@greek{\textbetasymbol}{\mathvarbeta}}
      \else
        \renewcommand*{\varbeta}{\textbetasymbol}
      \fi
      \ifdefined\mathvarkappa
        \renewcommand*{\varkappa}{\hep@greek{\textkappasymbol}{\mathvarkappa}}
      \else
        \renewcommand*{\varkappa}{\textkappasymbol}
      \fi
      \ifdefined\mathvarTheta
        \renewcommand*{\varTheta}{\hep@greek{\textTheta}{\mathvarTheta}}
      \else
        \renewcommand*{\varTheta}{\textTheta}
      \fi
      \renewcommand*{\Thetasymbol}{\textThetasymbol}
    }
%    \end{macrocode}
% Ensure that this works also after loading other fonts packages such as \software{cfr-lm}.
%    \begin{macrocode}
    \AtBeginDocument{\@ifpackageloaded{nfssext-cfr}{
      \DeclareFontFamily{LGR}{clmj}{}
      \DeclareFontFamilySubstitution{LGR}{clmj}{lmr}
      \DeclareFontFamily{LGR}{clm2j}{}
      \DeclareFontFamilySubstitution{LGR}{clm2j}{lmr}
      \DeclareFontFamily{LGR}{clm2}{}
      \DeclareFontFamilySubstitution{LGR}{clm2}{lmr}
      \DeclareFontFamily{LGR}{clm2s}{}
      \DeclareFontFamilySubstitution{LGR}{clm2s}{lmss}
      \DeclareFontFamily{LGR}{clm2js}{}
      \DeclareFontFamilySubstitution{LGR}{clm2js}{lmss}
      \DeclareFontFamily{LGR}{clmjs}{}
      \DeclareFontFamilySubstitution{LGR}{clmjs}{lmss}
    }{}}
%     \fi
%    \end{macrocode}
%
% \subsection{Additional math fonts}
%
% Either load the \software{MnSymbol} package \cite{MnSymbol} or the the \software{exscale} package \cite{exscale} in order to fix Latin Modern "lmex" fonts.
% Additionally, load the \software{amssymb} package \cite{amsfonts} which provides further math symbols and also loads the \software{amsfonts} package \cite{amsfonts}.
%    \begin{macrocode}
    \ifhep@minion
      \RequirePackage{MnSymbol}
    \else
      \RequirePackage{exscale}
      \RequirePackage{amssymb}
    \fi
%    \end{macrocode}
%
% \begin{macro}{\mathbf}
% Load the \software{bm} package \cite{bm} for superior boldmath.
% Make math symbols bold whenever they appear in bold macros such as "\section"\marg{text}.
%    \begin{macrocode}
    \RequirePackage{bm}
    \AtBeginDocument{\let\mathbf\bm}
    \g@addto@macro\bfseries{\boldmath}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mathtt}
% Typewriter math font
%    \begin{macrocode}
    \DeclareMathAlphabet{\mathtt}{OT1}{lmtt}{m}{n}
    \SetMathAlphabet{\mathtt}{bold}{OT1}{lmtt}{bx}{n}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mathscr}
% Provid the "\mathscr" math script font from the \software{mathrsfs} package \cite{mathrsfs}.
%    \begin{macrocode}
    \DeclareMathAlphabet{\mathscr}{U}{rsfs}{m}{n}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\mathbb}
% Redefine the the "\mathbb" math blackboard style font according to the \prefix{sans}{serif} option with the font from the \software{dsfont} package \cite{dsfont}.
%    \begin{macrocode}
    \ifhep@minion
      \DeclareMathAlphabet{\mathbb}{U}{%
        \ifhepmathfont@serif dsrom\else dsss\fi%
      }{m}{n}
    \else
      \ifhep@ams\else
        \SetMathAlphabet{\mathbb}{normal}{U}{%
          \ifhepmathfont@serif dsrom\else dsss\fi%
        }{m}{n}
      \fi
    \fi
%    \end{macrocode}
% End of symbols conditional.
%    \begin{macrocode}
  \fi
%    \end{macrocode}
% End of xetex conditional.
%    \begin{macrocode}
\fi
%    \end{macrocode}
% \end{macro}
%
%</package>
%
% \section{Tests}
%
%<*testserif|testsans>
%
%    \begin{macrocode}
\documentclass{article}

%<testserif>\usepackage[oldstyle]{hep-font}
%<testsans>\usepackage[oldstyle,sans]{hep-font}
\usepackage{hep-math-font}

\usepackage{fancyvrb}\DefineShortVerb{\|}
\newenvironment{vrb}{\begin{tabular}{@{}p{6cm}l@{}}}{\end{tabular}}

\begin{document}

\begin{vrb}
|| & $Ab\Gamma\delta123$ \\
|\mathbf | & $\mathbf{Ab\Gamma\delta123}$ \\
|\mathrm | & $\mathrm{Ab\Gamma\delta123}$ \\
|   \mathbf | & $\mathbfrm{Ab\Gamma\delta123}$ !! \\
|\text | & $\text{Ab\Gamma\delta123}$ \\
|   \textbf | & $\textbf{\text{Ab\Gamma\delta123}}$ \\
|\mathsf | & $\mathsf{Ab\Gamma\delta123}$ \\
|   \mathbf | & $\mathbfsf{Ab\Gamma\delta123}$ \\
|\mathtt | & $\mathtt{Ab\Gamma123}$ \\
|   \mathbf | & $\mathbf{\mathtt{Ab\Gamma123}}$ \\
|\mathcal | & $\mathcal{ABC}$ \\
|\mathscr | & $\mathscr{ABC123}$ \\
|\mathbb | & $\mathbb{ABC1}$ \\
|\mathfrak | & $\mathfrak{ABC123}$ \\
\end{vrb}

$\Gamma\Delta\Lambda\Phi\Pi\Psi\Sigma\Theta\Upsilon\Xi\Omega$

$\mathrm{\Gamma\Delta\Lambda\Phi\Pi\Psi\Sigma\Theta\Upsilon\Xi\Omega}$

\Gamma\Delta\Lambda\Phi\Pi\Psi\Sigma\Theta\Upsilon\Xi\Omega

$\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda
\mu\nu\xi\pi\rho\sigma\varsigma\tau\upsilon\phi\chi\psi\omega$

$\mathrm{\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda
\mu\nu\xi\pi\rho\sigma\varsigma\tau\upsilon\phi\chi\psi\omega}$

\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda
\mu\nu\xi\pi\rho\sigma\varsigma\tau\upsilon\phi\chi\psi\omega

\end{document}
%    \end{macrocode}
%
%</testserif|testsans>
%
% \section{Readme}
%
%<*readme>
%
%    \begin{macrocode}
# The `hep-math-font` package

Extended Greek and sans-serif math

## Introduction

The `hep-math-font` package adjust the math fonts to be sans-serif if the
document is sans-serif. Additionally Greek letters are redefined to be
always italic and upright in math and text mode respectively. Some math
font macros are adjusted to give more consistently the naively expected
results.

The package is loaded using `\usepackage{hep-math-font}`.

## Author

Jan Hajer

## License

This file may be distributed and/or modified under the conditions of the
`LaTeX` Project Public License, either version 1.3c of this license or
(at your option) any later version. The latest version of this license is
in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is
part of all distributions of LaTeX version 2005/12/01 or later.
%    \end{macrocode}
%
%</readme>
%
% \Finale

\endinput

% \PrintIndex
% makeindex -s gglo.ist -o hep-math-font-implementation.gls hep-math-font-implementation.glo
% makeindex -s gglo.ist -o hep-math-font-implementation.ind hep-math-font-implementation.idx
