I would like to be able to write an OCaml expression inside a LaTeX document, and have it loaded in the OCaml toplevel system, which would compile it and evaluate it. Then both the expression and its result would be typeset with syntax highlighting.

It could be some environment like

  let x = 2 + 3*4}

How can I accomplish this?

That is the same idea provided by the pyconsole environment from the PythonTeX package. PythonTeX supports addition of more languages. Maybe someone could add OCaml to the list.


enter image description here

I don't have OCaml these days but I have Fsharp which isn't totally different...

I'm using minted which uses pymentize to do the syntax highlighting, pygments has an fsharp lexer, but not a specific lexer for fsharp output although parsing it as input as done here makes a reasonable attempt at sensible colouring.

the input is directly handed to minted, the output is written to a temporary file and then input to minted. minted (and the extra file writing done here) requires pdflatex --shell-escape




let x = 2 + 3*4

\immediate\write18{echo "let x = 2 + 3*4" | fsi> \jobname.tmp}


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.