I've been learning how to write scripts to generate Latex reports and tables from data sources. Instead of using Latex directly to do this, the script written in your favorite language, which must have support multi-line raw strings, generates the Latex code on the fly as it is reading the data from external sources (files, XML, etc...).
The script formats the fields, builds the Latex tables, and does any computation needed in between, inserts these fields into the Latex stream and writes the final Latex code to external files.
The latex file is then compiled to pdf and HTML. Here is a small diagram of one report I've done this way (this happened to be a computer algebra related, where the input to the script that generates the reports and tables are plain text files with comma delimited fields). Some of these fields contain equations in Latex also generated by the computer algebra programs as result of solving integration problems.
There are over 70 PDF files generated this way, some over few thousands pages long, all from the same program. The program loops over the input, building the tables, doing statistics, and writing the Latex.
The result can be seen here. These pages are all done in Latex, compiled to HTML using tex4ht, but the Latex was generated from a program. I found it much more flexible doing it this way, than using Latex itself for the logic and the processing.
There are few languages that supports multi-line raw strings well (sometimes called HERE-DOCUMENT). These are: Python and C++11, Ruby and Perl. (Perl 6 will be out this year!)
The need for multi-line raw string is important, it allows one to write the Latex code in the script, as freely as you would do in a Latex editor.
The only difference, is that is it much easier to do the logic and the programming, the database interface and any numerical computation in these languages than in Latex itself, and on the fly using this method.
Here is a typical python script that generates a Latex file with a formulated table:
my_file = open("py_latex.tex", 'w')
num = 6
for i in range(1,num+1):
for j in range(1,num+1):
x=x+'$'+str(i)+' \\times '+str(j)+' = '+str(i*j)+'$'
if j<num :
When compiling the Latex file generated, the table is
This link has small examples using Ruby, Perl, C++-11 and Python for generating small Latex files. If the raw data is in XML, once it is loaded (using XML API library, which those language all have one), then the same method can be applied as above.
Another option is to use LuaLatex, and use Lua code to do these things. But I found the interface between Lua and Latex a little harder to manage. I found it easier to just use a script and generate all the Latex code on the fly directly.
May be this gives you some ideas any way. This method might not work for everyone. It definitely needs time to get used to it.