0

I would like to include output from a read-eval-print-loop of a programming system.

In my case, this would be the Poly/ML Standard ML compiler, but I guess there is a general solution for this, be it a Python REPL or anything else.

The HOL theorem prover does support this via a macro system but I hope there is a general LaTeX method for this.

Is there a package for this, where I can name the REPL executable and it would pipe the output to a verbatim environment?

Gergely
  • 1,065
  • 1
  • 8
  • 17
  • 2
    I don't know of one, but it shouldn't be hard (with shell escape) if we know the command line, and if the output can be redirected to a file. The LaTeX code would be just calling the command, then typesetting the output verbatim – Phelype Oleinik Jan 18 '22 at 12:41
  • 1
    Note that I selected that question specifically for the answer https://tex.stackexchange.com/a/93720/ that mentions the bashful package. – Marijn Jan 18 '22 at 14:23
  • 1
    There is also the (newer) iexec package, see https://tex.stackexchange.com/a/604433/. – Marijn Jan 18 '22 at 14:25

1 Answers1

0

I followed the first comment and created a Makefile section that invokes Poly/ML:

%.com.out:  %.com
        (echo -n '> '; cat $<) >$<.out; poly <$< >>$<.out

that puts a '> ' prompt, copies the command from the .com command file and then augments it with output of Poly/ML, fed by the command file. The whole thing is written out to the .com.out file.

Then I created a new command \poly to incorporate these .com.out files to the main text in verbatim, using the fancyvrb package's VerbatimInput command:

\usepackage{fancyvrb}

\newcommand\poly[1]{\VerbatimInput{#1.out}}

At the end it is just a simple invocation of it:

\poly{runhello.com}
Gergely
  • 1,065
  • 1
  • 8
  • 17