How to use $\LaTeX$ in Mathematica text



I would like to formulate a question in a notebook for my students using $\LaTeX$ (or $MathML$) to typeset functions and matrices. I specifically want a language other than Mathematica as students will have to replicate the output using Mathematica.

Is there a way of using $\LaTeX$ in text?

Is it also possible to generate $\LaTeX$ output when setting up a notebook in a text editor?

I have found solutions for using $\LaTeX$ in Mathematica commands but this does not work in text.


Posted 2017-07-10T14:23:37.797

Reputation: 131

Question was closed 2017-07-16T01:32:31.067


Take a look at MaTeX from our friend Szabolcs. It may help.

– MarcoB – 2017-07-10T14:34:34.740

2Load MaTeX, then (for instance): << MaTeX thenMaTeX@HoldForm[Sum[1/k^3, {k, 1, [Infinity]}]]` – David G. Stork – 2017-07-10T15:22:56.690

1If you just want to state a problem mathematically in a Text cell that students will answer by using entering expressions in a Input cell, Mma notebooks already offer extensive math formatting capabilities in text cells. (Or, did you want something else?) – Alan – 2017-07-10T15:36:10.263


Are you looking for LaTeX or are you looking for mathematical typesetting? If the latter, check these:

– Szabolcs – 2017-07-10T16:09:19.467

What do you mean by "Mathematica text" and what do you mean by setting up a notebook in a text editor? Do your students have Mathematica or do you want them to not use Mathematica? – Jens – 2017-07-10T17:17:21.563

I believe what the questioner wants is a way to display a matrix in a Mathematica text cell which does not involve using the Wolfram language (at least not directly) to accomplish the formatting. Otherwise, their students could just copy & paste the objects from the text cells into the "input" cells. (If that's the case, then I'd probably just use a stand-alone program like LaTeXiT and include the "formatted" mathematics as images.) – Michael Seifert – 2017-07-10T17:59:53.443

An excellent question about a feature that, AFAIK, is currently missing from the FrontEnd. It would be desirable not just for the purpose indicated by the poster, but also for finer (and often easier!) mathematical typesetting within a notebook than what is currently available. – murray – 2017-07-10T18:51:44.063

Sorry for the unclear question. Michael has hit it right ion the nose. I want to create a notebook using another program where I can put mathematical expression in a text cell without using the Wolfram Language.

My goal is to generate unique questions for students based on their student ID number. For example, I want to ask the question "Invert matix A = [...]" and have the matrix displayed in the text cell without having to use Mathematica.

Basically I want the functionality of generating questions a can be done in Maple T.A. but then in Mathematica – user49947 – 2017-07-11T07:38:47.637

What is the relevance of student ID numbers? Do you want some processing in Mathematica based on those? You still haven't clarified the workflow. If by "text cell" you mean a Mathematica text cell, then how can it be displayed without Mathematica? – Jens – 2017-07-12T06:00:38.410

Student numbers are usde to provide each student with a unique set of problems to prevent cheating.As for the workflow. I want to create a Mathematica notebook using a text editor, not Mathematica where I create a problem where, for example, a matrix is given. The matrix must not be in the wolfram language but in LaTeX. The problem text should be interpreted by Mathematica and displayed in the notebook when students open it. As I don't want student to have to run the notebook, I want the problems posed in a Mathematica text cell. Bu some here say the Mathematica front end doesn't support this. – user49947 – 2017-07-12T07:34:40.740



Question not clear. But to insert Latex Matrix (or any other latex output, such as equations etc..) in textcell using the notebook, here is an example. If OP does not want to use the notebook at all, then this is not possible and will delete this.

Load Matex to render the Latex. Start text cell. Insert the latex in the textcell from the rendered output. Here is an example

enter image description here


matrix = Table[i + j, {i, 1, 3}, {j, 1, 4}];
matrixAsLatex = MaTeX@TeXForm[matrix]

However, I would not do it this way if I were you. I use Mathematica all the time to generate Latex, but I output direct Latex to a file which later compile using lulatex directly. I use this method to generate hundreds of PDF files and reports all from Mathematica. (I do not use Export Latex at all either). But to do this, you need to know little Latex and make heavy use of TeXFrom as well when needed. Will try to post an example of how this method works if needed, but you asked for using textcell.

An option between using texcell and full method I use is to render the whole thing as String in the notebook. Here is an exammple

equation = y'[x]==x;

ANd now type

string="\\text{My Matrix in Latex is} "<>ToString@TeXForm[matrix]<>
       " \\text{which looks nice and my equation is } \\fbox{"
       <>ToString@TeXForm[equation]<>"}\\text{ which Mathematica can 
       solve giving the answer}"<>ToString@TeXForm@sol;


Which gives

Mathematica graphics

Or you can use Row instead, as in

string=Row[{"My Matrix in Latex is ",
           "which looks nice and my equation is ",
           " which Mathematica can solve giving the answer "

Mathematica graphics

The method I use, does not do the above, but sends all output to file. So it is basically as if one is writing plain Latex, but sending output to file, and using Mathematica to do the computation and convert results to Latex as needed.


Posted 2017-07-10T14:23:37.797

Reputation: 92 661

super-cool demo. – user1066 – 2017-07-10T20:27:00.930

Do you think this is a duplicate of How to use LaTeX for typesetting labels and titles in Mathematica? I don't want to be too hasty because I don't understand the question, but it looks very similar to me.

– Jens – 2017-07-10T22:10:57.850

1@Jens I really do not know. OP asked for Latex in textcell (using text editor?) There are number of Other Latex related questions on this site as well. But if you think it is duplicate, feel free to close it. I still do not understand fully what the OP is asking for actually :) – Nasser – 2017-07-10T22:20:50.287

Thank you for all the answers. I don't feel this is a duplicate as I want to typeset math in a text cell, not a command. I also want to generate the text outside Mathematica. I hope this and my comment above clarifies my problem. – user49947 – 2017-07-11T07:40:43.547

1@user49947 I am sorry, I still have no idea what you want to do. TextCell is by definition a construct inside a notebook. It works only in a notebook. I did not use Maple TA, so I do not know how it works. As far as I know, only Mathematica can author notebooks. I do not think there is software which can create Mathematica notebooks that will run inside Mathematica which is not generated by Mathematica itself. I still do not know why you do not want to use Mathematica to generate the Latex. – Nasser – 2017-07-12T01:28:33.163

I'm looking to generate notebooks outside of Mathematica to provide random problems for students such as "generate matrix A=[..]". I explicitly don't want to use the wolfram language as this is what I will be testing them on; if Mathematica generates Latex, they can copy and paste the expression into a command. I want to be able to control the content to prevent students copying answers from other students. However, other comments have lead me to realize that the Mathematica front end simply cannot do what I want. Thank you all for your help! – user49947 – 2017-07-12T20:24:56.820

if Mathematica generates Latex, they can copy and paste the expression into a command sorry, but I do not follow this. How will a student copy an equation from a PDF file generated by pdflatex or lualatex and paste it into Mathematica and have Mathematica understand it and run it? I am completely confused by what you want to do :) But I hope you find the right software to do what you want. – Nasser – 2017-07-13T18:19:14.773