8
$\begingroup$

I have read this link but can't quite figure out how to use a different font in MaTeX. Would someone be kind enough to provide a complete example for the following context

Graphics[Inset[MaTeX["\\sin(x)", Magnification -> 4], {3, 1}, {0, 0}]]

Also, the following questions occur to me:

  1. Can I use any font installed on my system (MacOS)?
  2. Even a Hershey font?
  3. Will the necessary metrics be recalculated for the given font?

Could you also include the code that illustrates how to use xelatex?

Many thanks in advance!

$\endgroup$
4
  • 1
    $\begingroup$ This is all covered in the MaTeX documentation, did you check it? $\endgroup$
    – Szabolcs
    Commented Jun 1, 2017 at 21:02
  • 1
    $\begingroup$ @Szabolcs Thank you for your answer below! How does one know that there is MaTeX documentation? I did "??MaTeX", but that yielded nothing. Same thing happened whey I searched for MaTeX in the Documentation Center. I also tried "reference.wolfram.com/MaTeX/guide/MaTeX", as well as typing "MaTeX/guide/MaTeX" in the search/address bar of the documentation window in Mathematica. Perhaps downloading the documentation from Github is best? $\endgroup$
    – Wynne
    Commented Jun 2, 2017 at 13:53
  • 1
    $\begingroup$ Did you search in your web browser or did you use the documentation center in the Help menu? $\endgroup$
    – Szabolcs
    Commented Jun 2, 2017 at 14:54
  • $\begingroup$ "How does one know that there is MaTeX documentation?" It's clearly written on the page you linked ... scroll to "Usage". If you type ?MaTeX, there will be a small blue >> sign after the usage message. Clicking it opens the help. Don't search on wolfram.com online. That's Wolfram's documentation. Click Help -> Documentation Center, and search there. You do have the latest version of the package, 1.7.0, right? $\endgroup$
    – Szabolcs
    Commented Jun 2, 2017 at 15:02

1 Answer 1

13
$\begingroup$

This is all covered in the built-in documentation. Search for MaTeX in Mathematica's documentation centre, or type in the following address: MaTeX/guide/MaTeX. But I will give some examples here anyway:

How to set a given font is really a LaTeX question. You will find many fonts samples with instructions on how to use them at The LaTeX Font Catalogue. Usually, you need to add a package to the preamble. For example, to use Utopia Regular with Fourier math,

MaTeX["\\text{If $x=2$ then $x^2=4$.}", 
 "Preamble" -> {"\\usepackage{fourier}"}, Magnification -> 4]

Mathematica graphics

This is covered under the examples for the "Preamble" option in the MaTeX doc page, as well as in the Typesetting with MaTeX tutorial.

To use XeTeX, you need to configure MaTeX to use the appropriate executable. This is covered in the ConfigureMaTeX documentation page. I will copy the example from that page here:

ConfigureMaTeX["pdfLaTeX" -> "/Library/TeX/texbin/xelatex"]

MaTeX["\\text{Beautiful typesetting}",
 "Preamble" -> {"\\usepackage{fontspec}", "\\setmainfont{Zapfino}"},
 FontSize -> 24
]

Mathematica graphics

Of course, the path to the xelatex executable will be specific to your system.

Remember that ConfigureMaTeX will change the configuration permanently. Restarting Mathematica will not reset it. If you need to change back to plain LaTeX, you must do it manually.

With XeLaTeX you can use any installed system font. This is generally useful for text mode only. To use a system font in math mode, you need a font with special math support, such as Cambria Math. Here's an example:

MaTeX["\\text{Foo $x^2$ bar}",
 "Preamble" -> {"\\usepackage{fontspec,unicode-math}", 
   "\\setmainfont{Cambria}", "\\setmathfont{Cambria Math}"},
 Magnification -> 4
]

Mathematica graphics

I am not experienced with Unicode math fonts. If you have more questions about them, I suggest asking on TeX.SE.

$\endgroup$
2
  • $\begingroup$ Thank you, very helpful! Is there a list of fonts with special math support? $\endgroup$
    – Wynne
    Commented Jun 2, 2017 at 13:55
  • $\begingroup$ @Lem.ma I don't know, you'd have to google ... $\endgroup$
    – Szabolcs
    Commented Jun 2, 2017 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.