# LaTeX typesetting in Mathematica

GROUPS:
 Szabolcs Horvát 21 Votes Hello everyone,I wrote a package that makes it easy to insert LaTeX-typeset formulae in Mathematica notebooks, in particular in Mathematica graphics. I use this to create figures with high quality typesetting that fit well with the visual style of LaTeX documents.Here's the package description and here's MaTeX.Features of the package: get LaTeX-typeset snippets as Mathematica Graphics expressions (convenient for a Mathematica-centric workflow) the baseline is preserved so these snippets can be precisely aligned with each other or with Mathematica text control over font size, magnification and display or inline styles integrated documentation (open the documentation centre and search for "MaTeX") Let me know what you think and whether you find it useful.A quick demo: Attachments:
Answer
3 years ago
12 Replies
 Szabolcs, it looks great. Thanks for sharing!
Answer
3 years ago
 Marco Thiel 2 Votes Works like a charm. It's great for presentations at conferences and for teaching. Fantastic work!Thanks a lot,Marco
Answer
3 years ago
 Gianluca Gorni 2 Votes Great work Szabolcs! From your documentation I learnt about the option BaseStyle -> {FontFamily -> "Latin Modern Roman"} that you can give to plots. I had no idea that you could do that. It works beautifully without the MaTeX package, at least in the simple cases that I tried, and it is as fast as the default. It will be noticeably non-TeX-like for greek letters, and maybe in other cases. Your example typesets almost the same this way: Plot[Evaluate@{Sin[x], Normal[Sin[x] + O[x]^6]}, {x, -Pi, Pi}, Frame -> True, BaseStyle -> {FontFamily -> "Latin Modern Roman"}, FrameLabel -> {"\!$$\*FormBox[\(x$$, TraditionalForm]\)", "sine of \!$$\*FormBox[\(x$$, TraditionalForm]\)"}, PlotLegends -> {Style[Sin[x], FontFamily -> "Latin Modern Roman"], Style[Normal[Sin[x] + O[x]^6], FontFamily -> "Latin Modern Roman"]}] Unfortunately, BaseStyle does not extend its influence into PlotLegends. I would regard this as a bug.
Answer
3 years ago
 Szabolcs Horvát 2 Votes Hi Gianluca,You are right that in this case the output is almost identical, and Mathematica's math typesetting is pretty good, even if it lags behind that of LaTeX. LaTeX is of course the very best, and Mathematica is also very good compared to similar alternatives. A while ago I would not have written this package, it would have seemed like wasted time since Mathematica's typsetting should be at least good enough for most purposes ... However, the reality is that (1) I do not always set the standards myself, unfortunately, so in the past I was forced to add LaTeX-made labels in drawing programs sometimes ... (2) it's not always easy to type formulae in Mathematica; right now I type them in a text cell after pressing Ctrl-9 to start a math subcell, then copy them; otherwise the spacing around operators is not always correct (3) math symbols won't use the Latin Modern font, try e.g. "\!$$\*FormBox[\(\(\[ScriptCapitalN](x)$$~$$\[ScriptCapitalG](x)$$\), TraditionalForm]\)" (I haven't tried Latin Modern Math though!) (4) Mathematica occasionally has bugs, e.g. this in v10.0.2. Typesetting quality also tends to be affected when exporting to PDF.My point is simply that the package grew out of a real practical need. I wanted to say this because a couple of years ago I may have considered this a useless exercise that won't add much to what Mathematica can already do.I hope others will find it useful too!I should also mention the MathPSFrag package which achieves similar results using PSFrag. I only discovered this after writing MaTeX ... yes, I should have googled first, not afterwards :-) I haven't tried using this package yet, so I can't comment on which is the most convenient approach.
Answer
3 years ago
 Gianluca Gorni 2 Votes Yes, your concerns about getting precise TeX-typeset labels in Mathematica pictures are mine too. Some 10 years ago together with a colleague of mine we developed a package that is very similar to your MaTeX: https://www.yumpu.com/it/document/view/5324914/arstexnica-numero-4-ottobre-2007-guit-scuola-superiore-sant-/80It used pstoedit to convert pdf into Mathematica graphics. Some years later pstoedit stopped working on my computer (it was compiled for PowerPC only), and I pretty much stopped using the package seriously. Mathematica can import pdf, but it gets all kernings wrong when the pdf was made by pdfTeX. From reading your documentation on MaTeX I gather that Ghostscript can now do what I needed pstoedit for. I am faced with the choice between switching to MaTeX and learing the new syntax, or to see if I can retouch my old familiar package to use Ghostscript. Thank you! A very interesting exchange.
Answer
3 years ago
 Just a quick update to note that if people are getting AbsoluteFileName::fdnfnd messages with Mathematica 10.3 on Windows, This is because you have directories in the system's [PATH environment variable](https://en.wikipedia.org/wiki/PATH_(variable)) that do not exist. This may happen when installing, then later uninstalling software that modifies the path. These directories can safely be removed from the path. The message is harmless and shouldn't influence MaTeX. The latest version of MaTeX avoids printing these messages.
Answer
2 years ago
 Murray Eisenberg 2 Votes Very nice, useful package!In your code for the functions, you had something Mathematica-ly mysterious to me: Sin[x] + O[x]^6 I know about "big-oh" but was surprised by that use — until I found under "Scope" on docs page ref/O a similar example with the explanation, "Like approximate numbers, approximate functions are contagious". Neat!
Answer
2 years ago
 Version 1.5.0 is now released. Get it from the GitHub releases page, as usual.This release has much improved error reporting. If you find any problems with it, please let me know.Reminder: the package is documented in this blog post, which usually gets updated with every new release.
Answer
1 year ago
 Szabolcs Horvát 1 Vote Version 1.6.2 is now released. Get it from the GitHub releases page.The 1.6 series can compile a list of expressions using a single call to LaTeX, which is much faster than compiling them separately.In 1.6.2 now the documentation integrates with Mathematica. Search for "matex" in the documentation center.This release is distributed as a .paclet file. This means that the installation instructions have changed. Please see the README on GitHub. This is my first experiment with this distribution format, so any feedback is appreciated.
Answer
1 year ago
 Szabolcs Horvát 1 Vote Version 1.7.1 is now released. This is the recommended version for Mathematica 11.1 and later (although it is compatible with 10.0 and later).User-facing changes since the 1.6 series: Better documentation compatibility with recent versions of Mathematica Expanded documentation Improved compatibility with certain Linux systems Please upgrade, and don't forget that the documentation can be accessed by going to Help → Wolfram Documentation and entering MaTeX.
Answer
7 months ago
 How does one uninstall an earlier version of MaTeX (or, for that matter, any add-on distributed in the form of a packet)?I found that, along with the undocumented function PacletInstall, there's a PacletUninstall function. But exactly what does one uninstall?The reason it's not obvious is that, while I do find MaTeX-1.6.2 in ~/Library/Mathematica/Paclets/Repository, I wonder if there's some corresponding file, or entries in a file, in ~/Library/Mathematica/Paclets/Configuration, or even in ~/Library/Mathematica/Paclets/Temporary that needs to be changed somehow. (Or does PacletUninstall do that automatically when you use it to uninstall the file from ~/Library/Mathematica/Paclets/Repository?
Answer
6 months ago
 Let me give a fully general answer, in case others need this information too.If you have MaTeX 1.6.1 or earlier (which does not use paclets), it is located in FileNameJoin[{\$UserBaseDirectory, "Applications"}]. Navigate to that directory and delete the MaTeX directory within.If you have MaTeX 1.6.2 or later, it uses the paclet system. It is not strictly necessary to uninstall earlier versions when upgrading. <
Answer
6 months ago