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.
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
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
gnuplottexpackage allows you to specify
gnuplotsource in your LaTeX file, and it will automatically run the
gnuplotcode, 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,
txtfiles), and then in your LaTeX you can
\includethose output files. You could do this with, say, a