I want to document my code using latex, but it's really annoying having all those modules and compiler extensions show up at the beginning of the latex document. Is there some flag I can pass to lhs2TeX to prevent it from displaying this section of code in the pdf, while still letting ghc see the code?
This seems like a pretty basic feature, but I can't find it in the manual.
The right way is indeed to use conditionals.
The simple option is to exclude such code from lhs2TeX processing completely:
%if False
Everything you want LaTeX not to see. Can be
> code
as well as other stuff.
%endif
In a more advanced scenario, you might want to use lhs2TeX to preprocess both your sources for LaTeX and your code for Haskell. In such a setting, you can use
%if style /= newcode
Everything you want LaTeX not to see, as above.
%else
Everything you want LaTeX to see, but not Haskell.
%endif
Here's an example of how I use this in practice: assume I have two versions of a function; in the document I don't want to distinguish them, but in the Haskell code, they should get different names. On the other hand, the first version of the example is incomplete, so I have an ellipsis, but I still want it typechecked. So I can do the following:
%if style /= newcode
%format example1 = example
%format example2 = example
%format DOTS = "\dots "
%else
%format DOTS = "undefined"
%endif
Our first attempt:
> example1 = 42 == DOTS
Now we complete the example:
> example2 = 42 == 6 * 9
You can process this file in --newcode
mode to extract preprocessed Haskell, and in --poly
mode to get the LaTeX as usual.
The manual describes conditionals in Section 10. Examples of uses of conditionals are provided in Sections 11.1 and 11.4.
I use the following style.
%if False
\begin{code}
<code>
\end{code}
%endif
Edit: I just found Andres Löh's slides, where I have probably taken this style from.
From http://www.haskell.org/haskellwiki/Literate_programming...
If you want to hide some code, you can e.g. define:
\long\def\ignore#1{}
Auxiliary functions can be hidden as follows:
\ignore{
\begin{code}
help = putStr "Help me, what is this LiterateProgramming thing??"
\end{code}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With