Now that I'm procrastinating with tweaking LaTeX, instead of finishing my Ph.D. thesis, I'm wondering what's the most beautiful way to typeset source code (C#, C++, LISP, XML, BNF) in LaTeX. Currently, I'm using the listings
package, and the literate
option, to search&replace some characters with mathematical equivalent symbols, such as:
\lstset{ %
...
literate= {+}{{$+$}}1 {*}{{$*$}}1 {=}{{$\gets$}}1
{<=}{{$\leq$}}1 {>=}{{$\geq$}}1 {!=}{{$\neq$}}1
{==}{{$\equiv$}}1 {=>}{{$\leadsto$}}1
}
Although one can find some inspiration for symbols in CWEB, I'm wondering if there exists any standard symbology for common programming (and domain specific) languages. Or maybe more appropriate packages (btw, I'm not looking for fancy syntax coloring, which would ruin my two-colored document).
Since there was some users concerned if this should be regarded as a good practice, I think this question deserves some further explanation. Overall, I have to both agree and disagree them (and I think a lot of the literate programming community too). Here's when:
- I absolutely would agree in cases one is writing a book on the language, a tutorial, a recipe, patterns, something where it is intended the reader to try that code on the computer. This can provoke confusion on the reader (where is that <- sign?), and hinder their reading pattern (you know, when you glance at hundreds of lines of code very quickly).
- But in thesis, papers, and other scientific publications, most of the snippets are illustrative; almost as if they were pseudo-code. Readability is improved, especially because lots of two/three character symbols (which can vary depending on the language) are compressed to a more symbolic notation. Now, it is true that most of you will suggest: "then why don't you you pseudo-code?" Well... First, because the pseudo-code provided by the
algorithmic
environment is nice for simplifying imperative languages, but it fails for things like LISP, XML and BNF. Second, because it takes a lot of time converting them, and it quickly falls out of sync.
Still, I maintain my original question: "examples of beautiful typography of source code".