190 Tugboat, Volume 34 (2013), No. 2 Lippgen: a Presentation
Total Page:16
File Type:pdf, Size:1020Kb
190 TUGboat, Volume 34 (2013), No. 2 LiPPGen: A presentation generator for sentation does not depend on syntactical constraints. literate-programming-based teaching For a developer this means that the original creative process can be recorded in the literate program, al- Hans-Georg Eßer lowing both top-down and bottom-up approaches. Abstract Instructors can base the presentation on didactic con- siderations, for example, they can first give function Literate programming techniques can be used as a definitions and structure declarations in an incom- teaching method | not only in book form, but also plete form (when the audience does not have the for lectures in the classroom. I present a tool which required knowledge to understand the full versions) helps instructors transform their literate programs and later extend them when the missing information into lecture presentations: LiPPGen, the Literate- has been taught. Programming-based Presentation Generator, takes a Since a book is not helpful in a classroom setting, standard literate program (with LAT X as the docu- E the question arises of how an instructor might create mentation language) as input and lets the instructor lecture slides from a literate program. While it is comfortably generate presentation slides for each possible to copy and paste fragments from the literate code chunk. It then assembles the provided slide program into a presentation and manually add text, texts and the code chunks and turns them into a such a procedure is tedious and will not always lead browser-based presentation. to good results. Also, whenever the author modifies LiPPGen offers unique features in comparison to the original literate program, he or she must also standard presentation programs (such as PowerPoint) manually update the slides. Until now, there has in that code chunks may be larger than the space on been no software to aid the instructor in creating a a slide permits: if so, the code can be scrolled during literate-programming-based presentation. the presentation. The code is also presented with syntax highlighting using simple regular-expression- 2 LiPPGen features based rules. Currently, C and Python are supported. LiPPGen [2] lets you select a part (or several parts) This article describes both the features and us- of a literate document by marking blocks with begin age of LiPPGen and provides an example, showing and end comments. When running the tool on such a small literate program (the implementation of a a file, it creates an HTML file and opens it in the component of an educational operating systems) and browser (Figure1). The page shows code chunks its transformation into lecture slides. and documentation blocks separately (with most LiPPGen is available under an open source li- LAT X code either stripped or converted to equiva- cense so that others who use literate programming E lent HTML), and for each code chunk you can enter in an instructional environment can also use the some descriptive text in an HTML editor field sit- software and modify it to their needs. ting next to the code chunk. (The program displays the documentation parts as well so that you can 1 Introduction easily decide what information to pick for the slide Literate programming [5] is a programming technique invented by D. E. Knuth which lets developers create source code and documentation in one \literate pro- gram" from which both well-readable documentation and compilable source files can be extracted. It can be used to create textbooks on any computer science topic that involves presenting and explaining larger program code blocks. This approach has been used by a few authors, including Knuth himself, when he published the TEX source code [6], but also more recently, for example by Pharr and Humphreys who explain the art of 3D rendering in their book [10]. Ad- ditional literate-programming-based textbooks are mentioned in the \Books: Applies Literate Program- ming" section of the literateprogramming.com link list [7]. Figure 1: LiPPGen lets you convert literate programs One of the advantages of literate programming into presentations, with large parts of the process over other development styles is that the order of pre- being fully automatic. Hans-Georg Eßer TUGboat, Volume 34 (2013), No. 2 191 content.) The editor allows for simple markup, such we want to show code which exceeds the available as enumerations, bullet lists, bold, and italics. space on a slide. When you've entered all the information, you 3.1 Recycling: Use what's there can send the data back to the program (it supplies a simple HTTP server for just this purpose), and then Classically, open source developers are too lazy to LiPPGen creates an HTML presentation file with the reinvent the wheel, and so at the beginning I checked code chunks and your added input. Finally it opens for available tools which might be able to reduce my the new presentation in the browser. own development efforts. I found two very helpful Additional features are: programs: You can repeat the editing process several times; The \Simple Standards-based Slide Show Sys- • • data entered in a preceding program run remains tem" (S5) contains CSS files which let users available. create complete presentations in single HTML The presentation shows chunk names in a way files [8]. Adding a slide is as simple as writing • that is similar to the formatting in a traditional <div class="slide"> literate program (e. g., name ), both for the <h1>Slide Title</h1> definition (as in name h. andi name + ...) ... as well as for occurrencesh i≡ in otherh codei chunks.≡ </div> LiPPGen recognizes repeated (i. e., continuing) • in the source file, and bullet items need no more definitions of code chunks. The first one is al- than standard HTML lists (<ul><li>...</li> ways shown as name , whereas the following </ul>). ones use nameh + .i≡ Also, the chunk names h i ≡ A LiPPGen presentation looks a lot like a are used as slide titles, and if a chunk occurs on standard S5 presentation, except for the added several slides, LiPPGen increments a counter. literate programming bits. Simple syntax highlighting (via regular expres- The \NicEdit Inline Content Editor" [4] is a • • sions) is available for C and Python source code, JavaScript program that provides an HTML edi- so there's a bit of pretty printing. You can easily tor which can be embedded in HTML pages. It extend this to other languages. is customizable, and for LiPPGen I've disabled As part of the syntax highlighting LiPPGen most of the available buttons, since they are not • also breaks code lines which are too long. The needed. continuation is shown via an arrow character at the end (similar to the display in the XEmacs 3.2 The power of Python editor) and there are dots at the beginning of the Python comes with several useful libraries and allows following line. That way it is clear where a line the on-the-fly implementation of a simple web server. begins and ends, without a need to introduce (This is true for many other script languages, but I line numbers. know Python best | the simple reason for choosing When you give the presentation, you can scroll it.) We need one for accepting the user's input on • code chunks up and down using the cursor keys the web form, and Python's socket module let me (for code chunks which are longer than the slide integrate the web server into the program. permits). Each code chunk \remembers" the The complete lippgen script is only about 700 current scrolling position, so when you later lines long, and these few lines of code handle pars- return to a slide, the display of the code chunk ing the literate program document, generating the is as it was when you last left the slide. HTML form, accepting the user input, and assem- bling the final HTML files with syntax highlighting, 3 Implementation line breaking and other stuff. When attempting to convert a document which is 3.3 Some JavaScript as well basically in LATEX syntax | though in its extended Literate Programming form | the natural choice for In order to allow scrolling of the code chunks, I had slide creation would be to stick with LATEX and use to slightly modify the JavaScript code that is part one of the available LATEX document classes for pre- of the S5 system. In brief, I've given HTML names sentations, such as beamer [13]. However, the end to all code chunks and changed the key-press event result of any approach using LATEX will be a PDF code so that [Cursor up] and [Cursor down] scroll document, and such documents are static. the currently displayed code chunk up and down. In contrast, HTML allows elements on a page to I also modified S5's default/pretty.css file so be scrollable, and this feature comes in handy when that the standard font for listings (tt) is M+ 1m [9] LiPPGen: A presentation generator for literate-programming-based teaching 192 TUGboat, Volume 34 (2013), No. 2 since this font runs narrower than the standard 2. Run ./lippgen on the file, e. g. by issuing the Courier type fonts. command ./lippgen example.nw; this produ- ces a file example.form.html and opens it in 4 LiPPGen tutorial the preconfigured browser. To try out LiPPGen yourself, download the software The default language for syntax highlighting and install it; then pick a sample literate program is C. If you want Python instead, use Python and use lippgen. We'll describe the process here. as a second argument to lippgen. If you use a different language, modify the program.