I remember the first time I glanced at TeX.sx: it was amazing. Useful information everywhere. Every bit of helpful commands, great constructs, clever conditionals, you name it, was right there, available at the distance of a mouse click.
One of the things that intrigued me was the absence of a print button. There are some questions about it in the main SO meta site. I admit it, I’m not a good screen reader, I need to have something physical to hold and draft. I want to save trees, but hey, I promise to plant another one. Just remember that ant and… oops there goes another rubber tree plant.
TeX.sx stylesheets do have some sort of printing support, but I was not satisfied with the result. I was expecting a more uhm… friendly result. When searching for possible workarounds, StackPrinter called my attention. I like the idea of a very clean interface and straight to the point. Unfortunately, I’m retrograde and not fond of webapps, I usually prefer the good old desktop app. Besides, I’d like something special for our TeX community, after all, amongst the plethora of StackExchange sites, TeX.sx is a fine gem.
On June 27th, in the TeX, LaTeX and friends chatroom, I made an announcement:
I wrote an experimental app similar to the stackprinter.com concept, but specific for tex.se and with PDF output. I wrote it yesterday and probably has several bugs and errors and so forth. It’s called TeXPrinter. I know, I fail at names, so don’t expect an original one…
Finally, on July 11th, again in the chatroom, I announced the first release of TeXPrinter, hosted in both SourceForge and GitHub:
It’s finally up! texprinter.sourceforge.net I just need to update the SVN and Git repos.
In the same day, Joseph Wright blogged about it in his blog. And TeXPrinter was introduced into the TeX.sx scene.
So what is this TeXPrinter application? Stefan Kottwitz suggested me to write about it, so here it is.
I had to choose a language to develop my app. Since I work with three different operating systems at the same time, I opted for Java. I could make it quite self-contained, in the sense of deploying one single file with all batteries included. The only requirement to run is a Java Virtual Machine. I’m very pleased that TeXPrinter runs flawlessly on both Oracle JVM and OpenJDK (the default in Linux distributions).
The core method in TeXPrinter is the one that actually fetches questions. I had to make the code compliant with the StackExchange HTML model and consistent enough to correctly extract data.
I tried to follow the KISS principle – keep it simple and straightforward – so the interface is very clean (I guess) and straight to the point. All you need is love… I mean, the question ID. The ID is that bunch of numbers that identify your question, the pattern is: http://tex.stackexchange.com/questions/ID
. Easy, right? So let’s see how it looks:
There we go, plain and simple. If you want to check the about box, type ? and hit OK. To print a thread, simply type the question ID and hit OK. TeXPrinter will attempt to fetch the thread, extract the content and generate the output. Which brings us to the next screen, if nothing goes wrong:
TeXPrinter can generate two formats: PDF and TeX. Before we continue, I must give an explanation on PDF first. In the early development stage, I thought of letting the underlying TeX distribution (TeXLive, MiKTeX, and so forth) to take care of the PDF generation, but I chose a minimalist approach: first, I can’t assume every potential TeXPrinter user has a working TeX distribution at the moment; and second, I don’t like to make external calls from my app, it’s dangerous, some kind of shell-escape
paranoia. So TeXPrinter relies on iText, a PDF library, thus working out of the box.
A friendly developer note: I’m aware that the iText library might raise an error while dealing with certain threads, probably due to a bug in the library. In that case, the PDF output won’t be generated. Until I find a workaround, I suggest you to generate the TeX output instead, as it should work. Only a few questions are affected.
I know the PDF output is very basic (ugly). I’m sorry, I really can’t think of anything better for that layout. As I said, it was a design choice. But hey, we are TeXers, we go wild for TeX output! Now the story takes a good turn.
The TeX output organizes everything inside an article
document class, with the nice listings
package providing syntax highlighting. Note that there are some LaTeX documents that won’t compile at first, possibly because of a bad formatting in the HTML. I tried to guess the correct syntax most of the time, but you know the humanity. If your document doesn’t compile at first, fix it – you won’t be difficult, I swear – and there you go, a nice PDF output. Ah, if the thread has images, they are automatically downloaded to the current folder.
If everything goes fine, you will reach the following screen:
Go there Luke, use the source! You can use TeXPrinter from the command line, just go to your terminal and type the following command: java -jar texprinter.jar --help
. The usage message will be displayed, so have fun.
Update: you can take a look on the resulting PDF output through the buit-in PDF library and the generated LaTeX code.
For this new version on, I added a version checker in the about window. Keep in mind that it will only let you know if there’s a newer version available, but it won’t download it for you. Security reasons again. Or programmer laziness.
TeXPrinter is far from finished. There are lot of things to improve, bugs to fix, features to add. I fixed several critical bugs found in the previous versions. Unfortunately:
Program testing can be used to show the presence of bugs, but never to show their absence. – Edsger Dijkstra
I added an experimental feature of a semi-automatic error report sending mechanism. If you encounter a really bad error, you will see this window:
If you reach this screen, please consider sending me an anonymous error report. It helps me a lot.
TeXPrinter is released under the New BSD license and the full source code is available in the project page in SourceForge or in the code repository in GitHub. I develop it in my spare time, so it might take a while until I implement new features or fix new bugs.
Speaking of new features, I’d love to collect potential ones! Joseph already suggested me two interesting features: (a) take multiple questions and automatically build an entire book of frequently asked (La)TeX questions; and (b) grab questions based on tags. They are already in my TODO list.
I really hope you like TeXPrinter. Thanks!
References
- The first YouTube link goes to Frank Sinatra’s version of High Hopes, a song introduced in the 1959 film A hole in the head.
- The second YouTube link goes to a clip version of All you need is love, The Beatles.
- All the cartoons are from the archives of the Dilbert comic strip, written and drawn by Scott Adams.
May the Source be with you Paulo! I think hanging in this site is my best investment I have ever did on my digital life. So good to see you and other guys do your magic.
Hey Paulo, thanks for the StackPrinter reference and good luck for your cool and interesting Project.
Hope to see a more general-purpose application for all the StackExchange network soon :).
Michele
Thanks percusse! Our community is fantastic, I’m glad you make part of it. 🙂
Thanks for the kind words, Michele! I’ll consider extending the scope of this application, it would be awesome to have a general purpose printing tool. 🙂
I appreciate the app (though I probably won’t ever use it) but had the time not been better spent on improving stackexchange’s print CSS?
Oh, please consider linking an exemplary conversion result (ideally, PDF) so we can get an impression of print quality without having to run the tool ourselves. Thanks!
CSS can’t ultimately match TeX for print quality, so it does make sense to have a TeX-based format as an option.
As Joseph pointed out, CSS can’t match TeX for print quality. Besides, we don’t have control on the StackExchange stylesheets. IMHO, printing a thread from your browser directly to a (virtual) printer won’t help much. We’d like to ensure quality and a good layout.
Great idea! I updated the post with sample a PDF. 🙂