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 copy_to_clipboard(true) m = [2//3 "e^(-c*t)" 1+3im; :(x/(x+k_1)) "gamma(n)" :(log10(x))] latexify(m)
This package supplies functionality for latexifying objects of the following types:
- Numbers (including rational and complex),
- Missings' Missing type,
- Symbolic expressions from SymEngine.jl,
- DataFrame from DataFrames.jl,
- Any shape of array containing a mix of any of the above types,
- ParameterizedFunctions from DifferentialEquations.jl,
- ReactionNetworks from DifferentialEquations.jl
julia> str = "x/(2*k_1+x^2)" julia> latexify(str)
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||Latexifies 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||latexify the input and surround it with $$ for inline rendering.|
|Align||Latexifies input and surrounds it with an align environment. Useful for systems of equations and such fun stuff.|
|Array||Latexify the elements of an Array or a Dict and output them in a $\LaTeX$ array.|
|Tabular||Latexify 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||Output a Markdown table. This will be rendered nicely by Jupyter, etc.|
|Markdown Text||Output and render any string which can be parsed into Markdown. This is really nothing but a call to |
|Chemical arrow notation||Latexify 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
print() will output text which is formatted for latex.
latexify("x/y") |> print
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([12893.1 1.328e2; "x/y" 7832//2378]; fmt="%.1e")
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.
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.