15

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)

Mico
  • 506,678
Henri Menke
  • 109,596
  • This doesn't work because there is no font definition file for EBGaramond12-Italic-lf-t1--base in the OML encoding. First, that is not a font family name. Second, no support is provided in ebgaramond for OML at all. Assuming that the fonts themselves include the required characters, you would need to generate additional support files in order to use the OML encoding in regular LaTeX/pdfLaTeX. Basically this involves supplementing or replacing the existing ebgaramond support package. This is not especially difficult if you are sufficiently persistent but it is time-consuming and a bit fiddly. – cfr Jan 01 '14 at 19:05
  • It should be more straightforward to setup the swash characters for mathcal, at least assuming that the mathcal alphabet doesn't need to contain much else. – cfr Jan 01 '14 at 19:07
  • Do you know that it is very easy to install garamondx using the getnonfreefonts script? That would surely be by far the simplest solution. – cfr Jan 01 '14 at 19:08
  • I'd accept an answer pointing out, how to create the OML support files - I will also offer a bounty. Using getnonfreefonts is only a practical solution on my own computer. – Henri Menke Jan 03 '14 at 07:40
  • I don't typeset much mathematics and I'm not very familiar with the set up for maths fonts. What exactly should the output look like? The upper and lower case letters should be in the italic shape of EBGaramond, I assume. What about the numbers? Right now, I'm getting OSF upright numbers in both text and maths when I typeset your sample and I'm not sure that is correct! It shouldn't be terribly difficult to get what is wanted into the OML files. I'm just not sure what I'm trying to do right now. – cfr Jan 03 '14 at 20:24
  • @cfr The matching font shapes to \mathrm, \mathit, \mathbf, etc. should be available. Also math mode has to have lining figures. – Henri Menke Jan 03 '14 at 20:28
  • But not from OML, I don't think. OML encodes oldstyle figures. OK. The numbers come from OT1. That's fine. I don't know what the oldstyle figures in OML do if they aren't used in maths but TeX doesn't take figures from OML in maths mode. The font doesn't seem to have all of the symbols in OML, though, or else they are named non-standardly. – cfr Jan 03 '14 at 21:24
  • So running a comparison with the lmodern package, \mathrm gets upright upper/lower case and figures, \mathit gets italic upper/lower case and figures, and \mathbf gets upright upper/lower case and figures (in bold for LM, in regular for EBGaramond since there is no bold). Should \mathbf do something different in this case? – cfr Jan 03 '14 at 21:55
  • Also, I take it \mathcal should use italic swash for upper case. What should it do for lower case and figures? (Or does this not really matter? lmodern gives me a bunch of symbols in these cases.) – cfr Jan 03 '14 at 22:44
  • What OS are you using? – cfr Jan 03 '14 at 23:01
  • You should add, which TeX distribution you use (TeX Live I guess …). With MiKTeX garamondx can easily be installed with the Package Manager, in TeX Live it seems by using the getnonfreefonts script, but also manually into a local TeXMF tree: http://mirror.ctan.org/fonts/garamondx.zip and Manual font installation. – Speravir Jan 03 '14 at 23:36
  • @Speravir Yes but the OP has already explained that installing garamondx is not an acceptable solution. – cfr Jan 03 '14 at 23:40
  • Oh, I overlooked this. But why is creating OML files (if a solution would be found) in a local TeXMF acceptable? Or is this meant as a feature request to the ebgaramond author? – Speravir Jan 03 '14 at 23:50
  • @Speravir Well it is possible to bundle everything produced with your document, if necessary, so people don't have to install anything. Whereas you can't bundle garamondx because the fonts can't be distributed. I don't know if this is the OP's reason or not, but it is one possible explanation which would make sense. I wonder, actually, if it would be better to just release my solution as a package but I worry that it would be bad to do that for something so dependent on another package. (Though cfr-lm is similarly dependent on lmodern. But I use that myself so it is tested a bit more.) – cfr Jan 04 '14 at 00:28
  • @cfr You may be right, I simply didn’t thought of this possibility. BTW You could ask the author yourself … – Speravir Jan 04 '14 at 00:33
  • @cfr @Speravir To answer some of your questions: I'm using TeXlive 2013 on GNU/Linux; Honestly I don't even know, what \mathcal does right now for lower case input; This is meant to be a feature request for either a package or a contribution to ebgaramond or newtxmath. – Henri Menke Jan 04 '14 at 15:40
  • @HenriMenke That's helpful. The way I've defined \mathcal it is equivalent to \mathit for lower case and numbers. I couldn't find any guidance on what it should do for anything except upper case (where it uses the swash as requested). The \mathcal bit is actually not at all difficult - at least defining it as I did - because ebgaramond already provides access to the swash characters in a more-or-less suitable encoding. – cfr Jan 04 '14 at 16:50

2 Answers2

19

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

cfr
  • 198,882
  • Thank you for your really detailed answer. I will try it out as soon as possible. I will award the bounty, when TeX.SX lets me do it. – Henri Menke Jan 04 '14 at 15:41
  • No worries. Let me know how it goes. It is always hard to think exactly what I do to explain it so let me know if anything seems to be missing or doesn't make sense. Since you are using TL 2013 on GNU/Linux, it should all apply fairly straightforwardly but the proof is in the pudding, as they say. – cfr Jan 04 '14 at 16:45
  • @HenriMenke Did you get this working in the end? – cfr Mar 11 '14 at 02:11
  • I finally tried it out, because I just typeset a document using ebgaramond. It works like a charm, thanks to perfect and straight forward explanations! – Henri Menke May 04 '14 at 14:39
  • @HenriMenke Brilliant! Thanks so much for letting me know. – cfr May 04 '14 at 14:52
  • 1
    Would you mind uploading this as a package to CTAN, that we can all enjoy it in TeXlive 2014? (This would be worth definitely worth another 200 rep bounty) – Henri Menke May 04 '14 at 15:05
  • @HenriMenke Hmmm... I will see what I can do. I don't know what the timeline for TL 2014 is, though, so I can't guarantee I will have time to do it in time for the initial release. (I don't know when they are freezing updates this year.) – cfr May 04 '14 at 18:02
  • 1
    There's no rush. – Henri Menke May 04 '14 at 18:20
  • 2
    @HenriMenke I hope you meant that last comment as I just uploaded to ctan. (However, I always get the format wrong so I doubt that this particular attempt will succeed. I'm pretty sure this is not entirely my fault and that they do change their minds. Though I'm not claiming to be entirely blameless, either. In any case, somebody will probably tell me which layout they want.) – cfr Sep 02 '14 at 02:28
  • @HenriMenke Seems I did it right for once. Please see edited answer for link. – cfr Sep 02 '14 at 20:27
  • @HenriMenke I just got this installed when I updated TeX Live so you should get it when you update, modulo mirror-syncing. – cfr Sep 03 '14 at 23:57
0

If only the math font is needed then

\documentclass{article}
\usepackage[ebgaramond]{newtxmath}
\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ

abcdefghijklmnopqrstuvwxyz

1234567890

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$abcdefghijklmnopqrstuvwxyz$

$1234567890$ \end{document}

only math

but if ebgaramond is needed in text too, then

\documentclass{article}
\usepackage[ebgaramond]{newtx}
\begin{document}
ABCDEFGHIJKLMNOPQRSTUVWXYZ

abcdefghijklmnopqrstuvwxyz

1234567890

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$abcdefghijklmnopqrstuvwxyz$

$1234567890$ \end{document}

math and text