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 Answer
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:
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 specifygnuplot
source in your LaTeX file, and it will automatically run thegnuplot
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, aMakefile
.
-
I just saw another question with an awesome answer which, in retrospect, is probably closer to what you were asking: emacs.stackexchange.com/questions/62286/… Commented Dec 29, 2020 at 17:11