# Can a Mathematica notebook be programmed to work as a LaTeX editor? [duplicate]

A short example code will show that the answer to this question is yes. The example code (which I give in my answer) is for a simple LaTeX editor that is almost a drop-in replacement for TeXworks. The only(?) editing features it lacks are syntax coloring, delimiter balancing, and being able to sync cursor positions between source and preview.

The value of this simple LaTeX editor is primarily conceptual. It is, in my opinion, the best starting point for thinking about and discussing a much more difficult question: How best to get LaTeX and Mathematica working easily together for the average user?

That this question was not answered at least 15 years ago, is I suppose, some indication of its difficulty. But now we can rephrase it as a more structured question that is much easier to answer: What editing features would we like to add to this simple LaTeX editor?

Of course, our wish-list should include features like generating LaTeX code from Mathematica output, well beyond what a "normal" LaTeX editor can do.

Disclosure statement: I am the author of a commercial package, EnableTeX, that implements most of my own wish-list of features for such an editor. I am using this post to announce the release of my package, to share my ideas, and to ask the following question which is perhaps too broad and open ended to be asked as a main question:

How is Mathematica currently being used to generate LaTeX documents, or parts of documents? To clarify: I'm interested not only in functions and packages that have been written for this purpose, but also the general workflows that have been adopted.

• How is Mathematica currently being used to generate LaTeX documents Mathematica is good for this. I use Mathematica to generate all my large Latex documents. This was described in this post making-a-website-with-mathematica I've been doing this for years now. It works very well for me. Jul 12, 2019 at 14:54
• Possible duplicate of Making a website with Mathematica, besides that, following links in the anser "A license for EnableTeX can be purchased here by credit card or using a PayPal account." ... so this broad and open ended question is actually advertisement for an US\$50 licensed package. I don't like this Jul 12, 2019 at 15:15
• FYI there used to be a Wolfram product called Publicon, which was a fully functional LaTeX editor. Jul 14, 2019 at 3:00
• @Silvia Thanks. I managed to find this paper describing Publicon. Jul 14, 2019 at 20:53

I am the author of a commercial product called EnableTeX, which I've just released. The question in the title is what I asked myself several years ago while struggling to publish research that used a lot of Mathematica computation. That Qn eventually led to here.

To answer the question in the title, I created a new cell style. The new cell style was similar to Text, in that text could be edited within the new cell. However, the new style specified a CellEvaluationFunction for the cell. Let's call it f. This means that when the cell is evaluated, it returns the value f[str], where str is the string contents of the cell.

I knew then that the definitive answer to my question is YES! My reasoning was as follows: If f[str] returns Null then the new cell will not only look like a Text cell, it will also print no Output cell in the notebook (also like a Text cell). Instead of printing output, f[str] could write str to a file, have it processed by pdflatex, and then the resulting PDF file could be displayed by an auto-reloading PDF viewer.

A notebook that contained just one such cell would be equivalent to something like TeXworks, and would already have built-in spell-check, find-and-replace, and a host of keyboard shortcuts. All this from just a single cell style definition and one 3 line function.

Here is a complete working code for the One-Cell-Editor. The style definition needs to be saved in a stylesheet and the definition for the function OneCellEditor (which is called f in the above) needs to be evaluated in the notebook:

   Cell[StyleData["One-Cell-Editor"],
Evaluatable->True,
CellEvaluationFunction->OneCellEditor,

OneCellEditor[str_, TextForm] :=
(WriteString["demo.tex", str];
Close["demo.tex"];
RunProcess[{"pdflatex", "demo.tex"}];)


To get it going, insert a One-Cell-Editor cell into the notebook (it will be at the top of the cell style menu because of the MenuSortingValue that has been used), and open an auto-reloading PDF viewer for demo.pdf. Whenever the cell is evaluated, the LaTeX document it contains will be displayed. Note: Open notebooks have to be re-opened before a changed style file will take effect.

Of course, Mathematica allows for a few improvements to the One-Cell-Editor. A multi-cell version of the editor can offer built-in notebook features such as notebook headings and collapsible sections that surpass those of many LaTeX editors. If one also factors in the potential for interleaved Mathematica calculations, and the possibility of having selected results automatically translated to LaTeX and written to file, then the possibilities become quite awesome.

The ideas that I've found useful to implement and the way that I use Mathematica to generate LaTeX documents are described in the EnableTeX user guide, which can be download here: EnableTeX-UserGuide.pdf.

Licenses for EnableTeX are not free and the code may not be distributed. Nevertheless, licensees have access to the source code, and are allowed to modify their copies of the code if they want to.

• I wouldnt mind this answer if it was just someone sharing their experience and solution to a difficult problem..and providing their solution to the community for free...Not selling it. Not sure S.E. Is supposed to be used as an advertisement platform for a paid product... Jul 12, 2019 at 16:54
• Why would there be a problem with a commercial package, if it solves the problem? Jul 12, 2019 at 19:37
• I don't like this mainly because it's not straightforward presented as the release of a commercial solution. It's not even presented as a good Q&A. I'm not sure what's the policy, I assume it's allowed given that moderators didn't follow up on my flag. But subjectively, it feels like sneaky way to sell what everybody else here share free of charge. Jul 12, 2019 at 22:47
• @rhermans and Andrew: unless policies have changed recently, and I may not be aware as presently I am mostly inactive, I interpret this as being OK however you must announce your affiliation to the product, and excessive self-promotion is against the rules. Please edit your answer to make it clear that you are the author/proprietor of this product, and please do not let its promotion become a major thrust of your participation on this site. Thank you. Jul 13, 2019 at 7:36
• Probably we should move this discussion to Mathematica Meta. I found a guideline on promotion, and based on those criteria, IMO this is more "Tell" than "Show", it's not answering a question from the community, it's a poorly-written Q&A, and doesn't disclose the nature of the post in a straightforwardly. So not cool, but also not blatantly illegal based on general guidelines. I assume that as a community we are also entitled to our own variations around such policy and to define the subtleties of what is desirable. Votes suggest this is controversial Jul 13, 2019 at 8:13