Provide any literate Haskell in PDF, HTML or similar

How to convert a literate Haskell file to something easier before our eyes? Here's what happens when I try to do the obvious thing:

$ 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} 

I am not familiar with the usual commands for processing tex files. What a simple, no-frills way I can use to convert almost any .lhs file, for example. PDF or HTML?

+4
source share
2 answers

In this space you can use lhs2TeX, which has many options, but can give good results when formatting. It has fairly extensive documentation, which you can find on the home page .

An example of use (directly from the manual) would be

 \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} and \end{document} are all TeX commands to indicate which document you need and where it starts / ends.

%include polycode.fmt is actually a comment in TeX, but will tell lhs2TeX what format to use when processing the .lhs file.

You can compile an example with

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

For HTML, you can also try Pandoc , which can provide you with all kinds of output formats (pdf, html, rtf, etc.).

+12
source

You want to preprogram your literate files with lhs2tex .

+2
source

Source: https://habr.com/ru/post/1414303/


All Articles