% \iffalse meta-comment
%
% Copyright (C) 2024 by Antoine Missier <antoine.missier@ac-toulouse.fr>
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 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.3 or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{mathgreeks.dtx}
%</driver>
%<*package> 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{mathgreeks}
    [2024/05/07 v1.2 .dtx Math Greek letters]
%</package>
%<*driver>
\documentclass[11pt]{article}
%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{doc}
\usepackage{geometry}
\usepackage[mathdesign=Charter,otherfonts]{mathgreeks}
\usepackage{sectsty}
\usepackage{xcolor}
\usepackage{spacingtricks}
\usepackage{metalogo}
%\usepackage{supertabular} % incompatible with tabls
\usepackage{tabls}
\usepackage{multirow}
\usepackage{ifluatex}
\ifluatex
  \usepackage{unicode-math}
  \setmainfont{XCharter}
\else
  \usepackage{charter}
\fi
\geometry{scale=0.73,vmarginratio=3:4,heightrounded}
\MakeShortVerb{"}
\definecolor{darkbrown}{rgb}{0.5,0.1,0.1}
\allsectionsfont{\color{darkbrown}}
\newcommand\bs{\textbackslash}
\DisableCrossrefs
%\CodelineIndex
%\RecordChanges
\OnlyDescription
\usepackage{hyperref}
\title{The \textsf{mathgreeks} package}
\author{Antoine Missier \\ \texttt{antoine.missier@ac-toulouse.fr}}
\date{\filedate, \fileversion}
\hypersetup{%
    colorlinks,
    linkcolor=blue,
    citecolor=red,
    pdftitle={mathgreeks},
    pdfsubject={LaTeX package},
    pdfauthor={Antoine Missier}
}

\begin{document}
\DocInput{mathgreeks.dtx}
%\PrintChanges
%\PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{1061}
%
% \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}{2024/04/30}{Initial version}
% \changes{v1.1}{2024/05/04}{Adding the libsans option; a few changes in the doc}
% \changes{v1.2}{2024/05/07}{A clarification in the documentation about the option shape=it}
%
% \GetFileInfo{mathgreeks.sty}
%
% \maketitle
% \tableofcontents
%
% \section{Introduction}
%
% The purpose of this package is to provide access to numerous Greek letter fonts 
% for math mode, without altering other mathematical characters and symbols 
% and without loading whole extensions that provide these fonts.
%
% The commands "\italpha", "\itbeta"\ldots\ produce the italic forms of the chosen font, 
% and "\upalpha", "\upbeta" \ldots\ produce the upright forms. 
% Style options allow choosing between italic or upright forms for the basic commands 
% "\alpha", "\beta"\ldots
% Only letters whose glyph differs from the corresponding Roman letter
% will be defined this way. 
% Therefore, the package does not provide a command "\omicron", 
% whose letter is identical to the Roman `o', and only a few uppercase letters are defined:
% "\Gamma", "\Delta", "\Theta"\ldots
%
% \medskip
% An ISO recommendation, rarely followed, is to typeset uppercase 
% Greek letters in italic shape, as for other variables~\cite{ICTNS}.
% This is automatically achieved, for some particular fonts, with packages 
% such as \textsf{fixmath} by Walter Schmidt~\cite{FIXM},
% \mbox{\textsf{isomath}} by Günter Milde~\cite{ISOM} 
% or \textsf{pm-isomath} by Claudio Beccari~\cite{PMISO} and optionally with some others
% (such as \textsf{mathpazo} or \textsf{mathptmx} with the option \texttt{slantedGreek}).
% When running through \LuaLaTeX\ or \XeLaTeX\ you can also get this result 
% with the option \mbox{\texttt{math-style=ISO}} provided 
% by the \textsf{unicode-math} package~\cite{UNIC}.
%
% \pagebreak ^^A To get the same page breaking when compiling with pdfLaTeX
% Furthermore there are several packages that provide the uppercase Greek letters 
% in italic and have also options to typeset the lowercase Greek  
% letters in upright shape.
% Notably, let us mention 
% \mbox{\textsf{mathdesign}}~\cite{DESIGN},
% \mbox{\textsf{kpfonts}}~\cite{KPF}, 
% \mbox{\textsf{fourier}}~\cite{FOUR}, but also
% \mbox{\textsf{pxgreeks}} (using \textsf{pxfonts}~\cite{PX}), \mbox{\textsf{txgreeks}}
% (using \textsf{txfonts}~\cite{TX}),
% \mbox{\textsf{libertinust1math}}~\cite{LIB}, \mbox{\textsf{libgreek}}, etc.
% A special mention goes to \textsf{lgrmath} of Jean-François Burnol~\cite{LGR}
% which allows the use of any Greek LGR-encoded font in math mode,
% an idea taken up in \textsf{mathgreeks}.
% Also note \textsf{newtxmath}~\cite{NTX} which has several font options.
% For upright lowercase letters, we have the nice \textsf{upgreek}~\cite{GREEK} package.
%
% \medskip
% The interest of \textsf{mathgreeks} lies in being able to choose the Greek letters font 
% from one of these packages or from a TrueType or OpenType font installed on your computer.
% The package sets Greek letters in the desired font and shape
% and enables to change font or shape dynamically within the document.
%
% \section{Options and settings}
%
% \subsection{Package options}
%
% When calling the package, there are three types of options:
% \begin{itemize}
% \item Font options,
% \item Shape options (the style),
% \item Additional options.
% \end{itemize}
% These options use the `\texttt{key=value}' mechanism. 
% When a default value is set, the key can be used without specifying a value 
% (which will then be the default value). 
% Some keys represent booleans with the default value being `\texttt{true}'.
%
% \bigskip
% The first table, in two parts, presents the different keys corresponding to font options, 
% the list of possible values (complete when it is reduced). 
% The default value is indicated in bold, the second part consist in boolean options. 
% Results are presented in section~\ref{examples}.
%
% \begin{table}[h]
% \begin{center}\ttfamily
% \begin{tabular}{ll}
% \hline
% \vstrut{2ex}\normalfont{Option} & \normalfont{Values} \\
% \hline
% lgrmath & Alegreya-LF, Cochineal-LF, \textbf{fcm}\ldots \\
% fontspec & FreeSerif, \textbf{GFS Didot}, Cambria\ldots \\
% unicode-math & \textbf{Latin Modern Math}, STIX Two Math\ldots \\
% upgreek & Euler, \textbf{Symbol}, Symbolsmallscale \\
% mathdesign & Utopia, Garamond, \textbf{Charter} \\
% kpfonts & \textbf{normal}, light \\
% \hline
% \end{tabular}
% \hspace{1cm}
% \begin{tabular}{l}
% \hline
% \vstrut{2ex}\normalfont{Booleans} \\
% \hline
% fourier \\
% pxfonts \\
% txfonts \\
% libertinus \\
% concrete \\
% cmbright \\
% \hline
% \end{tabular}
% \caption{\normalfont{font options}\label{table:font}}
% \end{center}
% \end{table}
%
% \vspace{-1\baselineskip}
% The \texttt{fontspec} and \texttt{unicode-math} options require loading 
% the corresponding packages, and these can only work when running through 
% \LuaLaTeX\ (or \XeLaTeX).
% The \texttt{fontspec} option allows for the use of most TrueType or OpenType 
% fonts installed on your computer, those that have Greek letters.
% Although the \textsf{unicode-math} package loads the \textsf{fontspec} package,
% the fonts usable with one of these options are not necessarily usable with the other;
% \texttt{fontspec} has a large number of possible values.
%
% When calling "\boldmath" (outside the math environment), you get the letters in bold face,
% but the command "\mathbf" doesn't work here.
%
% \bigskip
% The second table below presents the shape options. If the shape option 
% is not specified, the italic shape is chosen by default, meaning that the commands 
% "\alpha", "\beta", \ldots, "\Delta", "\Gamma"\ldots\ will produce the same result 
% as the corresponding "\it"\meta{letter} commands.
%
% \begin{table}[h]
% \begin{center}
% \begin{tabular}{ll}
% \hline
% \vstrut{2ex}\normalfont{Option} & \normalfont{Description} \\
% \hline
% \texttt{greekup} & lowercase letters in upright shape \\
% \texttt{Greekup} & uppercase letters in upright shape \\
% \texttt{TeX} & lowercase=italic, uppercase=upright \\
% \texttt{ISO} & lowercase=italic, uppercase=italic \\
% \texttt{upright} & lowercase=upright, uppercase=upright \\
% \texttt{style} & possible values: \texttt{TeX}, \texttt{ISO}, \texttt{upright} \\
% \hline
% \end{tabular}
% \caption{shape options\label{table:shape}}
% \end{center}
% \end{table}
%
% \vspace{-1\baselineskip}
% \begin{itemize}
% \item Except for \texttt{style}, all these options are booleans.
% \item The \texttt{Greekup} option est initialized to  \texttt{true} (corresponding
% to the \texttt{TeX} style).
% \item The \texttt{style=ISO} option produces the same result as the simple 
% \texttt{ISO} option, and the same applies to the other two styles 
% (\texttt{TeX}, \texttt{upright}).
% \item To get lowercase letters in upright shape and uppercase letters in italic,
% activate \begin{center}\texttt{greekup=true,Greekup=false}.\end{center}
% \end{itemize}
% 
% \bigskip
% The following list presents the additional options, which are also booleans:
% \begin{description}
% \item[\texttt{savegreeks}] Saves the letters corresponding to the original commands 
% "\alpha", "\beta"\ldots so that they remain accessible through the commands 
% "\backalpha", "\backbeta"\ldots
% \item[\texttt{otherfonts}] Allows dynamic font switching (see next section) 
% for later use of \texttt{lgrmath}, \texttt{fourier}, \texttt{libertinus} 
% or \texttt{upgreek}.
% \item[\texttt{libsans}] This is a special option that works only with \texttt{libertinus}
% to produce a sanserif font.
% \item[\texttt{lowercase}] This option is initialized to \texttt{true}; 
% \texttt{lowercase=false} allows keeping the original lowercase Greek letters 
% without redefining the commands "\alpha", "\beta"\ldots
% \item[\texttt{uppercase}] This option is initialized to \texttt{true}; 
% \texttt{uppercase=false} allows keeping the original uppercase Greek letters 
% without redefining the commands "\Gamma", "\Delta"\ldots
% \end{description}
%
% \subsection{Dynamic settings commands}
%
% There are two commands for dynamic settings:
% \begin{description}
% \item[] "\setmathgreeks"
% This command takes a mandatory parameter which is a list of 
% `\texttt{key=value}' settings among the shape options presented 
% in table~\ref{table:shape} (the other options are not usable in this command). 
% This allows modifying these settings in the body of the document, 
% with a global effect, or local if the command is called in an environment 
% or a group (delimited by braces).
%
% \item[] "\mathgreeksfont"
% This command allows modifying the font of Greek letters throughout the document, 
% with a global or local effect.
% The possible options fall into two categories: 
% \begin{center}
% \texttt{fontspec}, \texttt{unicode-math}, \\
% \texttt{enc}, \texttt{fam}, \texttt{series}, \texttt{shape}. 
% \end{center}
% The \texttt{fontspec} and \texttt{unicode-math} options are identical 
% to those in table~\ref{table:font}. In that case, the shape is set by "\setmathgreeks"
% (before or after). 
% The other previous font options (\texttt{lgrmath}, \texttt{mathdesign}, 
% \texttt{fourier}, etc.)\@ are not usable in "\mathgreeksfont". 
% However, these fonts can be obtained by specifying the encoding (option \texttt{enc}), 
% family (option \texttt{fam}), series and shape: the New Font Selection Scheme (NFSS).
% The series defines the `boldness' and has a default value: \texttt{series=m} (medium).
% For the shape, the default value is \texttt{shape=it};
% \texttt{enc} and \texttt{fam} have no default value.
% For example, 
% \begin{center}
% "\mathgreeksfont{enc=OML,fam=mdbch,shape=n}"
% \end{center}
% will produce upright letters from the Charter font provided by \textsf{mathdesign}.
% For each font option seen previously,
% the following examples (section~\ref{examples}) indicates
% the values to give to \texttt{enc}, \texttt{fam}, and \texttt{shape}.
% The font definition by NFSS attributes will not produce specific commands for italics
% "\it"\meta{letter} or for upright letters "\up"\meta{letter}.
% Only the commands "\alpha", "\beta"\ldots will be redefined according to the 
% selected shape.
%
% When using the \texttt{fontspec} or \texttt{unicode-math} option,
% these NFSS options have no effect.
%
% Notice that the encoding obtained by the package font options is faster, moreover
% the command "\boldmath" doesn't work anymore
% when changing the font with \texttt{enc}, \texttt{fam} and \texttt{shape},
% but you can obtain the boldface
% letters with \texttt{series=b}, or \texttt{series=bx} (bold extended).
%
% \end{description}
%
% \section{Examples} \label{examples}
% \begin{description}
% \item[] "\greektable"
% The following examples are produced with the "\greektable" command. 
% This command generates a table with two rows: the first contains the lowercase letters
% obtained with "\alpha", \ldots, "\omega", and the second contains variants 
% "\varepsilon", "\vartheta"\ldots\ of certain letters as well as the uppercase letters
% obtained with "\Gamma", "\Delta", \ldots, "\Omega" 
% (for those who differ from their Latin equivalent).
% \end{description}
%
% \subsection{PostScript font options}
%
% The \texttt{upgreek} option, as its name suggests, produces only upright letters, 
% and the \texttt{Euler} font does not have the variants "\varrho" and "\varsigma".
% The \texttt{Symbolsmallscale} font is identical to Symbol but reduced in size by 90\,\%;
% \texttt{Symbol} and \texttt{Symbolsmallscale} have no bold version.
% ^^A\texttt{mathdesign=Garamond} yields a virtual font that may not always work.
% For several fonts, the upright shape is obtained with the attribute \texttt{shape=it}
% and not \texttt{shape=n}.
% 
% \newlength\legendwidth
% \setlength\legendwidth{3.2cm}
% \newcommand*\doublerows[1]{\multirow{2}{\legendwidth}[-1.5ex]{\bfseries#1}}

% \begin{center}
% \begin{tabular}{|l|@{}c@{}|c@{$\;$}c@{\:}c|}
% \hline
% \makebox[\legendwidth][l]{\textbf{upgreek=...}} & \makebox[8.4cm]{Result} 
%  & \makebox[1cm]{enc} & \makebox[1cm]{fam} & shape \\
% \hline
% \textbf{Symbol} 
% & \mathgreeksfont{enc=U,fam=psy,shape=n}\greektable
% & U & psy & n \\
% \hline
% \textbf{Symbolsmallscale} 
% & \mathgreeksfont{enc=U,fam=fsy,shape=n} \greektable 
% & U & fsy & n \\
% \hline
% \textbf{Euler}
% & \mathgreeksfont{enc=U,fam=eur,shape=n} \greektable 
% & U & eur & n \\
% \hline
% \end{tabular}
% \end{center}
%
% \begin{center}
% \begin{tabular}{|l|@{}c@{}|c@{$\;$}c@{}c|}
% \hline
% \textbf{mathdesign=...} & \makebox[8.4cm]{Result} & enc & fam & shape \\
% \hline
% \doublerows{Utopia} 
% & \mathgreeksfont{enc=OML,fam=mdput} \greektable 
% & OML & mdput & it \\
% & \mathgreeksfont{enc=OML,fam=mdput,shape=n} \greektable 
% & OML & mdput & n \\
% \hline
% \doublerows{Garamond} 
% & \mathgreeksfont{enc=OML,fam=mdugm} \greektable 
% & OML & mdugm & it \\
% & \mathgreeksfont{enc=OML,fam=mdugm,shape=n} \greektable 
% & OML & mdugm & n \\
% \hline
% \doublerows{Charter} 
% & \mathgreeksfont{enc=OML,fam=mdbch} \greektable 
% & OML & mdbch & it \\
% & \mathgreeksfont{enc=OML,fam=mdbch,shape=n} \greektable 
% & OML & mdbch & n \\
% \hline
% \end{tabular}
% \end{center}
%
% \begin{center}
% \begin{tabular}{|l|@{}c@{}|c@{$\;$}c@{}c|}
% \hline
% \textbf{kpfonts=...} & \makebox[8.4cm]{Result} & enc & fam & shape \\
% \hline
% \doublerows{normal} 
% & \mathgreeksfont{enc=OML,fam=jkp} \greektable 
% & OML & jkp & it \\
% & \mathgreeksfont{enc=U,fam=jkpmia} \greektable 
% & U & jkpmia & it \\
% \hline
% \doublerows{light} 
% & \mathgreeksfont{enc=OML,fam=jkpl} \greektable 
% & OML & jkpl & it \\
% & \mathgreeksfont{enc=U,fam=jkplmia} \greektable 
% & U & jkplmia & it \\
% \hline
% \end{tabular}
% \end{center}
%
% \begin{center}
% \begin{tabular}{|l|@{}c@{}|c@{$\;$}c@{}c|}
% \hline
% Boolean options & \makebox[8.2cm]{Result} & enc & fam & shape \\
% \hline
% \doublerows{fourier} 
% & \mathgreeksfont{enc=FML,fam=futmi} \greektable
% & FML & futmi & it \\
% & \mathgreeksfont{enc=FML,fam=futm} \greektable
% & FML & futm & it \\
% \hline
% % \doublerows{pxfonts} 
% & \mathgreeksfont{enc=OML,fam=pxmi} \greektable
% & OML & pxmi & it \\
% & \mathgreeksfont{enc=U,fam=pxmia} \greektable
% & U & pxmia & it \\
% \hline
% \doublerows{txfonts} 
% & \mathgreeksfont{enc=OML,fam=txmi} \greektable
% & OML & txmi & it \\
% & \mathgreeksfont{enc=U,fam=txmia} \greektable
% & U & txmia & it \\
% \hline
% \doublerows{libertinus} 
% & \mathgreeksfont{enc=LS1,fam=libertinust1math} \greektable 
% & LS1 & * & it \\
% & \mathgreeksfont{enc=LS1,fam=libertinust1math,shape=n} \greektable 
% & LS1 & * & n \\
% \hline
% \textbf{concrete}
% & \mathgreeksfont{enc=OML,fam=ccm} \greektable 
% & OML & ccl & it \\
% \hline
% \textbf{cmbright}
% & \mathgreeksfont{enc=OML,fam=cmbrm} \greektable
% & OML & cmbrm & it \\
% \hline
% \end{tabular}
% \end{center}
% \emph{* The asterisks for the} \textbf{libertinus} \emph{family corresponds to} 
% \textnormal{`libertinust1math'} \emph{a name too long to appear in this table.
% Activating the} \texttt{libsans} \emph{package option yields a sanserif font.}
%
% \subsection{The \texttt{lgrmath} option}
%
% The \texttt{lgrmath} option, inspired by the eponymous package of J.F. Burnol, 
% has a large number of possible values. We present here only a few. 
% The documentation of the \textsf{lgrmath} package~\cite{LGR} explains how 
% to list the fonts available on your distribution with the LGR encoding. 
% One can also consult with profit the documentation of \textsf{cb-fonts}\cite{CB}, 
% the Greek fonts of Claudio Beccari.
%
% With the \texttt{lgrmath} option, the alternative commands for the variants 
% produce the same glyphs as those of the normal letters except for "\varsigma".
% However, the "\varsigma" $\varsigma$ often substitutes for the usual "\sigma" $\sigma$
% when using dynamic font changes through "\mathgreeksfont" with \texttt{enc=LGR}.
%
% We have not presented here the third column previously indicating the values for
% \texttt{enc}, \texttt{fam}, and \texttt{shape} because, for this entire section, 
% we have \texttt{enc=LGR}, \texttt{fam=\meta{font-name}}, the name of the font presented, 
% and \texttt{shape=it}, for the italic shape, or \texttt{shape=n}, for the upright shape.
% Example:
% \begin{center}
% "\mathgreeksfont{enc=LGR,fam=Alegreya-LF,shape=n}"
% \end{center}
%
%\setlength\legendwidth{4cm}
% \newcommand\lgrtbl[1]{%
%     \doublerows{#1}
%     & \mathgreeksfont{enc=LGR,fam=#1} \greektable \\ 
%     & \mathgreeksfont{enc=LGR,fam=#1,shape=n} \greektable \\
%     \hline
% }
%
% \begin{center}
% \begin{tabular}{|l|c|}
% \hline
% \textbf{lgrmath=...} & Result \\
% \hline
% \lgrtbl{Alegreya-LF}
% \lgrtbl{Cochineal-LF}
% \lgrtbl{LibertinusSerif-LF}
% \lgrtbl{LibertinusSans-LF}
% \lgrtbl{NotoSerif-LF}
% \lgrtbl{droidserif}
% \lgrtbl{fcm}
% \lgrtbl{gentium}
% \lgrtbl{lmss}
% \end{tabular}
% \end{center}
%
% \ifluatex
% \subsection{The \texttt{fontspec} option}
%
% Most TrueType or OpenType fonts can be used here.
% ^^A Needs the \textsf{fontspec} package and must be run through \LuaLaTeX\ or \XeLaTeX.
% Some of the fonts below are non free, and some do not have all the variants,
% for example Arial, Palatino Linotype, Times New Roman.
%
% \newcommand\fontspectbl[2][fontspec]{%
%     \doublerows{#2}
%     & \mathgreeksfont{#1=#2}
%       \setmathgreeks{style=ISO} \greektable \\
%     & \mathgreeksfont{fontspec=#2}
%       \setmathgreeks{style=upright} \greektable \\
%     \hline
% }
%
% \begin{center}
% \begin{tabular}{|l|c|}
% \hline
% \textbf{fontspec=...} & Result \\
% \hline
% \fontspectbl{DejaVu Serif}
% \fontspectbl{DejaVu Sans}
% \fontspectbl{FreeSerif}
% \fontspectbl{FreeSans}
% \fontspectbl{GFS Artemisia}
% \fontspectbl{GFS Didot}
% \fontspectbl{Liberation Serif}
% \fontspectbl{Liberation Sans}
% \end{tabular}
% \end{center}
%
% \begin{center}
% \begin{tabular}{|l|c|}
% \hline
% \textbf{fontspec=...} & Result \\
% \hline
% \fontspectbl{Linux Libertine O}
% ^^A\fontspectbl{Linux Biolinum O}
% \fontspectbl{Arial}
% \fontspectbl{Cambria}
% \fontspectbl{Palatino Linotype}
% \fontspectbl{Times New Roman}
% \end{tabular}
% \end{center}
%
%
% \subsection{The \texttt{unicode-math} option}
%
% \begin{center}
% \begin{tabular}{|l|c|}
% \hline
% \textbf{unicode-math=...} & Result \\
% \hline
% \fontspectbl[unicode-math]{Latin Modern Math}
% \fontspectbl[unicode-math]{STIX Two Math}
% \fontspectbl[unicode-math]{Fira Math}
% \end{tabular}
% \end{center}
%
% \else
% \typeout{This is a short version of the documentation.
%     Use LuaLaTeX to get the complete version}
% \fi
%
% \StopEventually{
% \begin{thebibliography}{20}
% \begin{raggedright}
% \bibitem{ICTNS} \emph{On the Use of Italic and up Fonts for Symbols in Scientific Text},
% I.M.~Mills and W.V.~Metanomski, ICTNS (Interdivisional Committee 
% on Terminology, Nomenclature and Symbols), dec 1999,
% \url{https://old.iupac.org/standing/idcns/italic-roman_dec99.pdf}.
% \bibitem{UNIC} \emph{Experimental Unicode mathematical typesetting: 
% The \textsf{unicode-math} package}, Will Robertson, Philipp Stephani, Joseph Wright, 
% Khaled Hosny, and others, CTAN, v0.8r 2023/08/13.
% \bibitem{FSPEC} \emph{The \textsf{fontspec} package -- Font selection for \XeLaTeX\ 
% and \LuaLaTeX}, Will Robertson, CTAN, v2.9b 2024/04/27.
% \bibitem{FIXM} \emph{The \textsf{fixmath} package for \LaTeXe}, Walter Schmidt, 
% CTAN, v0.9 2000/04/11.
% \bibitem{ISOM} \emph{\textsf{isomath} -- Mathematical style for science and technology},
% Günter Milde, CTAN, v0.6.1 2012/09/04.
% \bibitem{PMISO} \emph{\textsf{PM-ISOmath}, The Poor Man ISO math bundle}, 
% the \textsf{pm-isomath} package by Claudio Beccari, CTAN, v1.2.00 2021/08/04.
% \bibitem{GREEK} \emph{The \textsf{upgreek} package for \LaTeXe}, Walter Schmidt,
% CTAN, v2.0 2003/02/12.
% \bibitem{DESIGN} \emph{The \textsf{mathdesign} package},
% Paul Pichaureau, CTAN, v2.31 2013/08/29.
% \bibitem{KPF} \emph{\textsf{Kp-Fonts} -- The Johannes Kepler project},
% Christophe Caignaert, CTAN, v3.34 20/09/2022.
% \bibitem{FOUR} \textsf{Fourier-GUT\hspace{-0.1em}\emph{enberg}},
% Michel Bovani, CTAN, v1.3 2005/01/30.
% \bibitem{PX} \emph{\textsf{PX Fonts} -- Palatino-like fonts in support of mathematics}, 
% Young Ryu, CTAN, 2000/12/14.
% \bibitem{TX} \emph{\textsf{TX Fonts} -- Times-like fonts in support of mathematics}, 
% Young Ryu, CTAN, 2000/12/15.
% \bibitem{CB} \emph{The CB Greek fonts}, Claudio Beccari, CTAN, 2008/01/01.
% \bibitem{PXG} \emph{The \textsf{pxgreeks} package}, Jean-François Burnol,
% CTAN v1.0 2011/03/16.
% \bibitem{TXG} \emph{The \textsf{txgreeks} package}, Jean-François Burnol,
% CTAN v1.0 2011/03/16.
% \bibitem{LIBG} \emph{The \textsf{libgreek} package}, Jean-François Burnol,
% CTAN v1.1 2022/11/11.
% \bibitem{LGR} \emph{The \textsf{lgrmath} package}, Jean-François B., CTAN, v1.0 2022/11/16.
% \bibitem{NTX} \emph{New TX font package}, Michael Sharpe, CTAN, v1.735 2024/03/01.
% \bibitem{LIB} \emph{The LibertinusT1 Math Package}, Michael Sharpe, CTAN, 
% v2.0.4 2024/01/14.
% \bibitem{CHEM} \emph{\textsf{chemgreek} -- Upright Greek letters in chemistry},
% Clemens Niederberger, CTAN, v1.1a 2020/01/16.
% \end{raggedright}
% \end{thebibliography}
% }
%
% \section{Implementation}
%
%    \begin{macrocode}
\RequirePackage{kvoptions}
%\SetupKeyvalOptions{family=mgr} % mathgreeks by default

\DeclareStringOption{lgrmath}[fcm]
\newif\ifmathgreeks@lgrmath
\AddToKeyvalOption*{lgrmath}{\mathgreeks@lgrmathtrue}
\DeclareStringOption{fontspec}[GFS Didot]
\newif\ifmathgreeks@fontspec
\AddToKeyvalOption*{fontspec}{\mathgreeks@fontspectrue}
\newif\ifmathgreeks@unicodemath
\define@key{mathgreeks}{unicode-math}[Latin Modern Math]{
    \newcommand*{\mathgreeks@unicodemath}{#1}
    \mathgreeks@unicodemathtrue}
\DeclareStringOption{upgreek}[Symbol]
\newif\ifmathgreeks@upgreek
\AddToKeyvalOption*{upgreek}{\mathgreeks@upgreektrue
    \mathgreeks@Greekuptrue\mathgreeks@greekuptrue}
\DeclareStringOption{mathdesign}[Charter]
\newif\ifmathgreeks@mathdesign
\AddToKeyvalOption*{mathdesign}{\mathgreeks@mathdesigntrue}
\DeclareBoolOption{fourier}% false by default
\DeclareStringOption{kpfonts}[normal]
\newif\ifmathgreeks@kpfonts
\AddToKeyvalOption*{kpfonts}{\mathgreeks@kpfontstrue}
\DeclareBoolOption{pxfonts}
\DeclareBoolOption{txfonts}
\DeclareBoolOption{libertinus}
\DeclareBoolOption{concrete}
\DeclareBoolOption{cmbright}

\DeclareBoolOption{savegreeks}
\DeclareBoolOption{otherfonts}
\DeclareBoolOption{libsans}
\DeclareBoolOption[true]{lowercase}
\DeclareBoolOption[true]{uppercase}

% dynamic options
\DeclareBoolOption[true]{Greekup}
\DeclareBoolOption{greekup}
\DeclareBoolOption{upright}
\AddToKeyvalOption*{upright}{\mathgreeks@Greekuptrue
    \mathgreeks@greekuptrue}
\DeclareBoolOption{ISO}
\AddToKeyvalOption*{ISO}{\mathgreeks@Greekupfalse
    \mathgreeks@greekupfalse}
\DeclareBoolOption{TeX}
\AddToKeyvalOption*{TeX}{\mathgreeks@Greekuptrue
    \mathgreeks@greekupfalse}
\DeclareStringOption{style}
\AddToKeyvalOption*{style}{\setkeys{mathgreeks}{\mathgreeks@style}}

\DeclareDefaultOption{\PackageError{mathgreeks}{%
    Option key `\CurrentOptionKey' undefined}{}}
\ProcessLocalKeyvalOptions* % \setkeys is done here

\RequirePackage{etoolbox} % provides \AtEndPreamble

\newif\ifkp@upRm % from kpgonts, bugs if after \ifmathgreeks@kpfonts
\newif\iflibus@sansmath % from libertinust1math
\newif\ifmathgreeks@Symbol % for codes definition
\newif\ifmathgreeks@itgreek % for fonts without upright shape
\newif\ifmathgreeks@font % if font option at package call
\mathgreeks@fonttrue


%%%%%%%%%%%%%%%% INITIAL SETTINGS %%%%%%%%%%%%%%%

\ifmathgreeks@otherfonts
    \DeclareFontEncoding{LGR}{}{}
    \DeclareFontEncoding{FML}{}{}
    \DeclareFontSubstitution{FML}{futm}{m}{it}
    \ifmathgreeks@libsans \libus@sansmathtrue\fi % taken up at encoding time
    \DeclareFontEncoding{LS1}{}{}
    \DeclareFontSubstitution{LS1}{libertinust1math}{m}{n}
    
    % from the upgreek package
    \DeclareFontFamily{U}{eur}{\skewchar\font'177}
    \DeclareFontShape{U}{eur}{m}{n}{%
        <-6> eurm5 <6-8> eurm7 <8-> eurm10}{}
    \DeclareFontShape{U}{eur}{b}{n}{%
        <-6> eurb5 <6-8> eurb7 <8-> eurb10}{}
    \DeclareFontFamily{U}{fsy}{}
    \DeclareFontShape{U}{fsy}{m}{n}{<->s*[.9]psyr}{}
    
\fi

\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{lgrmath}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{fontspec}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{unicodemath}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{upgreek}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{mathdesign}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{fourier}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{kpfonts}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{pxfonts}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{txfonts}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{savegreeks}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{otherfonts}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{libsans}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{lowercase}
\DisableKeyvalOption[action=warning,package=mathgreeks]{mathgreeks}{uppercase}


\AtEndPreamble{\AtBeginDocument{
    \@ifundefined{text}{\RequirePackage{amstext}}{}

    \ifmathgreeks@lgrmath
        \DeclareFontEncoding{LGR}{}{}
        \DeclareSymbolFont{mgr@it}{LGR}{\mathgreeks@lgrmath}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{LGR}{\mathgreeks@lgrmath}{b}{it}
        \DeclareSymbolFont{mgr@up}{LGR}{\mathgreeks@lgrmath}{m}{n}
        \SetSymbolFont{mgr@up}{bold}{LGR}{\mathgreeks@lgrmath}{b}{n}

    \else\ifmathgreeks@fontspec
        \@ifpackageloaded{fontspec}{}{
            \PackageError{mathgreeks}{`fontspec' or `unicodemath'
                options need the fontspec package\MessageBreak
                which must be run with LuaLaTeX or XeLaTeX}{}
        }
        \newfontfamily\MathGreeksFont{\mathgreeks@fontspec}%
            [NFSSFamily=mgru]
        \DeclareSymbolFont{mgr@it}{TU}{mgru}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{TU}{mgru}{b}{it}
        \DeclareSymbolFont{mgr@up}{TU}{mgru}{m}{n}
        \SetSymbolFont{mgr@it}{bold}{TU}{mgru}{b}{n}

    \else\ifmathgreeks@unicodemath
        \@ifpackageloaded{unicode-math}{}{
            \PackageError{mathgreeks}{`unicodemath' option needs
                the unicode-math package\MessageBreak
                which must be run with LuaLaTeX or XeLaTeX}{}
        }
        \setmathfont{\mathgreeks@unicodemath}[range=it/{greek,Greek}]
        \setmathfont{\mathgreeks@unicodemath}[range=up/{greek,Greek}]
        \mathgreeks@fontspectrue % for \mgr@CodeGreeks
        \let\mgr@UnicodeGreek\mgr@UnicodemathGreek
          
    \else\ifmathgreeks@upgreek
        \ifdefstring{\mathgreeks@upgreek}{Euler}{
            \DeclareFontFamily{U}{eur}{\skewchar\font'177}
            \DeclareFontShape{U}{eur}{m}{n}{%
                <-6> eurm5 <6-8> eurm7 <8-> eurm10}{}
            \DeclareFontShape{U}{eur}{b}{n}{%
                <-6> eurb5 <6-8> eurb7 <8-> eurb10}{}
            \DeclareSymbolFont{mgr@up}{U}{eur}{m}{n}
            \SetSymbolFont{mgr@up}{bold}{U}{eur}{b}{n}
        }{
        \ifdefstring{\mathgreeks@upgreek}{Symbol}{
            \DeclareSymbolFont{mgr@up}{U}{psy}{m}{n} % no bold face
            \mathgreeks@Symboltrue
        }{
        \ifdefstring{\mathgreeks@upgreek}{Symbolsmallscale}{ 
            \DeclareFontFamily{U}{fsy}{}
            \DeclareFontShape{U}{fsy}{m}{n}{<->s*[.9]psyr}{}  
            \DeclareSymbolFont{mgr@up}{U}{fsy}{m}{n}
            \mathgreeks@Symboltrue
        }{
        \PackageError{mathgreeks}{Invalid value
            `\mathgreeks@upgreek' with `upgreek' key}{With `upgreek'
            possible values are: Euler, Symbol, Symbolsmallscale.}
        }}}

    \else\ifmathgreeks@mathdesign
        \ifdefstring{\mathgreeks@mathdesign}{Utopia}{
            \DeclareSymbolFont{mgr@it}{OML}{mdput}{m}{it}
            \SetSymbolFont{mgr@it}{bold}{OML}{mdput}{b}{it}
            \DeclareSymbolFont{mgr@up}{OML}{mdput}{m}{n}
            \SetSymbolFont{mgr@up}{bold}{OML}{mdput}{b}{n}
        }{
        \ifdefstring{\mathgreeks@mathdesign}{Garamond}{
            \DeclareSymbolFont{mgr@it}{OML}{mdugm}{m}{it}
            \SetSymbolFont{mgr@it}{bold}{OML}{mdugm}{b}{it}
            \DeclareSymbolFont{mgr@up}{OML}{mdugm}{m}{n}
            \SetSymbolFont{mgr@up}{bold}{OML}{mdugm}{b}{n}
        }{
        \ifdefstring{\mathgreeks@mathdesign}{Charter}{
            \DeclareSymbolFont{mgr@it}{OML}{mdbch}{m}{it}
            \SetSymbolFont{mgr@it}{bold}{OML}{mdbch}{b}{it}
            \DeclareSymbolFont{mgr@up}{OML}{mdbch}{m}{n}
            \SetSymbolFont{mgr@up}{bold}{OML}{mdbch}{b}{n}
        }{
        \PackageError{mathgreeks}{Invalid value
            `\mathgreeks@mathdesign' with `mathdesign' key}{With
            `mathdesign' possible values are: 
            Utopia, Garamond, Charter.}
        }}}

    \else\ifmathgreeks@fourier    
        \DeclareFontEncoding{FML}{}{}
        \DeclareFontSubstitution{FML}{futm}{m}{it}
        \DeclareSymbolFont{mgr@it}{FML}{futmi}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{FML}{futmi}{b}{it}
        \DeclareSymbolFont{mgr@up}{FML}{futm}{m}{it}
        \SetSymbolFont{mgr@up}{bold}{FML}{futm}{b}{it}

    \else\ifmathgreeks@kpfonts
        \ifdefstring{\mathgreeks@kpfonts}{normal}{
            \DeclareSymbolFont{mgr@it}{OML}{jkp}{m}{it}
            \SetSymbolFont{mgr@it}{bold}{OML}{jkp}{bx}{it}
            \DeclareSymbolFont{mgr@up}{U}{jkpmia}{m}{it}
            \SetSymbolFont{mgr@up}{bold}{U}{jkpmia}{bx}{it}
        }{
        \ifdefstring{\mathgreeks@kpfonts}{light}{
            \DeclareSymbolFont{mgr@it}{OML}{jkpl}{m}{it}
            \SetSymbolFont{mgr@it}{bold}{OML}{jkpl}{bx}{it}
            \DeclareSymbolFont{mgr@up}{U}{jkplmia}{m}{it}
            \SetSymbolFont{mgr@up}{bold}{U}{jkplmia}{bx}{it}
        }{
        \PackageError{mathgreeks}{Invalid value
            `\mathgreeks@kpfonts' with `kpfonts' key}{With
            `kpfonts' possible values are: normal, light.}
        }}
 
    \else\ifmathgreeks@pxfonts % no font option specified
        \DeclareSymbolFont{mgr@it}{OML}{pxmi}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{OML}{pxmi}{bx}{it}
        \DeclareSymbolFont{mgr@up}{U}{pxmia}{m}{it}
        \SetSymbolFont{mgr@up}{bold}{U}{pxmia}{bx}{it}
    
    \else\ifmathgreeks@txfonts
        \DeclareSymbolFont{mgr@it}{OML}{txmi}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{OML}{txmi}{bx}{it}
        \DeclareSymbolFont{mgr@up}{U}{txmia}{m}{it}
        \SetSymbolFont{mgr@up}{bold}{U}{txmia}{bx}{it}

    \else\ifmathgreeks@libertinus
        \ifmathgreeks@libsans \libus@sansmathtrue\fi
        \DeclareFontEncoding{LS1}{}{}
        \DeclareFontSubstitution{LS1}{libertinust1math}{m}{n}
        \DeclareSymbolFont{mgr@it}{LS1}{libertinust1math}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{LS1}{libertinust1math}{m}{it}
        \DeclareSymbolFont{mgr@up}{LS1}{libertinust1math}{m}{n}
        \SetSymbolFont{mgr@up}{bold}{LS1}{libertinust1math}{m}{n}

    \else\ifmathgreeks@concrete
        \DeclareSymbolFont{mgr@it}{OML}{ccm}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{OML}{ccm}{b}{it}
        \mathgreeks@itgreektrue
    
    \else\ifmathgreeks@cmbright
        \DeclareSymbolFont{mgr@it}{OML}{cmbrm}{m}{it}
        \SetSymbolFont{mgr@it}{bold}{OML}{cmbrm}{b}{it}
        \mathgreeks@itgreektrue
        
    \else
        \PackageWarningNoLine{mathgreeks}{No font option specified}
        \mathgreeks@fontfalse
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
     
    \ifmathgreeks@savegreeks \SaveGreeks \fi

    \ifmathgreeks@font
      \ifmathgreeks@upgreek
        \mathgreeks@Greekuptrue \mathgreeks@greekuptrue
        \PackageWarningNoLine{mathgreeks}{Commands \string \italpha,
            \string\itbeta... \MessageBreak
            not available with the `upgreek' option}    
      \else
        \mgr@CodeGreeks{it}
      \fi
      \ifmathgreeks@itgreek
        \mathgreeks@Greekupfalse \mathgreeks@greekupfalse
        \PackageWarningNoLine{mathgreeks}{Commands \string \upalpha,
            \string\upbeta... \MessageBreak
            not available with `concrete' or 'cmbright}    
      \else
        \mgr@CodeGreeks{up}
      \fi
    \mgr@DefaultGreeks
    \fi
}}


%%%%%%%%%%%%%%%%%%%%%%%%%% MACROS %%%%%%%%%%%%%%%%%%%%%%%%%%%


\def\re@DeclareMathSymbol#1#2#3#4{% from kpfonts, pxfonts, txfonts
    \let#1=\undefined
    \DeclareMathSymbol{#1}{#2}{#3}{#4}}
    
%\def\re@DeclareMathSymbol#1#2#3#4{% from newtxmath
%\if\relax\noexpand#1\let#1=\undefined \fi 
%\DeclareMathSymbol{#1}{#2}{#3}{#4}}

\newcommand{\mgr@CodeGreek}[3]{% #1 = it or up
    \expandafter\re@DeclareMathSymbol\csname#1#2\endcsname%
        {\mathalpha}{mgr@#1}{#3} % perhaps \mathord is better
}

\newcommand{\mgr@UnicodeGreek}[3]{%   
    \expandafter\Umathchardef\csname#1#2\endcsname="7 % mathalpha
        \csname symmgr@#1\endcsname #3
}   

\def\mgr@UnicodemathGreek#1#2#3{\unskip
    \expandafter\DeclareRobustCommand\csname#1#2\endcsname
        {\csname sym#1\endcsname{\symbol{#3}}}\ignorespaces
}

\newcommand{\mgr@CodeGreeks}[1]{% #1 = it or up
    \ifmathgreeks@lgrmath % LGR encoding
        \mgr@CodeGreek{#1}{Gamma}{71}
        \mgr@CodeGreek{#1}{Delta}{68}
        \mgr@CodeGreek{#1}{Theta}{74}
        \mgr@CodeGreek{#1}{Lambda}{76}
        \mgr@CodeGreek{#1}{Xi}{88}
        \mgr@CodeGreek{#1}{Pi}{80}
        \mgr@CodeGreek{#1}{Sigma}{83}
        \mgr@CodeGreek{#1}{Upsilon}{85}
        \mgr@CodeGreek{#1}{Phi}{70}
        \mgr@CodeGreek{#1}{Psi}{89}
        \mgr@CodeGreek{#1}{Omega}{87}
        \mgr@CodeGreek{#1}{alpha}{97}
        \mgr@CodeGreek{#1}{beta}{98}
        \mgr@CodeGreek{#1}{gamma}{103}
        \mgr@CodeGreek{#1}{delta}{100}
        \mgr@CodeGreek{#1}{epsilon}{101}
        \mgr@CodeGreek{#1}{zeta}{122}
        \mgr@CodeGreek{#1}{eta}{104}
        \mgr@CodeGreek{#1}{theta}{106}
        \mgr@CodeGreek{#1}{iota}{105}
        \mgr@CodeGreek{#1}{kappa}{107}
        \mgr@CodeGreek{#1}{lambda}{108}
        \mgr@CodeGreek{#1}{mu}{109}
        \mgr@CodeGreek{#1}{nu}{110}
        \mgr@CodeGreek{#1}{xi}{120}
        \mgr@CodeGreek{#1}{pi}{112}
        \mgr@CodeGreek{#1}{rho}{114}
        \mgr@CodeGreek{#1}{sigma}{115}
        \mgr@CodeGreek{#1}{tau}{116}
        \mgr@CodeGreek{#1}{upsilon}{117}
        \mgr@CodeGreek{#1}{phi}{102}
        \mgr@CodeGreek{#1}{chi}{113}
        \mgr@CodeGreek{#1}{psi}{121}
        \mgr@CodeGreek{#1}{omega}{119}
        \mgr@CodeGreek{#1}{varepsilon}{101} % = epsilon
        \mgr@CodeGreek{#1}{vartheta}{106} % = theta
        \mgr@CodeGreek{#1}{varpi}{112} % = pi
        \mgr@CodeGreek{#1}{varrho}{114} % = rho
        \mgr@CodeGreek{#1}{varsigma}{99}
        \mgr@CodeGreek{#1}{varphi}{102} % = phi 
    \else\ifmathgreeks@fontspec % unicode encoding
        \mgr@UnicodeGreek{#1}{Gamma}{"0393}
        \mgr@UnicodeGreek{#1}{Delta}{"0394}
        \mgr@UnicodeGreek{#1}{Theta}{"0398}
        \mgr@UnicodeGreek{#1}{Lambda}{"039B}
        \mgr@UnicodeGreek{#1}{Xi}{"039E}
        \mgr@UnicodeGreek{#1}{Pi}{"03A0}
        \mgr@UnicodeGreek{#1}{Sigma}{"03A3}
        \mgr@UnicodeGreek{#1}{Upsilon}{"03A5}
        \mgr@UnicodeGreek{#1}{Phi}{"03A6}
        \mgr@UnicodeGreek{#1}{Psi}{"03A8}
        \mgr@UnicodeGreek{#1}{Omega}{"03A9}
        \mgr@UnicodeGreek{#1}{alpha}{"03B1}
        \mgr@UnicodeGreek{#1}{beta}{"03B2}
        \mgr@UnicodeGreek{#1}{gamma}{"03B3}
        \mgr@UnicodeGreek{#1}{delta}{"03B4}
        \mgr@UnicodeGreek{#1}{epsilon}{"03B5}
        \mgr@UnicodeGreek{#1}{zeta}{"03B6}
        \mgr@UnicodeGreek{#1}{eta}{"03B7}  
        \mgr@UnicodeGreek{#1}{theta}{"03B8}
        \mgr@UnicodeGreek{#1}{iota}{"03B9}
        \mgr@UnicodeGreek{#1}{kappa}{"03BA}
        \mgr@UnicodeGreek{#1}{lambda}{"03BB}
        \mgr@UnicodeGreek{#1}{mu}{"03BC}
        \mgr@UnicodeGreek{#1}{nu}{"03BD}
        \mgr@UnicodeGreek{#1}{xi}{"03BE} % not omicron
        \mgr@UnicodeGreek{#1}{pi}{"03C0}
        \mgr@UnicodeGreek{#1}{rho}{"03C1}
        \mgr@UnicodeGreek{#1}{sigma}{"03C3}
        \mgr@UnicodeGreek{#1}{tau}{"03C4}
        \mgr@UnicodeGreek{#1}{upsilon}{"03C5}
        \mgr@UnicodeGreek{#1}{phi}{"03C6}
        \mgr@UnicodeGreek{#1}{chi}{"03C7}
        \mgr@UnicodeGreek{#1}{psi}{"03C8}
        \mgr@UnicodeGreek{#1}{omega}{"03C9}
        \mgr@UnicodeGreek{#1}{varepsilon}{"03F5}
        \mgr@UnicodeGreek{#1}{vartheta}{"03D1}
        \mgr@UnicodeGreek{#1}{varpi}{"03D6}
        \mgr@UnicodeGreek{#1}{varrho}{"03F1}
        \mgr@UnicodeGreek{#1}{varsigma}{"03C2}
        \mgr@UnicodeGreek{#1}{varphi}{"03D5}
    \else\ifmathgreeks@Symbol % Symbol encoding
        \mgr@CodeGreek{#1}{Gamma}{`G}
        \mgr@CodeGreek{#1}{Delta}{`D}
        \mgr@CodeGreek{#1}{Theta}{`Q}
        \mgr@CodeGreek{#1}{Lambda}{`L}
        \mgr@CodeGreek{#1}{Xi}{`X}
        \mgr@CodeGreek{#1}{Pi}{`P}
        \mgr@CodeGreek{#1}{Sigma}{`S}
        \mgr@CodeGreek{#1}{Upsilon}{`U}
        \mgr@CodeGreek{#1}{Phi}{`F}
        \mgr@CodeGreek{#1}{Psi}{`Y}
        \mgr@CodeGreek{#1}{Omega}{`W}
        \mgr@CodeGreek{#1}{alpha}{`a}
        \mgr@CodeGreek{#1}{beta}{`b}
        \mgr@CodeGreek{#1}{gamma}{`g}
        \mgr@CodeGreek{#1}{delta}{`d}
        \mgr@CodeGreek{#1}{epsilon}{`e}
        \mgr@CodeGreek{#1}{zeta}{`z}
        \mgr@CodeGreek{#1}{eta}{`h}
        \mgr@CodeGreek{#1}{theta}{`q}
        \mgr@CodeGreek{#1}{iota}{`i}
        \mgr@CodeGreek{#1}{kappa}{`k}
        \mgr@CodeGreek{#1}{lambda}{`l}
        \mgr@CodeGreek{#1}{mu}{`m}
        \mgr@CodeGreek{#1}{nu}{`n}
        \mgr@CodeGreek{#1}{xi}{`x}
        \mgr@CodeGreek{#1}{pi}{`p}
        \mgr@CodeGreek{#1}{rho}{`r}
        \mgr@CodeGreek{#1}{sigma}{`s}
        \mgr@CodeGreek{#1}{tau}{`t}
        \mgr@CodeGreek{#1}{upsilon}{`u}
        \mgr@CodeGreek{#1}{phi}{`f}
        \mgr@CodeGreek{#1}{chi}{`c}
        \mgr@CodeGreek{#1}{psi}{`y}
        \mgr@CodeGreek{#1}{omega}{`w}
        \mgr@CodeGreek{#1}{varepsilon}{`u} % = epsilon
        \mgr@CodeGreek{#1}{vartheta}{`J}
        \mgr@CodeGreek{#1}{varpi}{`v}
        \mgr@CodeGreek{#1}{varrho}{`r} % = rho
        \mgr@CodeGreek{#1}{varsigma}{`s} % = sigma
        \mgr@CodeGreek{#1}{varphi}{`j}  
    \else % OML (or U) encoding
        \mgr@CodeGreek{#1}{Gamma}{"00}
        \mgr@CodeGreek{#1}{Delta}{"01}
        \mgr@CodeGreek{#1}{Theta}{"02}
        \mgr@CodeGreek{#1}{Lambda}{"03}
        \mgr@CodeGreek{#1}{Xi}{"04}
        \mgr@CodeGreek{#1}{Pi}{"05}
        \mgr@CodeGreek{#1}{Sigma}{"06}
        \mgr@CodeGreek{#1}{Upsilon}{"07}
        \mgr@CodeGreek{#1}{Phi}{"08}
        \mgr@CodeGreek{#1}{Psi}{"09}
        \mgr@CodeGreek{#1}{Omega}{"0A}
        \mgr@CodeGreek{#1}{alpha}{"0B}
        \mgr@CodeGreek{#1}{beta}{"0C}
        \mgr@CodeGreek{#1}{gamma}{"0D}
        \mgr@CodeGreek{#1}{delta}{"0E}
        \mgr@CodeGreek{#1}{epsilon}{"0F}
        \mgr@CodeGreek{#1}{zeta}{"10}
        \mgr@CodeGreek{#1}{eta}{"11}
        \mgr@CodeGreek{#1}{theta}{"12}
        \mgr@CodeGreek{#1}{iota}{"13}
        \mgr@CodeGreek{#1}{kappa}{"14}
        \mgr@CodeGreek{#1}{lambda}{"15}
        \mgr@CodeGreek{#1}{mu}{"16}
        \mgr@CodeGreek{#1}{nu}{"17}
        \mgr@CodeGreek{#1}{xi}{"18}
        \mgr@CodeGreek{#1}{pi}{"19}
        \mgr@CodeGreek{#1}{rho}{"1A}
        \mgr@CodeGreek{#1}{sigma}{"1B}
        \mgr@CodeGreek{#1}{tau}{"1C}
        \mgr@CodeGreek{#1}{upsilon}{"1D}
        \mgr@CodeGreek{#1}{phi}{"1E}
        \mgr@CodeGreek{#1}{chi}{"1F}
        \mgr@CodeGreek{#1}{psi}{"20}
        \mgr@CodeGreek{#1}{omega}{"21}
        \mgr@CodeGreek{#1}{varepsilon}{"22}
        \mgr@CodeGreek{#1}{vartheta}{"23}
        \mgr@CodeGreek{#1}{varpi}{"24}
        \mgr@CodeGreek{#1}{varrho}{"25}
        \mgr@CodeGreek{#1}{varsigma}{"26}
        \mgr@CodeGreek{#1}{varphi}{"27}
        %\mgr@CodeGreek{#1}{varkappa}{"FE}
    \fi\fi\fi
}

\newcommand\mgr@DefaultGreeks{%
    \ifmathgreeks@uppercase
      \ifmathgreeks@Greekup
        \let\Gamma\upGamma
        \let\Delta\upDelta
        \let\Theta\upTheta
        \let\Lambda\upLambda
        \let\Xi\upXi
        \let\Pi\upPi
        \let\Sigma\upSigma
        \let\Upsilon\upUpsilon
        \let\Phi\upPhi
        \let\Psi\upPsi
        \let\Omega\upOmega 
      \else
        \let\Gamma\itGamma
        \let\Delta\itDelta
        \let\Theta\itTheta
        \let\Lambda\itLambda
        \let\Xi\itXi
        \let\Pi\itPi
        \let\Sigma\itSigma
        \let\Upsilon\itUpsilon
        \let\Phi\itPhi
        \let\Psi\itPsi
        \let\Omega\itOmega
    \fi\fi  
    \ifmathgreeks@lowercase
      \ifmathgreeks@greekup
        \let\alpha\upalpha
        \let\beta\upbeta
        \let\gamma\upgamma
        \let\delta\updelta
        \let\epsilon\upepsilon
        \let\zeta\upzeta
        \let\eta\upeta
        \let\theta\uptheta
        \let\iota\upiota
        \let\kappa\upkappa
        \let\lambda\uplambda
        \let\mu\upmu
        \let\nu\upnu
        \let\xi\upxi
        \let\pi\uppi
        \let\rho\uprho
        \let\sigma\upsigma
        \let\tau\uptau
        \let\upsilon\upupsilon
        \let\phi\upphi
        \let\chi\upchi
        \let\psi\uppsi
        \let\omega\upomega
        \let\varepsilon\upvarepsilon
        \let\vartheta\upvartheta
        \let\varpi\upvarpi
        \let\varrho\upvarrho
        \let\varsigma\upvarsigma
        \let\varphi\upvarphi  
      \else
        \let\alpha\italpha
        \let\beta\itbeta
        \let\gamma\itgamma
        \let\delta\itdelta
        \let\epsilon\itepsilon
        \let\zeta\itzeta
        \let\eta\iteta
        \let\theta\ittheta
        \let\iota\itiota
        \let\kappa\itkappa
        \let\lambda\itlambda
        \let\mu\itmu
        \let\nu\itnu
        \let\xi\itxi
        \let\pi\itpi
        \let\rho\itrho
        \let\sigma\itsigma
        \let\tau\ittau
        \let\upsilon\itupsilon
        \let\phi\itphi
        \let\chi\itchi
        \let\psi\itpsi
        \let\omega\itomega
        \let\varepsilon\itvarepsilon
        \let\vartheta\itvartheta
        \let\varpi\itvarpi
        \let\varrho\itvarrho
        \let\varsigma\itvarsigma
        \let\varphi\itvarphi
    \fi\fi
}

\providecommand\SaveGreeks{%
    \let\backGamma\Gamma
    \let\backDelta\Delta
    \let\backTheta\Theta
    \let\backLambda\Lambda
    \let\backXi\Xi
    \let\backPi\Pi
    \let\backSigma\Sigma
    \let\backUpsilon\Upsilon
    \let\backPhi\Phi
    \let\backPsi\Psi
    \let\backOmega\Omega    
    \let\backalpha\alpha
    \let\backbeta\beta
    \let\backgamma\gamma
    \let\backdelta\delta
    \let\backepsilon\epsilon
    \let\backzeta\zeta
    \let\backeta\eta
    \let\backtheta\theta
    \let\backiota\iota
    \let\backkappa\kappa
    \let\backlambda\lambda
    \let\backmu\mu
    \let\backnu\nu
    \let\backxi\xi
    \let\backpi\pi
    \let\backrho\rho
    \let\backsigma\sigma
    \let\backtau\tau
    \let\backupsilon\upsilon
    \let\backphi\phi
    \let\backchi\chi
    \let\backpsi\psi
    \let\backomega\omega    
    \let\backvarepsilon\varepsilon
    \let\backvartheta\vartheta
    \let\backvarpi\varpi
    \let\backvarrtho\varrho
    \let\backvarsigma\varsigma
    \let\backvarphi\varphi
}


%%%%%%%%%%%%%% Macros for changing font dynamically %%%%%%%%%%%%%

\def\setmathgreeks#1{\setkeys{mathgreeks}{#1}\unskip
    \ifmathgreeks@upgreek 
        \mathgreeks@Greekuptrue 
        \mathgreeks@greekuptrue
        \PackageWarning{mathgreeks}{Style is set to `upright'
            \MessageBreak with the `upgreek' option}
    \fi
    \mgr@DefaultGreeks\ignorespaces
}

\newif\ifmgrfont@unicodemath
\define@key{mgrfont}{unicode-math}[Latin Modern Math]{%
    \def\mgrfont@unicodemath{#1}\mgrfont@unicodemathtrue}
\newif\ifmgrfont@fontspec
\define@key{mgrfont}{fontspec}[GFS Didot]{%
    \def\mgrfont@fontspec{#1}\mgrfont@fontspectrue}
\define@key{mgrfont}{enc}{\def\mgrfont@enc{#1}}
\define@key{mgrfont}{fam}{\def\mgrfont@fam{#1}}
\newcommand*\mgrfont@series{m} % default value
\define@key{mgrfont}{series}{\renewcommand*\mgrfont@series{#1}}
\newcommand*\mgrfont@shape{it} % default value
\define@key{mgrfont}{shape}{\renewcommand*\mgrfont@shape{#1}}

\def\mathgreeksfont#1{%
    \mgrfont@unicodemathfalse
    \mgrfont@fontspecfalse
    \renewcommand*\mgrfont@series{m}
    \renewcommand*\mgrfont@shape{it}
    \mathgreeks@lgrmathfalse
    \mathgreeks@fontspecfalse
    \mathgreeks@Symbolfalse
    \mathgreeks@upgreekfalse
    \setkeys{mgrfont}{#1}
    \ifmgrfont@unicodemath
        \setmathfont{\mgrfont@unicodemath}[range=it/{greek,Greek}]
        \setmathfont{\mgrfont@unicodemath}[range=up/{greek,Greek}]
        \let\mgr@UnicodeGreek\mgr@UnicodemathGreek
        \mathgreeks@fontspectrue % for \mgr@CodeGreeks
        \mgr@CodeGreeks{it}
        \mgr@CodeGreeks{up}
        \mgr@DefaultGreeks
    \else\ifmgrfont@fontspec
        \let\MathGreeksFont\relax
        \newfontfamily\MathGreeksFont{\mgrfont@fontspec}
        \let\mgr@UnicodeGreek\mgr@NewUnicodeGreek
        \mathgreeks@fontspectrue
        \mgr@CodeGreeks{it}
        \mgr@CodeGreeks{up}
        \mgr@DefaultGreeks
    \else
        \let\mgr@CodeGreek\mgr@NewCodeGreek
        \ifdefstring{\mgrfont@enc}{LGR}{
            \mathgreeks@lgrmathtrue
        }{
        \ifdefstring{\mgrfont@fam}{psy}{
            \mathgreeks@Symboltrue
        }{
        \ifdefstring{\mgrfont@fam}{fsy}{
            \mathgreeks@Symboltrue
        }{
        }}}
        \mgr@CodeGreeks{}
    \fi\fi
}

\def\mgr@NewCodeGreek#1#2#3{\unskip
    \expandafter\DeclareRobustCommand\csname#1#2\endcsname
        {\mathalpha{\text{\usefont{\mgrfont@enc}{\mgrfont@fam}
            {\mgrfont@series}{\mgrfont@shape}\symbol{#3}}
        }}\ignorespaces
}

\def\mgr@NewUnicodeGreek#1#2#3{\unskip % only with fontspec
    \expandafter\DeclareRobustCommand\csname#1#2\endcsname
        {\mathalpha{\text{\csname#1shape\endcsname%
            \MathGreeksFont\symbol{#3}}
        }}\ignorespaces
}

\providecommand\greektable{
    $\begin{array}{c}
      \begin{array}{*{23}{@{\;}c}@{\;}}
        \alpha & \beta & \gamma & \delta & \epsilon & \zeta & \eta &
        \theta & \iota & \kappa & \lambda & \mu & \nu & \xi & \pi &
        \rho & \sigma & \tau & \upsilon & \phi & \chi & \psi & \omega
      \end{array} 
    \\
      \begin{array}{*{18}{@{\;}c}@{\;}}
        \varepsilon & \vartheta & \varpi & \varrho & \varsigma & \varphi
        & | &
        \Gamma & \Delta & \Theta & \Lambda & \Xi & \Pi & \Sigma &
        \Upsilon & \Phi & \Psi & \Omega
      \end{array}
    \end{array}$
}

%    \end{macrocode}
% \Finale
\endinput
