My roommate knows Mathematica. He draw 3-d graph for each term of (a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3. He doesn't know LaTeX. I want to write his thesis document in LaTeX. So, If there is a tool that converts Mathematica code into LaTeX, that would be easier for me than write the same things in LaTeX from scratch.
-
2Related: tex.stackexchange.com/questions/84748Henri Menke– Henri Menke2017-11-06 05:00:19 +00:00Commented Nov 6, 2017 at 5:00
-
Why do you want to write his thesis? Mathematica can do quite a bit on its own.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2017-11-06 16:43:28 +00:00Commented Nov 6, 2017 at 16:43
-
@ThorbjørnRavnAndersen I don't know the quality, but he complain that he made a pdf from these image that produce low quality.alhelal– alhelal2017-11-06 17:04:05 +00:00Commented Nov 6, 2017 at 17:04
-
@alhelal Perhaps he should ask that question too? Low quality images in PDF usually just indicate that the target was web and not print. Switching to TeX for that reason is like installing Linux because the printer is not working in Windows.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2017-11-06 17:06:15 +00:00Commented Nov 6, 2017 at 17:06
-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers.samcarter_is_at_topanswers.xyz– samcarter_is_at_topanswers.xyz2018-07-23 17:27:52 +00:00Commented Jul 23, 2018 at 17:27
3 Answers
You can copy-and-paste LaTeX directly from a Mathematica notebook:
It is assumed the content is math-related, so non-math functions are set using \text (requires amsmath).
-
1+1. You may also want to mention the possibility of using either
\textsfor\textttinstead of just\textfor the stringPlot3D. That would make it clearer, visually speaking, what's Mathematica code.Mico– Mico2017-11-06 06:10:59 +00:00Commented Nov 6, 2017 at 6:10
What do you mean by "Mathematica code"? Can you give an example of the desired conversion?
Apart from the convenient copy-paste method described by @Werner, there's TeXForm, which converts a Mathematica expression into math-mode LaTeX.
In[]:= TeXForm[Sin[x]^2]
Out[]//TeXForm=
\sin ^2(x)
If you want to convert a notebook to LaTeX, use File -> Save As... -> LaTeX Document.
In the past, I have been asked by people who did not know LaTeX if it is a good workflow to write your document as a Mathematica notebook, then simply save as LaTeX and compile it to PDF (as a means of getting better typesetting). I do not think this is a good idea. The LaTeX produced by Mathematica often has multiple issues. The LaTeX knowledge needed to correct these problems is already sufficient to write the LaTeX from scratch, so why not just do that?
Furthermore, when writing formulas in LaTeX, we specify what they should look like. When writing formulas in Mathematica, we specify what they mean, but the ultimately it is up to the system to format them in a certain way. This means that LaTeX auto-generated from Mathematica expressions will often benefit from additional manual editing.
To sum up:
Tell your roommate to take an hour to learn the basics of LaTeX. If the desired output is LaTeX, starting with a Mathematica notebook does not usually provide any benefits. I think that those LaTeX features that Mathematica can handle can really be learned in an hour or so (bold, italic, headings, equations).
However, if your goal is to convert an already written Mathematica document to LaTeX, and continue editing in LaTeX only, then go ahead and use Save As ... -> LaTeX Document.
For those who do not have installed Mathematica application but are using the online Mathematica Plotter & Graphics (Mathematica Plotter & Graphics), ther is an online tool which I use to convert Mathematica equations etc. into LaTeX Equation to LaTeX Converter which works without creating account or any payment etc.
Example, with graph sin t + cos (sqrt(3)t):

which gives, after adding the missing \usepackage{pgfplots}:
-
3Welcome to TeX.SX! Thanks for your contribution. I added an example (but fell free to revert). It seems that an account is needed if your want to convert more than one formula (unless you delete the site cookie).jlab– jlab2025-10-11 11:50:58 +00:00Commented Oct 11 at 11:50

