2
$\begingroup$

I've checked this answer. While it works in Mathematica, the $\LaTeX$ output is weird.

X[x_, y_, z_] := Piecewise[{{3/(4*Pi), Sqrt[x^2 + y^2 + z^2] <= 1}}, 0]
Row[{HoldForm[X[x, y, z]], X[x, y, z]}, "\[LongEqual]"] // TraditionalForm // TeXForm

The $\LaTeX$ output is:

X(x,y,z)=
\begin{array}{cc}
 \{ & 
\begin{array}{cc}
 \frac{3}{4 \pi } & \sqrt{x^2+y^2+z^2}\leq 1 \\
 0 & \text{True} \\
\end{array}
 \\
\end{array}

which renders as:

enter image description here

How could I get something like:

enter image description here

?

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Dec 22, 2021 at 22:42

1 Answer 1

1
$\begingroup$

You can do

toX[s_]:=ToString@TeXForm[s]
X[x_,y_,z_]:=Piecewise[{{3/(4*Pi),Sqrt[x^2+y^2+z^2]<=1}},0]
toX[HoldForm@X[x,y,z]]<>"="<>toX[X[x,y,z]]

Which gives

X(x,y,z)=\begin{cases}
 \frac{3}{4 \pi } & \sqrt{x^2+y^2+z^2}\leq 1 \\
 0 & \text{True}
\end{cases}

COPY the above from the notebook using plain text to your Latex editor outside of Mathematica:

\documentclass[12pt]{article} 
\usepackage{amsmath}
\begin{document}   
\[
X(x,y,z)=\begin{cases}
 \frac{3}{4 \pi } & \sqrt{x^2+y^2+z^2}\leq 1 \\
 0 & \text{True}
\end{cases}
\]
\end{document}

Compiled using TeXLive gives

enter image description here


Or if you have MaTeX installed in Mathematica, you can compile the output without leaving the comfort of the notebook:

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.