Adds Latexify recipes for Unitful units and quantities.
] add UnitfulLatexify
julia> using Unitful, Latexify, UnitfulLatexify;
julia> q = 612.2u"nm";
julia> u = u"kg*m/s^2";
julia> latexify(q)
L"$612.2\;\mathrm{nm}$"
julia> latexify(u; unitformat=:mathrm) # explicit default
L"$\mathrm{kg}\,\mathrm{m}\,\mathrm{s}^{-2}$"
julia> latexify(q; unitformat=:siunitx)
L"\qty{612.2}{\nano\meter}"
julia> latexify(u,unitformat=:siunitx)
L"\unit{\kilo\gram\meter\per\second\tothe{2}}"
One use case is in Pluto notebooks, where my current favourite workflow is to write
Markdown.parse("""
The period is $(@latexrun T = $(2.5u"ms")), so the frequency is $(@latexdefine f = 1/T post=u"kHz").
""")
, which renders as
The period is
$T = 2.5 \mathrm{ms}$ , so the frequency is$f = \frac{1}{T} = 0.4 \mathrm{kHz}$ .
Note that the quantity has to be interpolated (put inside a
dollar-parenthesis), or Latexify will interpret it as a multiplication between
a number and a call to @u_str
.