Is there some functionality to spit out LaTeX code for typesetting matrices?

#1

For instance to typeset 3 x 3 random matrix of floats, I would like to call a function (or a macro) to produce the typesetting code. Is there such a thing?

0 Likes

#2

You might want to go through SymPy:

using SymPy
v = Sym.(rand(3,3))
args = ()
SymPy.sympy_meth(:latex, v, args...)

with args detailed here: https://docs.sympy.org/latest/modules/printing.html#sympy.printing.latex.latex

2 Likes

#3

Also check out

3 Likes

#4
julia> using Latexify

julia> A = rand(3,3)
3×3 Array{Float64,2}:
 0.212977  0.297547  0.422277
 0.302519  0.522596  0.180855
 0.288964  0.01098   0.683853

julia> latexify(A)
L"\begin{equation}
\left[
\begin{array}{ccc}
0.212976937434459 & 0.29754727246675006 & 0.42227698240275924 \\
0.30251946700649746 & 0.5225962585963944 & 0.18085503939791114 \\
0.28896355463698153 & 0.010980031174606442 & 0.6838534272801575 \\
\end{array}
\right]
\end{equation}
"
3 Likes

#5

Perfect, works like a charm. Thanks!

0 Likes

#6
julia> using Reduce

julia> rounded(true)
true

julia> A = rand(3,3)
3×3 Array{Float64,2}:
 0.939254  0.688392  0.499559
 0.18629   0.833578  0.503867
 0.172579  0.991595  0.93439 

julia> Algebra.latex(RExpr(A))
"\\begin{displaymath}\nmat\\left(0.939253842625,0.186290380376,0.172578870645\\right)\n\\end{displaymath}\n"
2 Likes