logo

Using TeX in Plots in Julia 📂Julia

Using TeX in Plots in Julia

Code 1

To use the LaTeXStrings library, prefix strings with L, like so L"...".

@time using Plots
@time using LaTeXStrings

plot(0:0.1:2π, sin.(0:0.1:2π), xlabel = L"x", ylabel = L"y")
title!(L"\mathrm{TeX\,representation:\,} y = \sin x , x \in [0, 2 \pi]")

example.png

Note that the package name is precisely LaTeXStrings and regular text does not work with \text{}; instead, use \mathrm{}. For spaces, use \,.

Environment

  • OS: Windows
  • julia: v1.7.0