Search code examples
latexliterate-programming

How to hide block of code


I'm writing a program in a .lhs file which contains code in Haskell (I'm specifying this because I want it to be clear that it's not only for rendering a pdf but it's also for being execute with runhaskell or ghci). I'm rendering the code with lstlisting like this:

\begin{lstlisting}

> Haskell code here

\end{lstlisting}

Anyway, the code itself require some modules that I have to import, but I don't want the imports to appear in the resulting pdf. So, I've tried to put the code without the lstlisting block, like this:

> import X
> import Y
...

But it's not working and the resulting PDF renders those lines only not as code like lstlisting would do. What should I do to write the import code only for being execute but not to be showed in the PDF itself?


Solution

  • The Haskell wiki suggests defining a LaTeX macro like:

    \long\def\ignore#1{}
    

    You could also define this with \newcommand which, to me, seems more natural:

    \newcommand{\ignore}[1]{}
    

    In both cases, it is used like this:

    \ignore{
    
    > import Foo.Bar (baz)
    
    }
    

    `