[portland] Using LaTeX for Python Reports
Rich Shepard
rshepard at appl-ecosys.com
Wed Oct 10 19:25:41 CEST 2007
I've received some great suggestions from the LyX/LaTeX mail list. The
most cogent, I believe, is the recommendation of using the string.Template()
class for substitutions.
Tell me what you think of this approach:
The printing module imports that class:
from string import Template
The LaTeX preamble and body up to the first variable is written as
triple-quoted text, to be printed to the output *.tex file. Then each line of
LaTeX that needs real data substituted for the place holders would be written
like this:
s1 = Template('$$who likes $$what')
There needs to be two '$' because that symbol has meaning within TeX, too.
s1.substitute(who='tim', what='kung pao')
which would be followed by a print statement and the output file would
include 'tim likes kung pao'.
On the right track?
Rich
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
More information about the Portland
mailing list