2012-05-25 66 views
4

如何將Literate Haskell文件轉換爲更容易的東西?下面是當我嘗試做明顯的事情會發生什麼:將任何Literate Haskell渲染爲PDF,HTML或類似文件

$ latex Check.lhs 
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) 
entering extended mode 
(./Check.lhs 
LaTeX2e <2009/09/24> 
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh 
yphenation, loaded. 

! LaTeX Error: Environment code undefined. 

See the LaTeX manual or LaTeX Companion for explanation. 
Type H <return> for immediate help. 
...            

l.7 \begin{code} 

我不熟悉處理TEX文件通常的命令。什麼是一種簡單的,毫無意義的方式,我可以用來將幾乎任何.lhs文件轉換爲PDF或HTML?

回答

2

你想用lhs2tex預處理你的識字文件。

12

在這個空間中,您可以使用lhs2TeX,它有很多選項,但可以在格式上給出相當不錯的結果。它有相當廣泛的文檔,你可以在homepage找到。

使用(直接從手動)的一個例子是

\documentclass{article} 
%include polycode.fmt 
\begin{document} 
This is the famous ‘‘Hello world’’ example, 
written in Haskell: 
\begin{code} 
main :: IO() 
main = putStrLn "Hello, world!" 
\end{code} 
\end{document} 

\documentclass{article}\begin{document}\end{document}都是TeX的命令,指示你想要什麼樣的文件,並在那裏開始/結束。

%include polycode.fmt實際上是TeX中的一條評論,但會指示lhs2TeX在處理.lhs文件時使用何種格式。

您可以編譯的例子與

$ lhs2TeX -o HelloWorld.tex HelloWorld.lhs 
$ pdflatex HelloWorld.tex 

對於HTML,你也可以嘗試Pandoc,它可以給你各種輸出格式(PDF,HTML,RTF等)。