Skip to content

Instantly share code, notes, and snippets.

@TysonRayJones
Last active January 1, 2024 23:15
Show Gist options
  • Save TysonRayJones/42d4fb572e97e53309ca9d8b04240622 to your computer and use it in GitHub Desktop.
Save TysonRayJones/42d4fb572e97e53309ca9d8b04240622 to your computer and use it in GitHub Desktop.
Rendering LaTeX-style plots in Mathematica

Here's how to render plots in Mathematica which fit nicely into LaTeX documents.

First, download the LaTeX fonts onto your machine. This page describes how to do so for MaCOS. This is not needed on Ubuntu.

To use the LaTeX font for both axis-numbers and labels, add this option to your plot on Mac OS:

LabelStyle -> {FontFamily -> "CMU Serif", FontSize -> 12}

and this on Ubuntu:

LabelStyle -> {FontFamily -> "Latin Modern Roman", FontSize -> 12}

Plots can be made more aesthetic by giving them complete, black borders with ticks only on the bottom and left axis, via

Frame->True, FrameStyle->Black, FrameTicks->{{Automatic,None},{Automatic,None}}

in combination with FrameLabel to label the axis.

For example,

Plot[
 x^2, {x, 0, 1}, 
 LabelStyle -> {FontFamily -> "CMU Serif", FontSize -> 12},
 FrameLabel -> {"Variable", "Quadratic"},
 Frame -> True, FrameStyle -> Black, 
 FrameTicks -> {{Automatic, None}, {Automatic, None}}
 ]

yields the following plot:

example

Even text in circuit drawings rendered with QuESTlink's DrawCircuit[] function can be changed to the LaTeX font, using:

DrawCircuit[u, BaseStyle -> {FontFamily -> "CMU Serif"}]

Replace "CMU Serif" with "Latin Modern Roman" on Ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment