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 stylsheet 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,
MenuSortingValue->900]
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...
...now, several years later, I'm happy to announce that EnableTeX has been released :)
The user guide for EnableTeX is available for 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.