How to highlight particular ranges of lhs2TeX code in beamer?

Naive example (to be preprocessed with lhs2TeX --agda):

%include agda.fmt
somefunction :  {-"\begin{alertenv}"-}importantaspect{-"\end{alertenv}"-}

Compiling such a snippet fails with:

./test.tex:308: Incompatible glue units.
\reset@color ->\beamer@lastskip =\lastskip 
                                           \edef \beamer@lastskiptexta {\the...
l.308 \end{frame}

In Agda mode, the alerted region contains an occurrence of \;, as you can observe if you look at the generated code:


This is triggering the error (it's a muskip and apparently something tries to put it into a normal skip register, leading to the incompatibility error; however, I don't currently completely understand who's responsible). One can argue that lhs2TeX shouldn't put the skip there in the first place.

I can see two workarounds.

(1) Put another skip in that's easier to digest:

somefunction :  {-"\begin{alertenv}"-}importantaspect{-"\hskip0pt\end{alertenv}"-}

(2) Avoid the skip from being inserted by using a different formatting mechanism, for example

%format Importantaspect = "\alert{" importantaspect "}"

and then

somefunction :  Importantaspect
  • I updated the question with a minimally complete example. Two aspects were missing from the original question: A second line and --agda.
    – Helmut
    Mar 11 '14 at 8:11
  • I've adapted the answer.
    – kosmikus
    Mar 11 '14 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.