Can LaTeXStrings display arrays and DataFrames with LaTeX characters?

I’ve recently discovered the package LaTeXStrings, and am very impressed with it. I was wondering if this package makes it possible to display LaTeX strings within arrays and DataFrames. For example, suppose I have a DataFrame containing a column of strings such as “\alpha_{BC}^{n}”, “\beta_{DF}^{m}”, “\gamma_{G}^{k}”. Is there a way to make these strings display in LaTeX format when the DataFrame is printed?

I was trying to get this to work for arrays, but couldn’t figure it out. I tried

vars = ["\\alpha_{BC}^{n}", "\\beta_{DF}^{m}", "\\gamma_{G}^{k}"]
tex_vars = ["L%$v" for v in vars]
println(tex_vars)

which produced

LaTeXString[L"$\alpha_{BC}^{n}$", L"$\beta_{DF}^{m}$", L"$\gamma_{G}^{k}$"]

rather than actually rending LaTeX characters, as I had hoped. Is it possible to make this work? If so, can this also work for a DataFrame for which some (but not all) entries are strings of LaTeX code?

Julia itself also has tab completion giving unicode characters.
This will print nicely in the following example, but unicode doesn’t currently cover all subscripts (e.g. subscript capitals).

DataFrame(s=["αⁿ", "βⁿ", "γᵏ"])

You shouldn’t be — LaTeXStrings actually does hardly anything. All of the LaTeX rendering is done by your display environment (e.g. Jupyter); LaTeXStrings mainly just makes equations easier to type without escaping backslashes. (I wrote LaTeXStrings.)

You’d need to add a show method that outputs the DataFrame to a type like text/markdown that Jupyter (or whatever environment you are using) can render with embedded LaTeX equations.

2 Likes