Message Boards Message Boards

Compiling a notebook directly into LaTeX

Posted 7 years ago

Hi everyone,

Recently I've been writing some work up in LaTeX. As I usually work in Mathematica, I found myself going back and forth between Mathematica and my Tex editor as I adjusted figures I was rendering with Mathematica code. I began to wonder if I could set up my notebook to turn itself into LaTeX, cutting out the middleman (me!).

To achieve this I've done two things, firstly I wrote a notebook that could select sections of itself and convert them to plaintext. I do this using various bits of Mathematicas front end interface. Notably the notebook saves and deletes output cells, this means one can write an input "hello " <> "world", and trust that it will be converted to output, without having to view that output, which might be repetitive or contain a lot of superfluous scaffolding. Find this notebook "Notebook to plaintext" is attached.

The second step was augmenting the above notebook to save the generated plaintext as a tex file, and automatically run pdfLatex.exe on the tex file to receive the ultimate output file. By writing Mathematica functions that export Mathematica plots, and return LaTeX that imports said plots, one can write a LaTeX document in Mathematica, the same environment that we specify our graphics. This notebook "Notebook to LaTex" is also attached, but one requires pdfLatex.exe, as is included in a MikTex installation for example. The pdf output of this example is also attached.

I had not previously worked with front end controls. As write time and run time are so close in Mathematica, we have fairly unique capacity to muck about with the structure of the work environment; automatically updating and evaluating cells. I hope this proves interesting.

David

Attachments:
POSTED BY: David Gathercole
3 Replies

Is there some way to use your code, say from a palette, so that one does not have to copy the code into the notebook that you want to convert?

POSTED BY: Murray Eisenberg
POSTED BY: Imre Pazsit
Attachments:
POSTED BY: Imre Pazsit
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract