kosmikus / lhs2tex

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

lhs2TeX breaks table specs of tabular environment #89

Closed jexek closed 1 year ago

jexek commented 1 year ago

I would like to use tables in an lhs document, but a tabular environment with a table spec string l | c | r in the input to lhs2TeX 1.24

\begin{tabular}{ l | c | r }
  1 & 2 & 3 \\
\end{tabular}

is translated to

\begin{tabular}{ l \ensuremath{\Varid{c}} r }
  1 & 2 & 3 \\
\end{tabular}

which is rejected by pdfTeX. I would expect lhs2TeX to not modify the table spec string. Another failing example with odd number of vertical bar symbols in the table spec:

$ cat main.lhs
\documentclass{article}
%include lhs2TeX.fmt
\title{Title}
\author{Author}
\begin{document}
\begin{tabular}{ l | r }
  1 & 2 \\
\end{tabular}
\end{document}

$ lhs2TeX main.lhs -o main.tex
*** Error in file ./main.lhs line 6: 
matching `|' not found
| r }
  1 & 2 \\
\end{tabular}
\end{document}

It seems lhs2TeX confuses itself by mistakenly interpreting a valid table spec string as something else where vertical bars must be paired.

kosmikus commented 1 year ago

That's normal lhs2tex behaviour. See e.g. the documentation, Section 3:

Inline verbatim Text between two @ characters that is not in a code block is con- sidered inline verbatim. If you actually want a @ character to appear in the text, it needs to be escaped: @@. There is no need to escape @’s in code blocks. For example, @id :: a -> a@ appears as $\verb+id :: a -> a+$.

Inline code Text between two | characters that is not in a code block is considered inline code. Again, | characters that should appear literally outside of code blocks need to be escaped: ||. For example, |id :: a -> a| appears as $\textit{id} :: a \rightarrow a$.

lhs2tex makes no real attempts to parse (La)TeX. It only recognises a few constructs. So vertical bars in table specs have to be escaped.

jexek commented 1 year ago

Thanks for a quick reply! Of course it works exactly as documented in the guide and it makes perfect sense now.