kosmikus / lhs2tex

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

OPTIONS_GHC pragma not rendered correctly #75

Open boris-stepanov opened 4 years ago

boris-stepanov commented 4 years ago

Hello.

If you declare a pragma with underscore symbol then it will be translated in a code unreadable by pdflatex.

$ lhs2Tex --version
lhs2TeX 1.22, Copyright (C) 1997-2017 Ralf Hinze, Andres Loeh

lhs2TeX comes with ABSOLUTELY NO WARRANTY;
for details type `lhs2TeX --warranty'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `lhs2TeX --copying' for details.
$ cat Main.lhs

\documentclass{article}
%include polycode.fmt
\begin{document}

OK
> {-# LANGUAGE OverloadedStrings #-}

Not OK
> {-# OPTIONS_GHC -Wall #-}

\end{document}
$ lhs2TeX Main.lhs -o Main.tex && pdflatex Main.tex

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./Main.tex
LaTeX2e <2018-12-01>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/share/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/share/texmf-dist/tex/latex/stmaryrd/stmaryrd.sty)
(/usr/share/texmf-dist/tex/latex/polytable/polytable.sty
(/usr/share/texmf-dist/tex/latex/lazylist/lazylist.sty)
(/usr/share/texmf-dist/tex/latex/tools/array.sty))
(/usr/share/texmf-dist/tex/latex/tools/calc.sty) (./Main.aux)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texmf-dist/tex/latex/amsfonts/umsb.fd)
(/usr/share/texmf-dist/tex/latex/stmaryrd/Ustmry.fd)
(/usr/share/texmf-dist/tex/latex/base/omscmr.fd)
! Missing $ inserted.
<inserted text> 
                $
l.269 \end{hscode}
                  \resethooks
? q

If you look at generated .tex file, then you'll see such line

\>[3]{}\mbox{\enskip\{-\# OPTIONS_GHC -Wall  \#-\}\enskip}{}\<[E]%

Something is wrong with the underscore.

asr commented 3 years ago

The same issue occurs with

lhs2TeX --version
lhs2TeX 1.24, Copyright (C) 1997-2020 Ralf Hinze, Andres Loeh