Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put result of code right below the code in resulting PDF. Haskell

Is there any way to execute code in a .lhs file and put the result right below the code itself in the resulting PDF?

For example:

[1,2,3] ++ [4,5,6]
[1,2,3,4,5,6]
like image 407
Jcao02 Avatar asked May 13 '13 02:05

Jcao02


1 Answers

If you are using LaTeX, you can use lhs2TeX. Here is a simple example document:

\documentclass{article}

%include polycode.fmt
%options ghci

\begin{document}

< [1,2,3] ++ [4,5,6]

This evaluates to \eval{[1,2,3] ++ [4,5,6]}.

> x = [1 .. 6]

And this evaluates to \eval{x}, too.

\end{document}

This will run GHCi with the source file as input in the background. You can thus evaluate expressions using \eval in the context of the current (literate Haskell) module, and their results will be spliced into the resulting .tex sources.

like image 182
kosmikus Avatar answered Oct 22 '22 13:10

kosmikus