%% Copyright 2019 Clea F. Rees
%
% This work 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.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clea F. Rees.
%
% This work consists of all files listed in manifest.txt.

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
% arara: pdflatex: { synctex: true }

\documentclass[12pt,british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{csquotes}
   \MakeAutoQuote{‘}{’}
   \MakeAutoQuote*{“}{”}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr,fancyref,enumitem,pageslts,upquote,array,booktabs}
\usepackage{verbatim}
\usepackage{url}
        \urlstyle{tt}
\usepackage{hyperref}
\usepackage[sf,scale=0.95,ttscale=.9]{libertine}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\pdfmapfile{+EBGaramond-Maths.map}
\usepackage{ebgaramond-maths}
\usepackage{microtype}
\usepackage[headheight=15pt]{geometry}

\title{ebgaramond-maths\thanks{Version 1.2 2019--09--24.}}
\author{Clea F.\ Rees\footnote{\liningfam ReesC21 <at> cardiff <dot> ac <dot> uk}}
\newcommand*{\dyddiad}{24\textsu{th} September, 2019}
\date{\dyddiad}
\pagestyle{fancy}
        \fancyhf[lh]{\itshape ebgaramond-maths}
        \fancyhf[rh]{\itshape\dyddiad}
        \fancyhf[ch]{}
        \fancyhf[lf]{}
        \fancyhf[rf]{}
        \fancyhf[cf]{\itshape \thepage~\ofname~\lastpageref*{LastPage}}

\makeatletter% am unrhyw reswm, dyw ebgaramond ddim yn diffinio'r rhai hyn
  \DeclareRobustCommand{\oldstylefam}{\fontfamily{EBGaramond-\ebgaramond@figurealign OsF}\selectfont}
  \DeclareRobustCommand{\liningfam}{\fontfamily{EBGaramond-\ebgaramond@figurealign LF}\selectfont}
  \DeclareRobustCommand{\tabularfam}{\fontfamily{EBGaramond-T\ebgaramond@figurestyle}\selectfont}
  \DeclareRobustCommand{\proportionalfam}{\fontfamily{EBGaramond-\ebgaramond@figurestyle}\selectfont}
\makeatother

\begin{document}
\pagenumbering{arabic}% pageslts eisiau hyn
\maketitle\thispagestyle{empty}
\pdfinfo{%
        /Creator   (TeX)
        /Producer  (pdfTeX)
        /Author    (Clea F.\ Rees)
        /Title     (ebgaramond-maths)
        /Subject   (TeX)
        /Keywords  (TeX, LaTeX, font, fonts, tex, latex, ebgaramond-maths, EBGaramond, ebgaramond, EBGaramond, maths, mathematics, Clea, Rees)}
\pdfcatalog{%
        /URL       ()
        /PageMode  /UseOutlines}

\newcommand*{\lpack}[1]{\textsf{#1}}

\begin{abstract}
  \liningfam
  \noindent\lpack{ebgaramond-maths} provides some \LaTeX\ support for the use of EBGaramond in mathematics.
  It requires \lpack{ebgaramond} and uses the postscript fonts provided by that package\footnote{This version corresponds to the 2019--05--04 version of \lpack{ebgaramond}.}.
  The package essentially consists of the files generated by an answer to a question at \url{http://tex.stackexchange.com/q/152038/} and is a response to a follow-up request by the author of that question.
\end{abstract}

\section{Introduction}\label{sec:intro}
% BEGIN sec:intro
There is not really much to document.
To use EBGaramond in mathematics, you just load the package:
\begin{quote}
\begin{verbatim}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\usepackage{ebgaramond-maths}
\end{verbatim}
\end{quote}
Note that this will also load \lpack{ebgaramond} which will set your default serif font to \liningnums{EBGaramond}.
If for any reason you do not want this, note two things.
First, your document will be a typographic abomination.
Second, you can easily create the abomination of your choice by changing the default serif family \emph{after} loading \lpack{ebgaramond-maths}.
% END sec:intro

\section{Details}\label{sec:manylion}
% BEGIN sec:manylion

The package includes \verb|.tfm| and \verb|.map| files which define EBGaramond-Maths, a new \TeX\ font for \LaTeX.
This font uses \liningnums{EBGaramond-Italic} with an OML encoding.
However, not all characters in this encoding are available (see \fref{tab:dim}).
Note that this is a limitation of the font itself and not of this package.

\begin{table}
  \centering
  \begin{tabular}{llll}
	\toprule
	\string\leftharpoonup & \string\triangleright & \string\flat & \string\smile\\
	\string\leftharpoondown & \string\triangleleft &  \string\natural & \string\frown\\
	\string\rightharpoonup & \string\star & \string\sharp & \string\vec\\
	\string\rightharpoondown & \string\partial & & \string\t\\
	\bottomrule
  \end{tabular}
  \caption{Symbols missing from EBGaramond}\label{tab:dim}
\end{table}


\lpack{ebgaramond-maths} uses this new font together with support files from \lpack{ebgaramond} to set up support for mathematics as follows:
\begin{itemize}
  \item EBGaramond-Maths (medium weight) is used for \verb|letters| (standard and bold);
  \item EBGaramond-LF (medium weight, upright shape) is used for \verb|operators| (standard and bold);
  \item EBGaramond-LF (medium weight, swash shape) is used for the calligraphic alphabet, \verb|\mathcal| (medium weight);
  \item \verb|\mathrm|, \verb|\mathbf| and \verb|\mathit| should work as expected and use EBGaramond-LF (medium weight, upright or italic shape as appropriate).
\end{itemize}

Note that \liningnums{EBGaramond} does not include a bold weight by design.
Following the designer's intentions, this package, like \lpack{ebgaramond}, substitutes the medium weight for bold where required.
% END sec:manylion

\section{Method}\label{sec:dull}
% BEGIN sec:dull

If you just wish to use the package, you do not need to read this section.
It explains how to create the font support files used by the package given that you have \lpack{ebgaramond} installed.
It assumes that you are using TeX Live on GNU/Linux or another Unix-like system such as OS X.

\subsection{Variables}\label{subsec:var}
% BEGIN subsec:var
Make a working directory somewhere which I'll call \verb|${work}|.
The only requirement is that you have permission to write there and a (very small) amount of space.
(It goes without saying that this should not be done as root.)

In the instructions which follow \verb|${texmain}| is your main, current \verb|texmf| directory.
On my system, that's \verb|/usr/local/texlive/YYYY| (where \verb|YYYY| is the latest version of TeX Live installed) or \verb|/usr/local/texlive/current|.
% END subsec:var

\subsection{Working environment}\label{subsec:amgylchedd}

% BEGIN subsec:amgylchedd
Change to \verb|${work}|.
From now on, I assume that all commands are executed in this directory and that all created files are saved there.

Create the following symbolic links in your working directory:

\begin{quote}
\begin{verbatim}
ln -s ${texmain}/texmf-dist/tex/fontinst/mathetx/oml.etx \
  ${texmain}/texmf-dist/fonts/opentype/public/ebgaramond/\
  EBGaramond-Italic.otf ./
\end{verbatim}
\end{quote}
% END subsec:amgylchedd

\subsection{Create a preliminary encoding file}\label{subsec:creu-enc}
% BEGIN subsec: creu-enc
This is not the encoding file \TeX\ needs but it will form the basis for that file.

First, run \verb|fontinst| in interactive mode.
(That is, just type \verb|fontinst| at the command.)
At the prompt:
\begin{quote}
\begin{verbatim}
\input finstmsc.sty
\etxtoenc{oml}{oml-ebgaramond}
\bye
\end{verbatim}
\end{quote}

This will produce \verb|oml-ebgaramond.enc| which should be lightly modified before feeding to \verb|otftotfm|:

\begin{quote}
\begin{verbatim}
sed -i -e 's/TeXMathItalicEncoding/\
  EBGaramondTeXMathItalicEncoding/g' \
  -e 's/oldstyle//' oml-ebgaramond.enc
\end{verbatim}
\end{quote}

This ensures that the encoding has a distinctive (and hopefully unique) name.
% END subsec: creu-enc

\subsection{Generate the \TeX\ font}\label{subsec:tfm}
% BEGIN subsec:tfm
\lpack{ebgaramond} already provides the \liningnums{type1} files needed so there is no need to regenerate those.
All that is required is to generate a suitable \verb|.tfm|:

\begin{quote}
\begin{verbatim}
otftotfm -e oml-ebgaramond.enc EBGaramond-Italic.otf \
  > EBGaramond-Maths.map
\end{verbatim}
\end{quote}

This will create both the \verb|.tfm| file and the \verb|.map| file fragment \TeX\ needs to use the font.
It will also create a new encoding file with what will almost certainly be a very weird name.
This is the encoding file \TeX\ will use, as specified in the \verb|.map| file fragment.
The temporary encoding \verb|oml-ebgaramond.enc| can now be deleted as it is no longer required.
% END subsec:tfm

% END sec:dull
\end{document}
