Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Generate PDF output #11

dungpa opened this Issue Mar 13, 2013 · 2 comments


None yet
2 participants

dungpa commented Mar 13, 2013

Hi Tomas,

I often need PDF documents with F# syntax highlighting. I wonder whether we should generate PDF output directly from the tool.

We can generate a LaTeX document and use pdflatex to produce PDFs. The advantage is that we still can use templates as HTML generation. Its problem is the dependency on an external tool. However, unless we want to be something like pandoc, manipulating PDF on our own is not a good idea.

If we follow the LaTeX route, I would use listings package to color F# code. Tooltips make less sense in PDF format, but using pdfcomment we are still able to see them in Acrobat Reader.

If you agree this is reasonable thing to do, I will try to come up with a pull request.


tpetricek commented Mar 15, 2013

having a way to generate PDF output from the document would be great. I quite like the LaTeX option (this would be nice for people like me who occasionally want to include some F# code in academic publications, which often require LaTeX).

As for the packages used, the pdfcomment looks quite nice (but I agree that tooltips do not make that much sense in PDF). The listings package seems to take care of the colouring itself (the text in the document is just plain text). I suppose that if you want to generate LaTeX, you would generate code with all the formatting (based on the AST, just like when generating HTML), so I do not see how this would work (but definitely, give it a try! I'm a LaTeX beginner :-)).

It might be worth checking out how lhs2TeX works - which is a similar tool for Haskell.

Thanks for your interest in doing this! Having PDF output would be really great!


dungpa commented Mar 27, 2013

I finally have some time to work on a pull request.

I abandon tooltips completely because we don't need them in PDFs.

Regarding source code highlighting, I narrow to choose one in three packages: fancyvrb, minted and listings.

  • fancyvrb: pros - easy to customize with commands; cons - hard to set background color and word wrapping.
  • minted: pros - extending fancyvrb with advanced options; cons - hard to set up and having external dependencies (Python, etc).
  • listings: pros - supporting background color and word wrapping; cons - hard to extend the current setting.

Right now I implement fancyvrb to colorize F# source code and listings to format other languages. I tried to extend listings in the same way I did with fancyvrb but failed. Otherwise, using only listings is the preferred option.

When writing conversion from Markdown to LaTeX, I notice HtmlBlock. LaTeX doesn't support inline HTML, so I escape those strings and display them as is. In the future, we may need to parse HTML and convert to LaTEX.
And the fact that we format snippets as HtmlBlock before displaying is confusing since it is not the only way the snippets should be processed.

I took a look at lhs2TeX. We can generate beautiful type-set source code with math symbols like them if we handle Markdown math extensions. One might have to annotate to recognize which bits need to be type-set. I'm just toying the idea with template-math.tex template.

Please take a look at the #14 issue.

@dungpa dungpa closed this Apr 16, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment