|
From: Foad S. F. <f.s...@gm...> - 2024-05-03 19:36:21
|
Thanks folks for the response,
I just tried the command
```maxima
tex(sigma = matrix([sigma[xx], sigma[xy]], [sigma[yy], sigma[yx]]))
```
in the maxima REPL and I it got stuck for some reason! I ran the same
command in WxMaxima and I got
```latex
$$\sigma=\ifx\endpmatrix\undefined\pmatrix{\else\begin{pmatrix}\fi
\sigma_{{\it xx}}&\sigma_{{\it xy}}\cr \sigma_{{\it yy}}&\sigma_{ {\it
yx}}\cr \ifx\endpmatrix\undefined}\else\end{pmatrix}\fi $$
```
which is syntactically wrong. Then I tried Robert's suggestion:
```maxima
texput(sigma_xx, "\\sigma_xx");
texput(sigma_xy, "\\sigma_xy");
texput(sigma_yy, "\\sigma_yy");
texput(sigma_yx, "\\sigma_yx");
tex(sigma = matrix([sigma_xx, sigma_xy], [sigma_yy, sigma_yx]));
```
and I got
```latex
$$\sigma=\ifx\endpmatrix\undefined\pmatrix{\else\begin{pmatrix}\fi
\sigma_xx&\sigma_xy\cr \sigma_yy&\sigma_yx\cr
\ifx\endpmatrix\undefined}\else\end{pmatrix}\fi $$
```
which is also wrong. I tried the command
```maxima
sigma = matrix([sigma[xx], sigma[xy]], [sigma[yy], sigma[yx]])
```
inside the WxMaxima and used the LaTeX export, and I got
```latex
\[sigma\operatorname{=}\begin{pmatrix}{{sigma}_{\ensuremath{\mathrm{xx}}}}
& {{sigma}_{\ensuremath{\mathrm{xy}}}}\\
{{sigma}_{\ensuremath{\mathrm{yy}}}} &
{{sigma}_{\ensuremath{\mathrm{yx}}}}\end{pmatrix}\]
```
which, despite being a bit bloated, is a valid LaTeX equation. I would
appreciate it if you could help me know what is going on here! 🤔
On Fri, May 3, 2024 at 7:13 PM Robert Dodier <rob...@gm...>
wrote:
> On Fri, May 3, 2024 at 2:35 AM Foad Sojoodi Farimani
> <f.s...@gm...> wrote:
>
> > Could anyone provide guidance on how to properly format Greek letters in
> the .mac/.mc files for correct LaTeX rendering, or point me towards a
> command in Maxima that outputs LaTeX code directly?
>
> Foad, I use Maxima a lot to generate TeX documents. ?? tex at the
> Maxima console input prompt will find several relevant functions.
>
> As you have found, sigma_x is not output as expected (with x being a
> subscript) by the tex function. One solution is to write sigma[x],
> however, that implies replacing every existing use of sigma_x in your
> program. That might or might not be what you want; an alternative is
> to say texput(sigma_x, "\\sigma_x") so that just 'sigma_x' is output.
>
> I often write stuff like this. Let's say this is foo.mac. You can see
> a couple of things there: double backslash to make one backslash in a
> string, end of line in a string is OK, with_stdout captures print and
> tex output (also printf which is not shown in this example).
>
> with_stdout ("mydocument.tex",
> print ("\\documentclass{article}
> \\begin{document}
> Here's my first equation.
> "),
> tex (F = m*a^2),
> print ("Another hoary old chestnut.
> "),
> tex (F = G*m[1]*m[2]/norm(r[2] - r[1])^2),
> print ("Well, that's all for today.
> \\end{document}
> "));
>
> After maxima -b foo.mac, I see that Maxima rearranges the order of
> terms from what I wrote, and tex doesn't seem to know about norm. I'll
> say simp: false to inhibit term reordering (and all other identities),
> and texput to assign a suitable output for norm.
>
> texput (norm, ["\\|", "\\|"], matchfix);
>
> simp: false $
>
> with_stdout ("mydocument.tex",
> print ("\\documentclass{article}
> \\begin{document}
> Here's my first equation.
> "),
> tex (F = m*a^2),
> print ("Another hoary old chestnut.
> "),
> tex (F = G*m[1]*m[2]/norm(r[2] - r[1])^2),
> print ("Well, that's all for today.
> \\end{document}
> "));
>
> Term reordering is a vexing problem for TeX output -- simp: false is a
> heavy-handed solution.
>
> Hope this helps in some way,
>
> Robert
>
|