The lhs2TeX preprocessor supports evaluation of Haskell expressions through GHCi. Here is a minimal example:
\documentclass{article} %include polycode.fmt %options ghci \begin{document} Running > fmap (+1) [1..10] yields \eval{fmap (+1) [1..10]}. \end{document}
This will lead to output of the output that contains the list [2,3,4,5,6,7,8,9,10,11] in the place where the \eval command is in the input line.
You can refer to definitions from the current file. Ie, the \eval function works by loading the current file into ghci and then evaluating the expression in this context.
There is also \perform , which does the same as \eval , but the result will not be considered as part of the Haskell code, but rather as part of the LaTeX code. This way you can write Haskell functions that generate parts of your output.
As the saying goes, there are many things that could be improved in this function in lhs2TeX, and the implementation is pretty gown.
EDIT: To conclude from the comments, the goal is to include images created by the Chart library. Here is a concept document that shows how to achieve this:
\documentclass{article} \usepackage{graphicx} %include polycode.fmt %options ghci %if style == newcode (Stuff here will not be typeset by LaTeX, but seen by Haskell.) > import Data.Accessor > import Graphics.Rendering.Chart > > renderAndInclude :: Renderable a -> FilePath -> IO () > renderAndInclude r filename = do > renderableToPDFFile r 200 200 filename > putStrLn $ "\\includegraphics{" ++ filename ++ "}" %endif %format ^= = "\mathbin{{}^\wedge\!\!=}" \begin{document} The image description > image :: Renderable () > image = toRenderable > $ layout1_title ^= "Test" > $ layout1_plots ^= [ Left (toPlot plot) ] > $ defaultLayout1 > where > plot = plot_lines_values ^= [[ (x, sin x) | x <- [0, 0.01 .. 10 :: Double] ]] > $ defaultPlotLines yields the following output: \perform{renderAndInclude image "image.pdf"}. \end{document}
The central helper function you should write is something like renderAndInclude above, which does the actual rendering, writes the result to a file, and issues the LaTeX \includegraphics command, which reads the file.