yml2tex is a Python script which will generate a LaTeX Beamer presentation out of a YAML file. You can download the script at Google Code.
The initial idea came from Zed Shaw who wrote a similar script for his RuPy 2008 presentation and published it on his blog.
I've done presentations with LaTeX Beamer in the past, but always had a hard time remembering the LaTeX syntax for things like adding a table of contents, displaying the current frame number in the footer or adding an itemized list which highlights the current element.
The only thing I always remembered was the basic structure of LaTeX Beamer presentations (sections, subsections, frames) — and that's where YAML, with its hierarchical structure, comes into play. You don't have to remember the LaTeX commands for creating a presentation, just the basic structure.
The purpose of this script is to generate a presentation which mainly includes (nested) itemized lists. It is also possible to make a frame with an image in it and a frame which includes highlighted source code (with help from Idiopidae).
The YAML hierarchy is perfect for the features mentioned above, but not for most of the other commands LaTeX Beamer has to offer. For example, trying to create columns in a frame would be hard to realize and only complicate the YAML syntax.
In order to generate a presentation, the script requires the YAML file to have the following syntax:
- section:
- subsection:
- frame:
- item
- item
- item
(The dashes are necessary to parse an item into a List instead of a Dictionary in Python. Dictionaries have no concept of order among elements — the presentation would be completely unordered.)
The items in each frame can also be nested:
- section:
- subsection:
- frame:
- item
- item:
- item
- item
- item
Note that LaTeX Beamer limits the maximum depth of nested items to 3.
To create a frame with an image in it, the title needs to start with the "image" keyword and define the image path after it. The following example will create a frame and include the "foobar.png" image.
- section:
- subsection:
- image foobar.png:
- frame:
- item
- item
- item
Images are automatically shrunk to the size of the frame.
yml2tex will create a placeholder/marker for Idiopidae whenever it finds a frame which starts with the "include" keyword and is followed by the path of the file which should be included.
- section:
- subsection:
- include foobar.c:
- frame:
- item
- item
- item
Remember to run your generated LaTeX file through Idiopidae to actually include and highlight the source code:
idio out.tex > out_idio.tex
The first parameter needs to be the path to the YAML file. The output will be printed to stdout.
./yml2tex.py input.yml > output.tex
After generating the LaTeX syntax, you can build the presentation by executing the pdflatex command:
pdflatex output.tex
The default style was taken from Ki-Joo Kim's Beamer v3.0 Guide. The script will also:
You can download a demonstration pdf of a generated presentation and take a loot at the download the source code of it).
Published June 23, 2008 • Tagged as latex, osx, python, yaml