1

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

\begin{ocamltoplevel}
  let x = 2 + 3*4}
\end{ocamltoplevel}

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.

1
1

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

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{minted}{fsharp}
let x = 2 + 3*4
\end{minted}

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

\end{document}
1

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.