1

I've created a custom handwritten style font complete with various mathematical symbols and glyphs. I'm relatively new to LaTeX, and I'm trying to see if this is even possible. I'd like all text, numbers, symbols, and mathematical operators to be expressed in my custom font.

How can I achieve this? A beginner-friendly explanation would be greatly appreciated!

Sebastiano
  • 54,118
Dotoree
  • 11
  • 4
    Welcome to TeX StackExchange. That depends a bit on your precise situation: Which format does your font have (OpenType?)? Which TeX engine do you want to use (It will be easier with XeTeX or LuaTeX, pdfTeX requires more work)? How complete is your font (There are many mathematical symbols, you might have to import external glyphs)? – Marcel Krüger Jul 03 '20 at 16:38
  • You might open an OpenType math font, such as XITS Math, in fontforge and have a look. If you save as OpenType, it’s possible to create legacy 8-bit T1/OT1/OML/OMX math fonts from that. – Davislor Jul 04 '20 at 01:04
  • @MarcelKrüger Cheers for the comment! It is an Opentype font and it has enough symbols to cover all of highschool - introductory university mathematics, which is all I intend to use it for, so not particularly concerned about missing glyphs, although it would be nice to be able to import missing glyphs from other fonts if ever need be. I'm not familiar with the different types of TeX engines, but I intend to export the equations as svgs (or any other format) for use in presentations and video animations. – Dotoree Jul 05 '20 at 13:22
  • @Davislor Thanks for the input! Could you clarify the next steps after creating the legacy math font? There seems to be a lot of different packages and methods of using the font, so any pointers would be appreciated. – Dotoree Jul 05 '20 at 13:25
  • If you create an OpenType font with a MATH table and other math features such as subscripts and sub-sub-scripts, you can load it with LuaLaTeX and XeLaTeX using the package unicode-math. There are many examples. This is much, much more elegant than trying to make a bunch of 8-bit symbol fonts and hack together a package that works. – Davislor Jul 05 '20 at 19:15
  • To get equations in SVG, you might compile them to PDF with \documentclass{standalone} and convert from PDF to SVG. – Davislor Jul 05 '20 at 19:17

1 Answers1

4

You wrote that you have an OpenType font and you want to export equations in SVG files. Then it is probably best if you you XeTeX as TeX engine because that allows you to use your OpenType font directly and it works great with dvisvgm, a program to convert TeX output to SVG.

Before using your font as math font, you have to make sure that it contains all the metadata expected from Math fonts. How to do this depends on the program you use for creating the font, but e.g. in FontForge, you can find it under Element > Other Info > MATH Info. There one of the biggest and most important categories are the Constants. Short descriptions of the meaning of each of these can be found at https://docs.microsoft.com/en-us/typography/opentype/spec/math#mathconstants-table, including suggested values for some of them. If you are not sure about some of them it can help to look into other OpenType math fonts like Latin Modern Math to get some inspiration. This menu also allows you to setup extensible delimiters, accents, italic correction etc.

But let's assume that all that is already done. Then you can load the font in XeLaTeX: The easiest way here is to use unicode-math:

\documentclass{standalone}
\usepackage{unicode-math}
\setmathfont{my-mystery-math-font.otf}
\begin{document}
Now let's write some Math in our new font:
\[a^2+b^2=c^2.\]
\end{document}

This has to be compiled with XeLaTeX, so run xelatex instead of pdflatex in your shell or select the XeLaTeX option in your editor.

  • I would recommend LuaLaTeX, which is still being actively developed. XeTeX is only getting bug fixes. – Davislor Jul 05 '20 at 19:11
  • 1
    @Davislor Under most circumstances I would agree, but (at least until TeXLive 2021 is released) dvisvgm can't handle OpenType fonts in LuaTeX DVI output, so it can't be used here. Therefore SVG conversion is only possible by creating a PDF and then converting that which is IMHO less elegant and might lead to worse SVG files. – Marcel Krüger Jul 05 '20 at 19:28
  • 1
    I would recommend one change: that template will get you a letter- or A4-sized PDF with a page number at the bottom. To produce a SVG of an equation suitable to include on a webpage, you probably want to compile as \documentclass{standalone} and put the equation in display mode, e.g. \[ a^2+b^2=c^2 \]. – Davislor Jul 05 '20 at 19:42
  • @MarcelKrüger I appreciate the thorough answer. I've tried it out but ran into the following errors:

    kpathsea:make_tex: Invalid filename `[HWANG5-Thin.otf]/OT', contains '['

    Package fontspec Error: The font "HWANG5-Thin" cannot be found.

    Currently trying to resolve these, but I after playing around with the code and trying out LuaLaTeX, the code was able to compile but gave the following issue:

    Package fontspec Warning: OpenType feature 'Style=MathScript' (ssty) not (fontspec) available for font....

    Is this indicating that my math font cant be used because it is incomplete?

    – Dotoree Jul 06 '20 at 17:20
  • @Davislor I tried out LuaLaTeX, and it did manage to compile, however it raised the following issues:

    Package fontspec Warning: Font "HWANG5-Thin" does not contain requested Script (fontspec) "Math".

    Package fontspec Warning: OpenType feature 'Style=MathScript' (ssty) not (fontspec) available for font 'HWANG5-Thin' with script (fontspec) 'CustomDefault' and language 'Default'.

    I have left some maths symbols out of the font, but I'm not sure if that is why the output is rendered in just the default font. Is there a bigger issue at hand?

    – Dotoree Jul 06 '20 at 17:33
  • 1
    @Dotoree That means you didn’t define separate scripts for math, or for subscripts/superscripts. If that’s on purpose, the warning is harmless. Most math fonts, however, make subscripts/superscripts slightly wider, and script-scripts slightly wider than that, for greater legibility at those small sizes. Again, see existing OpenType math fonts for examples. – Davislor Jul 06 '20 at 21:51
  • @Dotoree When you say that the output is rendered in just the default font, do you mean that the font isn't used at all or only for some symbols? – Marcel Krüger Jul 07 '20 at 01:52
  • @MarcelKrüger The font isn't used at all, even for letters and numbers. – Dotoree Jul 07 '20 at 03:25
  • @Dotoree Without seeing the actual font and document I can't tell what's going on exactly, but there should be some kind of error message in addition to the warnings if the font can't be loaded. – Marcel Krüger Jul 07 '20 at 03:35
  • @MarcelKrüger

    `\documentclass{standalone} \usepackage{unicode-math}

    \setmathfont{texgyrepagella-math1.otf} \setmainfont{tester1.otf} \setmathfont[range={up}]{tester1.otf} \setmathfont[range={it}]{tester1.otf} \setmathfont[range={bfup}]{tester1.otf} \setmathfont[range={bfit}]{tester1.otf} \setmathfont[range={"002B,"003D, "002D, "2212}]{tester1.otf}

    \begin{document} $-$ \end{document}`

    Got it working after some tinkering! But the minus doesn't render in the new font and other solutions found on other threads didn't work. Do you know any workarounds that work in XeLaTeX?

    – Dotoree Jul 07 '20 at 18:36