Latexify.jl is a package which supplies functions for producing $\LaTeX$ formatted strings from Julia objects. The package allows for latexification of a many different kinds of Julia object and it can output several different $\LaTeX$ or Markdown environments.

A small teaser:

using Latexify
m = [2//3 "e^(-c*t)" 1+3im; :(x/(x+k_1)) "gamma(n)" :(log10(x))]
\[\begin{equation} \left[ \begin{array}{ccc} \frac{2}{3} & e^{ - c \cdot t} & 1+3\textit{i} \\ \frac{x}{x + k_{1}} & \Gamma\left( n \right) & \log_{10}\left( x \right) \\ \end{array} \right] \end{equation}\]

Supported input

This package supplies functionality for latexifying objects of the following types:


julia> str = "x/(2*k_1+x^2)"
julia> latexify(str)
\[\frac{x}{2 \cdot k_{1} + x^{2}}\]

Supported output

Latexify has support for generating a range of different $\LaTeX$ environments. The main function of the package, latexify(), automatically picks a suitable output environment based on the type(s) of the input. However, you can override this by passing the keyword argument env =. The following environments are available:

no env:rawLatexifies an object and returns a $\LaTeX$ formatted string. If the input is an array it will be recursed and all its elements latexified. This function does not surround the resulting string in any $\LaTeX$ environments.
Inline:inlinelatexify the input and surround it with $$ for inline rendering.
Align:alignLatexifies input and surrounds it with an align environment. Useful for systems of equations and such fun stuff.
Array:arrayLatexify the elements of an Array or a Dict and output them in a $\LaTeX$ array.
Tabular:table or :tabularLatexify the elements of an array and output a tabular environment. Note that tabular is not supported by MathJax and will therefore not be rendered in Jupyter, etc.
Markdown Table:mdtableOutput a Markdown table. This will be rendered nicely by Jupyter, etc.
Markdown Text:mdtextOutput and render any string which can be parsed into Markdown. This is really nothing but a call to Base.Markdown.parse(), but it does the trick. Useful for rendering bullet lists and such things.
Chemical arrow notation:chem, :chemical, :arrow or :arrowsLatexify an AbstractReactionNetwork to $\LaTeX$ formatted chemical arrow notation using mhchem.

Modifying the output

Some of the different outputs can be modified using keyword arguments. You can for example transpose an array with transpose=true or specify a header of a table or mdtable with header=[]. For more options, see the List of possible arguments.

Printing vs displaying

latexify() returns a LaTeXString. Using display() on such a string will try to render it.

latexify("x/y") |> display

Using print() will output text which is formatted for latex.

latexify("x/y") |> print

Number formatting

You can control the formatting of numbers by passing the keyword argument fmt. This will be passed on to Printf, have a read there for more information.


latexify(12345.678; fmt="%.1e")
latexify([12893.1 1.328e2; "x/y" 7832//2378]; fmt="%.1e")
\[\begin{equation} \left[ \begin{array}{cc} 1.3e+04 & 1.3e+02 \\ \frac{x}{y} & \frac{3916}{1189} \\ \end{array} \right] \end{equation}\]

Automatic copying to clipboard

The strings that you would see when using print on any of the above functions can be automatically copied to the clipboard if you so specify. Since I do not wish to mess with your clipboard without you knowing it, this feature must be activated by you.

To do so, run


To once again disable the feature, pass false to the same function.

The copying to the clipboard will now occur at every call to a Latexify.jl function, regardless of how you chose to display the output.

Automatic displaying of result

You can toggle whether the result should be automatically displayed. Instead of

latexify("x/y") |> display
## or
display( latexify("x/y") )

one can toggle automatic display by:


after which all calls to latexify will automatically be displayed. This can be rather convenient, but it can also cause a lot of unwanted printouts if you are using latexify in any form of loop. You can turn off this behaviour again by passing false to the same function.

Legacy support

Latexify.jl has stopped supporting Julia versions older than 0.7. This does not mean that you cannot use Latexify with earlier versions, just that these will not get new features. Latexify.jl's release v0.4.1 was the last which supported Julia 0.6. Choose that release in the dropdown menu if you want to see that documentation.