[Tex/LaTex] ebgaramond interface for newtxmath

ebgaramondfontsmath-mode

Remarks

The newtxmath-package comes with support for various fonts, including libertine, minion or garamondx. Personally I like the Garamond very much, but garamondx is not part of the default installation. Thus I use ebgaramond instead.

To do so, I just copied the part, where the fonts are set up from newtxmath.

Problem statement

Here is a minimal NOT working example of what I have tried so far to load ebgaramond as a math alphabet. (unicode-math or mathspec is not an option, it needs to be pdflatex compatible)

\documentclass{article}
\usepackage{ebgaramond}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\DeclareSymbolFont{letters}{OML}{EBGaramond12-Italic-lf-t1--base}{m}{it}
\SetSymbolFont{letters}{bold}{OML}{EBGaramond12-Italic-lf-t1--base}{b}{it}
\DeclareFontSubstitution{OML}{EBGaramond12-Italic-lf-t1--base}{m}{it}
\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ

abcdefghijklmnopqrstuvwxyz

1234567890

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$abcdefghijklmnopqrstuvwxyz$

$1234567890$
\end{document}

Bonus question

How can I use swash glyphs as mathcal alphabet?


EDIT 2014-01-03

Pointed out by cfr's comment, the question reduces to How can I create OML files for ebgaramond? (The bonus question remains valid)

Best Answer

Update

The simplest solution is now to use ebgaramond-maths, a new package available from CTAN.

ebgaramond-maths is now included in TeX Live. If you have TeX Live 2014 installed, you should get the package when you update. (For example, running tlmgr update --all at the command line or using your GUI wrapper of choice.)

The answer below is now likely to be useful only if you want to tweak the results or apply the method to a different font.

Original Answer

Setting up the \mathcal stuff is relatively straightforward. Setting up the OML support is less so.

Provide OML support for EBGaramond

Several approaches are possible. I've taken what seemed to me to be the simplest given the way the existing ebgaramond package works. I would probably do this differently if I was generating support for both text and mathematics from scratch but in this case I'm trying to avoid duplication of effort as much as possible.

Variables

  • Make a working directory somewhere which I'll call ${work}. Doesn't matter where so long as you have permission to write there. (Don't do this as root, obviously.)

  • I'll call ${texmain} your main, current texmf directory. On my system, that's /usr/local/texlive/current or /usr/local/texlive/2013.

Working environment

Change to ${work}. From now on, I assume that all commands are executed in this directory and that all created files are saved here.

Copy needed files to your working directory or make symbolic links if preferred:

cp ${texmain}/texmf-dist/tex/fontinst/mathetx/oml.etx ${texmain}/texmf-dist/fonts/opentype/public/ebgaramond/EBGaramond12-Italic.otf ./

or

ln -s ${texmain}/texmf-dist/tex/fontinst/mathetx/oml.etx ${texmain}/texmf-dist/fonts/opentype/public/ebgaramond/EBGaramond12-Italic.otf ./

Create a preliminary encoding file

This is not the encoding file you'll finally tell TeX about but it will form the basis for that file.

First, run fontinst in interactive mode. (That is, just type 'fontinst' as the command.) At the prompt:

\input finstmsc.sty
\etxtoenc{oml}{oml-ebgaramond}
\bye

This will produce oml-ebgaramond.enc which you can lightly modify before feeding to otftotfm.

sed -i -e 's/TeXMathItalicEncoding/EBGaramondTeXMathItalicEncoding/g' -e 's/oldstyle//' oml-ebgaramond.enc

Generate the TeX font

ebgaramond already provides the type1 files you need so there is no need to regenerate those. All that is required is to generate a suitable .tfm.

otftotfm -e oml-ebgaramond.enc EBGaramond12-Italic.otf > EBGaramond-Maths.map

This will create both the .tfm file and the .map file fragment TeX needs to use the font. Essentially, the .tfm just is a font as far as TeX is concerned. (pdfTeX sees things slightly differently - it wants the type1 bit as well.)

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 .map file fragment. oml-ebgaramond.enc can now be deleted if you wish as it is no longer required.

Create the font definition for LaTeX

otftotfm does not generate font definition files for LaTeX as far as I can tell but the file is pretty simple in this case. Create a file with the following content:

%Filename: OMLEBGaramond-Maths.fd
%Based on a file created using fontinst v1.928

%THIS FILE SHOULD BE PUT IN A TEX INPUTS DIRECTORY

\ProvidesFile{OMLEBGaramond-Maths.fd}
   [2014/01/03 font definitions for OML/EBGaramond-Maths.]

\DeclareFontFamily{OML}{EBGaramond-Maths}{}

\DeclareFontShape{OML}{EBGaramond-Maths}{m}{it}{
   <-> EBGaramond12-Italic--oml-ebgaramond
}{}

\DeclareFontShape{OML}{EBGaramond-Maths}{b}{it}{<->ssub * EBGaramond-Maths/m/it}{}
\DeclareFontShape{OML}{EBGaramond-Maths}{bx}{it}{<->ssub * EBGaramond-Maths/m/it}{}

\endinput

and save it as OMLEBGaramond-Maths.fd. This tells LaTeX what the font family EBGaramond-Maths consists of in the OML encoding. Specifically, it tells it which TeX fonts belong to this family in this encoding and the characteristics of each one. (In this case, there's only one such font which is then substituted for other weights as there is no bold in EBGaramond and OML only cares about the italic shape.)

Create a package file for LaTeX (optional)

It is generally easier to load a package than repeat the font set up each time you wish to use a particular configuration, so I would create a LaTeX package. To do so, create another file with the following content:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ebgaramond-maths}[2014/01/03 v1.0 ebgaramond-maths for use with EBGaramond]

\RequirePackage{ebgaramond}

% \pdfmapfile{+EBGaramond-Maths.map}

\DeclareSymbolFont{letters}   {OML}   {EBGaramond-Maths} {m} {it}
\DeclareSymbolFont{operators} {OT1}   {EBGaramond-LF}    {m} {n}

\SetSymbolFont{letters}   {bold}  {OML} {EBGaramond-Maths} {b}  {it}
\SetSymbolFont{operators} {bold}  {OT1} {EBGaramond-LF}    {bx} {n}

\DeclareFontSubstitution{OML}{EBGaramond-Maths}{m}{it}
\DeclareFontSubstitution{OT1}{EBGaramond-LF}{m}{n}

\SetMathAlphabet{\mathbf}   {normal}  {OT1} {EBGaramond-LF} {bx} {n}
\SetMathAlphabet{\mathbf}   {bold}    {OT1} {EBGaramond-LF} {bx} {n}
\SetMathAlphabet{\mathit}   {normal}  {OT1} {EBGaramond-LF} {m}  {it}
\SetMathAlphabet{\mathit}   {bold}    {OT1} {EBGaramond-LF} {bx} {it}

\DeclareMathAlphabet{\mathcal} {OT1} {EBGaramond-LF} {m} {sw}

\endinput

and save it as ebgaramond-maths.sty.

  • If you do not wish to ask people to install the fonts, uncomment the relevant line in the .sty file.

Then, from ${work} the result can be tested prior to installation of the fonts:

\documentclass{article}
\usepackage{ebgaramond}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\pdfmapfile{+EBGaramond-Maths.map}
\usepackage{ebgaramond-maths}

\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ

abcdefghijklmnopqrstuvwxyz

1234567890

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$abcdefghijklmnopqrstuvwxyz$

$1234567890$

$\Gamma\varGamma\Delta\Lambda\varLambda\Xi\varXi\Pi\varPi\Sigma\varSigma\Upsilon\varUpsilon\Phi\varPhi\Psi\varPsi\Omega\varOmega$

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

$\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

$\mathbf{abcdefghijklmnopqrstuvwxyz}$

$\mathbf{0123456789}$

$\mathit{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

$\mathit{abcdefghijklmnopqrstuvwxyz}$

$\mathit{0123456789}$

$\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

$\mathrm{abcdefghijklmnopqrstuvwxyz}$

$\mathrm{0123456789}$

$\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

$\mathcal{abcdefghijklmnopqrstuvwxyz}$

$\mathcal{0123456789}$

\end{document}

produces:

enter image description here

Related Question