Skip to main content

Inset expressions

Unlike Mathematica, we interpret all expressions passed to Text, PlotLabel, etc., normally. Therefore, this approach can conflict with Mathematica's method of displaying equations or Wolfram Language (WL) expressions in labels. For example:

Plot[x, {x, 0, 1}, PlotLabel -> x]
Plot[x, {x, 0, 1}, PlotLabel -> "x"]

However, we provide other tools to achieve the same goals.

Plain Superscript/Subscript and Greek Symbols

There is built-in support for basic TeX-like formatting (though somewhat limited) in all Text or Text-like primitives, including PlotLabel, AxesLabel, etc.

Plot[x, {x, 0, 1}, AxesLabel -> {"cm^{-1}", "\\alpha"}]

Some special characters in the Wolfram Language, compatible with the Unicode symbol table, can be entered directly:

Render WL Expressions

Using EditorView inside Inset, you can place any valid WL expression in StandardForm:

Plot[x, {x, 0, 10}, Epilog -> {
Inset[
EditorView["(*FB[*)((1)(*,*)/(*,*)(2))(*]FB*)"],
{3, 5}
]
}]

These symbols in the string are just copied text from a standard input or output Wolfram cell (see Introduction). You can also render expressions in-place:

Plot[Sin[x]/x, {x, 0, 10}, Epilog -> {
Inset[
EditorView @ ToString[Sin[x]/x, StandardForm],
{3, 0.5}
]
}]

Render LaTeX

Option 1

Using CellView, you can insert an entire output cell into an Inset, with its content provided as a string. By default, the "markdown" cell type supports LaTeX:

Plot[Sin[x]/x, {x, 0, 10}, Epilog -> {
Inset[
CellView["$\\hat{T} = i \\hbar \\frac{\\partial}{\\partial t}$", "Display" -> "markdown"],
{3, 0.5}
]
}]

Option 2

Using the MaTeX package, you can directly render LaTeX equations into Graphics primitives. Install it from the official repository or use a resource function available online:

ResourceFunction["MaTeXInstall"][]
warning

This package requires LaTeX and Ghostscript to be installed.

<<MaTeX`

Plot[Sin[x]/x, {x, 0, 10}, Epilog -> {
Inset[
MaTeX["\\sum_{k=1}^{\\infty} \\frac{1}{k}", FontSize -> 20],
{3.5, 0.5}
]
}]

If you place it directly on the same canvas by exploding it into primitives using // First, you may encounter issues with the aspect ratio, as it will be dictated by your plot.