# LaTeXDB

Integrating LaTeX and SQL databases

This is LaTeXDB. The purpose of this project is to bring together LaTeX and an SQL database. By using LaTeXDB you can use SQL queries in your LaTeX document and loop over the result sets, creating tables, serial letters and other stuff. From version 0.2 on, LaTeXDB allows nesting of SQL queries. LaTeXDB is released under the GPL. ### Contents
Introduction Requirements Download version 0.3 / Release Notes Installation First try | Limitations Workshop (new page) Reference (n.a.) Credits Copyright/Feedback
     \begin{document}
       \texdbfor{##AllUsers}{
         Dear ##Title ##Lastname,

         thanks for ordering ##Quant items of ##Product.
         I'll ship it to your address in ##Town when I
         find the time.

         Best regards,
         \newpage
       }
     \end{document}

[2006/04/24] Version 0.3 released which fixes the bug described in the next entry.

[2006/03/26] Some users noted a bug where LaTeXDB will terminate with an error (and no output) when the size of a \texdbfor{} loop is too big. This is actually a stupid programming mistake causing Python to recurse too deeply. I'll exchange the recursive code with an iterative equivalent. Won't be long now ;)

[2005/10/27] There's a spanish introduction to LaTeXDB at http://caldum.um.es/~juanjo/?p=30.

### Introduction

LaTeXDB is pretty simple to use, there are only three new commands to extend your LaTeX files: With them you define a database connection, create queries and access the result sets.

You include commands such as

    \texdbconnection{DBType,host,user,passwd,db}

to setup a database connection,

    \texdbdef{##query}{select var1,var2,... from table where...}{##VAR1,##VAR2,...}

to define a query, and

    \texdbfor{##query}{... some LaTeX stuff with ##VAR1, ...}

to use the results in your LaTeX code.

### Requirements

This relase of LaTeXDB supports MySQL and PostgreSQL. You need Python (tested with version 2.2.2) and the Python MySQLdb or psycopg module for MySQL or PostgreSQL support, respectively. The database need not be running on the local machine, since you can use any server that you could also access from the mysql or similar command line client.

### Download / Release Notes

Version 0.3 [2006/04/24]: latexdb-0.3.tgz
A bug within the preparser that caused latexdb to break in texdbfor loops with too big arguments was fixed (contributed by Francois Meyer)
- New script pdflatexdb which is the same as latexdb but calls pdflatex instead of latex, so it generates PDF, not DVI files (user request)

Version 0.2 [2003/08/20]: latexdb-0.2.tgz
Queries can now be nested (refering to data from the upper query).
Using MySQLdb modules instead of _mysql
Extended to use PostgreSQL as well, code cleanup. (contributed by Gerhard Kirchmann)

Version 0.1 [2003/08/15]: latexdb-0.1.tgz
Initial release, MySQL support

### Installation

This is easy too: Grab the archive, unpack it, and run install as root, or for minimum functionality copy latexdb, latexdb.py and latexdb-preparse.py from the code directory to /usr/local/bin or some other directory that can be found in $PATH. Only put them in the same directory, because latexdb expects latexdb.py and latexdb-preparse.py in its own directory.

### First try

For a first try of LaTeXDB check the tiny tutorial in workshop.html. A more thorough description can be found in reference.html (not available yet). There are some examples in the examples folder of the package.

### Limitations

This is a quick hack, more a proof of concept. One of the special commands introduced with LaTeXDB (the database connection) needs to sit on a line of its own (and only one line), only the commands for defining queries and using the result set can use as many lines as you like and have other stuff in front and behind.

The Python code is strictly procedural. Some people won't like that since you're supposed to do objects in Python ;) But I couldn't be bothered. If anyone likes to write up this code and make it follow standard Python programming more properly, I'd be happy to see that code.

I have not included proper error condition checking. Do something wrong, and the tool will break. It won't kill any of your files, and it will even give some hint as to what was wrong while it dies.

### Credits

There's no point in trying to list all developers who have created the software that I used. However, this program is here thanks to the existence of Linux, MySQL, Python, TeX, LaTeX, and lots of other stuff -- we tend to forget.

PostgreSQL support was contributed by Gerhard Kirchmann.

The man page was created using manedit, http://wolfpack.twu.net/ManEdit/.

### Copyright and Feedback

LaTeXDB is Copyright © 2003-2006 Hans-Georg Eßer (h.g.esser@gmx.de).

It is released under the GNU GPL, a copy of which you find in the package after downloading. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

If you have suggestions how to improve this software, or if you have successfully used it for something a lot better than the trivial examples given in the documentation -- please drop me a note.