Rich Shepard wrote:
On Fri, 4 Apr 2008, Dov Feldstern wrote:

Based on your example, I would strongly recommend that you look into http://www.cheetahtemplate.org/ --- it's a wonderful tool, and it looks to me like it may be just what you're looking for.

Dov,

  Thank you for the recommendation. But, I don't see why I want to put html
code in my python application in order to produce .tex files. Or write xml.
I see the value of the templater for web applications and unstructured
reports. However, that's not what I need.


Hmmm, I thought that perhaps I had misunderstood what you're trying to do, but on reading the thread again, it still seems to me like cheetah may be what you want ;) . I'll explain:

Cheetah is actually orthogonal to html --- it's just that html is what it is usually used for, and I guess the manual is geared towards that. But in fact, it can be used for anything --- code generation, for example; as well as typesetting.

So basically, what you would do is this: start out with a latex file that outputs something that you want. Then, just replace the instances of the data in the latex file with the variables in cheetah's format. The result is a template which is basically a .tex file, but which has variables in place of the actual data. When you instantiate the template with actual data, you get a .tex file. No html/xml whatsoever involved in this.

Attached is an example which is similar to the example you posted. Here's one way of how you can use it, but since this is python, there are many other ways, depending on which is most convenient for your workflow.

0) you'll obviously have to install cheetah if you actually want to try this out

1) We'll create a file with the actual data that we want to fill the template with. In this case, we're going to use pickle to dump it into a file "cheetah.data". Note that what we dump into this file should be a dictionary, whose keys are strings of the names of the variable that we reference in the template (title and pairData, in our case), and whose values are the values we want to give these variables.

 Python 2.3.4 (#2, Jan  5 2005, 08:24:51)
 [GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 Executing Local Startup... Done.
 >>> pairData = [("Jobs","Tax base"),
 ...               ("Jobs","Infrastructure"),
 ...               ("Jobs","Schools"),
 ...               ("Jobs","Housing"),
 ...               ("Jobs","Medical care"),
 ...               ("Jobs","Sustainability"),
 ...               ("Jobs","Traffic volume"),
 ...               ("Tax base","Infrastructure"),
 ...               ("Tax base","Schools"),
 ...               ("Tax base","Housing"),
 ...               ("Tax base","Medical care"),
 ...               ("Tax base","Sustainability"),
 ...               ("Tax base","Traffic volume"),
 ...               ("Infrastructure","Schools"),
 ...               ("Infrastructure","Housing"),
 ...               ("Infrastructure","Medical care"),
 ...               ("Infrastructure","Sustainability"),
 ...               ("Infrastructure","Traffic volume"),
 ...               ("Schools","Housing"),
 ...               ("Schools","Medical care"),
 ...               ("Schools","Sustainability"),
 ...               ("Schools","Traffic volume"),
 ...               ("Housing","Medical care"),
 ...               ("Housing","Sustainability"),
 ...               ("Housing","Traffic volume"),
 ...               ("Medical care","Sustainability"),
 ...               ("Medical care","Traffic volume"),
 ...               ("Sustainability","Traffic volume")]
 >>> title="Cheetah Example"
 >>> from pickle import dump
 >>> dump({'pairData':pairData, 'title':title}, open("cheetah.data", "w"))
 >>> (Ctrl-D)

2) We now have the template (cheetah.tmpl) and the data (cheetah.data). We now want to create the actual tex file:

 [EMAIL PROTECTED]> cheetah fill --oext tex --pickle cheetah.data cheetah.tmpl

the result is a file called cheetah.tex.

This is just a normal tex file. run  latex on it, view the dvi, etc.

Now you discover that the output is not exactly what you want. But the beauty is this: this is purely a latex (or LyX, if you choose to template LyX) issue, and to solve it you just edit the template until you get the result that you want.

Hope this helps!
Dov

\documentclass[oneside,english]{article}
\usepackage{palatino}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[dvips] {geometry}
\geometry{verbose,letterpaper,tmargin=1.5cm,bmargin=1.5cm,lmargin=1.5cm,rmargin=1.5cm}
\pagestyle{empty}

\makeatletter

\date{}
\setlength\headsep{4.4cm}
\setlength{\textheight}{18.5cm}
\setlength{\textwidth}{25.0cm}

\usepackage{babel}
\makeatother

\begin{document}

\title{$title}
\maketitle

\vspace{6cm} % space below title to line up first line with OMR form

Fill in the box under \'Economic\' on this line -->

\vspace{1.5cm}

Record your position on the project here -->

\vspace{3cm}

#for $left,$right in $pairData
$left\hspace{3cm}$right

#end for
\end{document}

Reply via email to