I am looking for LaTeX style files for writing a programming language book (OO programming with Java examples). I'd appreciate if anyone can point me to style files that I can use.
4 Answers
I do not have a package to recomment, other than listings which was already suggested, but I would like to offer one general piece of advice: use the power of TeX to make your examples automatically correct.
What I mean by this is that with TeX/LaTeX you can set up an example environment whose body contains your source code. That source can be automatically written to a file (together with some hidden preamble and some hidden postamble as necessary) so that the resulting file forms a complete program that can be externally compiled. With the right kind of system setup you can then ensure that those compilations are automatically done and that the result is available to you again, e.g., in form of a graphic that can be read in by TeX and displayed next to your input. This way you can be sure that what you describe corresponds 100% to the results you show and this is a huge asset.
I can't tell you how many errors we later found in the first edition of the LaTeX Companion (which was proof read by many people, including professional proof readers) and how much headaches were avoided by switching to such a scheme in the second edition.
I don't think there is a package ready for this kind of approach, as it largely depends on the type of language you document as well as on the environment you have available, e.g., the external formatting needs to be done using something like make and some scripting support, but from my experience it is certainly worth investing in this space. And I know that several other authors have applied the same kind of approach in their publications.
- 77,146
-
One approach in this direction (for inspiration) is the bashful package, which provides this feature for shell code. Maybe it can be configured / adapted to run another Java compiler. – Daniel Feb 08 '12 at 12:58
In addition to the already-mentioned listings package, you may also want to look into the algorithms, algorithm2e, and algorithmicx packages.
- 506,678
For nice typesetting of listings and their output I can also recommend the
tcolorbox package. While it's main purpose is to typeset beautiful example boxes (PGF-based), it also has built-in support for verbatim material and especially the listings package to externalize code snippets into own files, which could be helpful to implement Frank's approach.
- 37,517
-
-
1This is a beautiful package and deserves a bit more promotion. Can anyone of our German speakers make a small translation as to how to use it? If you can I can post a relevant question. – yannisl Feb 08 '12 at 13:38
-
@YiannisLazarides: I think this comment should be pointed out in the chat. Of course I can give some hints. – Marco Daniel Feb 08 '12 at 16:19
-
@YiannisLazarides: Note that besides the German package documentation there also is an English
tcolorbox-examples.tex, which demonstrates most of the features and is pretty self-explanatory. However, regarding promotion, a dedicated question might be helpful :-) – Daniel Feb 09 '12 at 08:23 -
@YiannisLazarides: Please see: http://chat.stackexchange.com/transcript/message/3331785#3331785 – Marco Daniel Feb 09 '12 at 17:47
I also create "lecture notes" for my programming students. I'm very impressed with memoir class and the minted package for pretty-printed (color coded) output of code. Try it out. The output is pretty good.
- 4,201
listingspackage andbookdocument class. – kiss my armpit Feb 07 '12 at 22:41