kosmikus / lhs2tex

Preprocessor for typesetting Haskell sources with LaTeX
Other
99 stars 28 forks source link

Different styles (?) in one file? #56

Closed nomeata closed 11 months ago

nomeata commented 7 years ago

Assume I have a bunch of %format … directive that describe the layout I want for Haskell. And then I have a similar bunch of %format … directive that describe the layout I want for a different language (Agda, or Gallina).

How can I switch between these sets on a per-listing basis?

Example (with some invented commands):

%variant haskell_code
%format instance = "\textbf{instance}
%end

%variant coq_code
%format Instance = "\textbf{Instance}
%format Global = "\textbf{Global}
%end

\begin{haskell_code}
instance Eq Bool where …
\end{haskell_code}

\begin{coq_code}
Global Instance Eq_Bool : Eq Bool := ….
\end{coq_code}

Is that at all possible with lhs2Tex?

kosmikus commented 7 years ago

Not in a nice way. You can, however, put all the formatting directives in two files, and use grouping.

%{
%include haskell.fmt

> instance Eq Bool where ...

%}
%{
%include coq.fmt

> Global Instance Eq_Bool : Eq Bool := ...

%}

(Of course, you can also use \begin{code}/\end{code} rather than > ...)

Also note that grouping for a strange historical reason does only apply to %format, but not to %subst directives.

nomeata commented 7 years ago

Not too bad, thanks for the hint! (Feel free to close this issue if you don’t plan to provide this feature properly any time soon.)