1

Babel lets you include code blocks of different programming languages inside an Org-mode document, which can be printed and executed. Is there something similar for other modes as well? For example, I would like to include code blocks inside TeX-mode.

1

What you probably want to do is write your document in org mode, and then export it to LaTeX (M-x org-export-dispatch and then l l).

If you're looking for other options: some languages provide their own tools to export literate programs to LaTeX. For example:

  • Racket has Scribble which can generate LaTeX
  • R has Sweave which can generate LaTeX

But those are obviously language-specific. As far as I know, org-mode and org-babel is the most general solution for this sort of thing.

If you really want to write in LaTeX rather than in org-mode, some things you can try:

  • Some LaTeX packages have been created to invoke specific programs from LaTeX. For example, the gnuplottex package allows you to specify gnuplot source in your LaTeX file, and it will automatically run the gnuplot code, generate a graph, and then include the graph in your document.

  • Otherwise, you can create a simple build pipeline (what some web devs could call an "asset pipeline") that runs your code, creates output files (say, txt files), and then in your LaTeX you can \include those output files. You could do this with, say, a Makefile.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.