Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

LyX /

Lhs2LyX

Categories: LHS, lhs2TeX, lhs2LyX, Haskell
<< | Page list | >>

This page describes how one can include literate Haskell files (*.lhs) in LyX using Templates and have LyX convert them automatically to TeX files using lhs2TeX. The solution presented here is suboptimal. Suggestions for improvement are very welcome.

Before starting, make sure lhs2TeX is installed on your system. The easiest way to do this is by executing cabal install lhs2TeX. See the lhs2TeX website for other installation options.

Create a lhs2TeX .sty file, which can be included in your preamble. See the FAQ in the lhs2TeX manual for instructions.

Open your LyX settings window and go to File Handling -> File Formats. Add a new format called LHS with "lhs" as short name and "lhs" as extension (without the quotes). Select the Document format checkbox. Next, add a new converter in the File Handling -> Converters dialog. This converter converts from LHS to LaTeX (pdflatex). Add the following line to the Converter field: lhs2TeX $$i -o $$o

Finally, add a new template to your external_templates file. This file is located somewhere in ~/.lyx on Linux and in ~/Library/Application Support/LyX-n/ on Mac OS X. Its contents are:

Template LHS 
    GuiName "LHS: $$AbsOrRelPathParent$$Basename"
    HelpText
        Including Literate Haskell
    HelpTextEnd
    InputFormat lhs
    FileFilter "*.lhs"
    AutomaticProduction true
    Format LaTeX
        Product "\\input{$$AbsOrRelPathMaster$$Basename.tex}"
        UpdateFormat pdflatex
        UpdateResult "$$AbsPath$$Basename.tex"
        ReferencedFile lhs "$$AbsPath$$Basename.tex"
    FormatEnd
    Format PDFLaTeX
        Product "\\input{$$AbsOrRelPathMaster$$Basename.tex}"
        UpdateFormat pdflatex
        UpdateResult "$$AbsPath$$Basename.tex"
        ReferencedFile lhs "$$AbsPath$$Basename.tex"
    FormatEnd
    Format Ascii
        Product "\\input{$$AbsOrRelPathMaster$$Basename.tex}"
        UpdateFormat pdflatex
        UpdateResult "$$AbsPath$$Basename.tex"
        ReferencedFile lhs "$$AbsPath$$Basename.tex"
    FormatEnd
    Format DocBook
        Product "\\input{$$AbsOrRelPathMaster$$Basename.tex}"
        UpdateFormat pdflatex
        UpdateResult "$$AbsPath$$Basename.tex"
        ReferencedFile lhs "$$AbsPath$$Basename.tex"
    FormatEnd
TemplateEnd

That's it! You might need to restart LyX first. You can add .lhs files directly to your LyX document via the Insert -> File -> External Material menu.

Happy Haskelling!

LHS lhs2TeX lhs2LyX Haskell

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2010-11-01 16:25 UTC