### LaTeX Output from MATLAB Symbolic Expressions

I’ve recently been doing a lot of work with the symbolic toolbox - some of the matrices I produce are large, and I need to get the results into LaTeX. I’d previously done this manually or with a quick shell script - but it turns out that MATLAB already has the command latex, which takes a symbolic expression and generates LaTeX output. Even better, if you name your symbolic variables with underscores, the command will generate proper subscripts! For example:

>> syms q_1 q_2 q_3 real
>> q = [q_1; q_2; q_3]
q =
q_1
q_2
q_3
>> latex(q)
ans =
\left(\begin{array}{c} q_{1}\\ q_{2}\\ q_{3} \end{array}\right)


Very handy!