Skip to content

[Feature Request] Use lhs2TeX as a preprocessor only (e.g., for \eval{}), Without Formatting Code #113

@scuellar

Description

@scuellar

lhs2TeX has a powerful preprocessor, including useful macros like \eval{} for evaluating Haskell expressions. I'd like to use these features without having lhs2TeX also format code blocks or apply its own layout/styling.

Is there a way to run lhs2TeX so it only expands macros like \eval{}, but leaves code formatting untouched? I’ve tried overriding %subst rules in a .fmt file to no-op, but I couldn't get it to fully work. A proper "preprocessor-only" mode would be ideal!


As context, I’m using minted for formatting Haskell code. It offers semantic highlighting that (afaict) lhs2TeX can’t replicate. For example, distinguishing between when a name is defined vs. used:

fix :: (a -> a) -> a
fix f = f (fix f)

Here, minted highlights fix differently on the LHS than on the RHS. I'd like to keep that behavior (and others), but still use \eval{} from lhs2TeX.


What I've tried:

I tired setting

%let style = verb

But I get the error:

*** Error in file ./lit/MyFile.lhs line 60: 
`code' is not defined;
perhaps you forgot to include "polycode.fmt" (or "lhs2TeX.fmt")?

I also tried directly setting:

%subst code a    = "\begin{minted}{haskell}'n" a "'n\end{minted}'n"

And set all other variables to no-ops. This almost worked. I keep finding little issues, like lhs2tex replacing spaces in strings with ~.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions