kosmikus / lhs2tex

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

\aligncolumn not working properly with \restorecolumns #83

Closed Krantz-XRF closed 10 months ago

Krantz-XRF commented 4 years ago

See the following example, I expect all the code centered, align at the equal sign, with LHS align to the right and RHS align to the left.

\documentclass{article}
%include polycode.fmt

\begin{document}

  \begin{center}
  \savecolumns
  \aligncolumn{5}{@@{}>{\hspre}r<{\hspost}@@{}}
  \begin{spec}
    a         = alice
    aaaa      = f
  \end{spec}
  \end{center}

  \begin{center}
  \restorecolumns
  \aligncolumn{5}{@@{}>{\hspre}r<{\hspost}@@{}}
  \begin{spec}
    bbb       = bob
    test      = t
  \end{spec}
  \end{center}

  \begin{center}
  \restorecolumns
  \aligncolumn{5}{@@{}>{\hspre}r<{\hspost}@@{}}
  \begin{spec}
    cccccccc  = carol
    c         = carol'
  \end{spec}
  \end{center}

  \begin{center}
  \restorecolumns
  \aligncolumn{5}{@@{}>{\hspre}r<{\hspost}@@{}}
  \begin{spec}
    bbb       = bob
    test      = t
  \end{spec}
  \end{center}

  \begin{center}
  \restorecolumns
  \aligncolumn{5}{@@{}>{\hspre}r<{\hspost}@@{}}
  \begin{spec}
    cccccccc  = carol
    c         = carol'
  \end{spec}
  \end{center}

\end{document}

But after running lhs2tex test.lhs -o test.tex and pdflatex test.tex, some LHS end up aligning to the left. If I manually modify the generated TeX file, replace the l with r in \column{5}{@{}>{\hspre}l<{\hspost}@{}}%, I get the correct result:

Incorrect Correct
image image

I did not find documentation for aligncolumn, so I followed instructions in #23.

kosmikus commented 4 years ago

Sorry for the late reply. Thanks for the detailed report. I can reproduce this. I'll try to understand what's going on.

kosmikus commented 4 years ago

This is a bug in polytable.sty. I have committed an updated version to the branch https://github.com/kosmikus/lhs2tex/compare/wip/issue-83

Note that installing polytable.sty via lhs2tex is fragile. Depending on your setup, you may have to manually put the new polytable.sty into a directory where your LaTeX installation will find it.

It would be great if you could confirm that the fix works not just for the sample file you reported with, but also the file that actually first triggered the problem for you.

Krantz-XRF commented 4 years ago

Thanks for the fix! I edited polytable.sty in my local MiKTeX installation as in this line (in the above mentioned branch), and it worked as expected.