How to publish symbolic matrices in latex format in MATLAB?
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a project in which I have to publush symbolic matrices in latex format.
An example of a matrix is the following:
J1 =
[ 1, 0, a]
[ 1, 0, -a]
[ cos(beta_3s), sin(beta_3s), b*sin(beta_3s)]
If I try to publish it in latex format, I get the same eqiation as above:
\begin{document}
\color{lightgray} \begin{verbatim}
J1 =
[ 1, 0, a]
[ 1, 0, -a]
[ cos(beta_3s), sin(beta_3s), b*sin(beta_3s)]
\end{verbatim} \color{black}
As you can see, the matrix is not publlished in the neat way that latex can actually write the matrix.
Moreover, if I tried solving the problem using a function that I created as follows:
function lat = tex(input)
lat=['$',latex(input),'$'];
end
This outputs the desired code which is: '$\left(\begin{array}{ccc} -\sin\left(\beta _{\mathrm{1s}}\right) & \cos\left(\beta _{\mathrm{1s}}\right) & b\,\sin\left(\beta _{\mathrm{1s}}\right)\\ \sin\left(\beta _{\mathrm{2s}}\right) & -\cos\left(\beta _{\mathrm{2s}}\right) & b\,\sin\left(\beta _{\mathrm{2s}}\right)\\ -\sin\left(\beta _{\mathrm{3c}}\right) & \cos\left(\beta _{\mathrm{3c}}\right) & c\,\sin\left(\beta _{\mathrm{3c}}\right) \end{array}\right)$'
However, if I try to publish the script in latex format using the function above and the disp function, (disp(tex(J1))), I get the following output in the published .tex file:
\begin{document}
\color{lightgray} \begin{verbatim}$\left(\begin{array}{ccc} 1 & 0 & a\\ 1 & 0 & -a\\ \cos\left(\beta _{\mathrm{3s}}\right) & \sin\left(\beta _{\mathrm{3s}}\right) & b\,\sin\left(\beta _{\mathrm{3s}}\right) \end{array}\right)$
\end{verbatim} \color{black}
So as you can see, the code is now published with \begin{verbatim} \end{verbatim} . So, instead of showing the matrix, the latex code will show the code instead.
Is there a way to output the latex code in a way that it will be outside \begin{verbatim} \end{verbatim} and make it display the symbolic matrix?
I am sorry for the long question but I saw some people tried to ask the same question but did not find an answer. So, I tried to detail my problem as much as possible.
Thank you for your time.
0 Commenti
Risposta accettata
Ameer Hamza
il 2 Giu 2020
You may try Live scripts. It renders the symbolic matrices in mathematical notation and allows you to get latex code directly. For example, run this code in Live script
syms a beta_3s b
x = [1 0 a;
1 0 -a;
cos(beta_3s) sin(beta_3s) b*sin(beta_3s)]
right-click on the output and click "copy as Latex". It gives the following latex code
\left(\begin{array}{ccc}
1 & 0 & a\\
1 & 0 & -a\\
\mathrm{cos}\left(\beta_{\textrm{3s}} \right) & \mathrm{sin}\left(\beta_{\textrm{3s}} \right) & b\,\mathrm{sin}\left(\beta_{\textrm{3s}} \right)
\end{array}\right)
which is rendered like this
Più risposte (0)
Vedere anche
Categorie
Scopri di più su LaTeX in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!