Re: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to that
since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as long as
you have python installed on your system, it will run.

  However, the output is not what I expected. I think it's really a Python
issue, not a LaTeX issue, so I've asked the local python geeks for help.
But, since I started this thread I thought to keep you all informed of
progress.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863#!/usr/bin/env python

import os, sys, config

preamb = 
  \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}
  
  

ending = \end{document}
  
def econPairs():
  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)]


  ratingHead = Importance   
Value   Definition
   

  ratingTab = 1   Equal importance
 3   Weak importance of one over the other
 5   Strong importance of one over the other
 7   Demonstrated importance of one over the other
 9   Absolute importance of one over the other
2, 4, 6, 8   Intermediate values between the two adjacent 
definitions


  instructPara = Using the table below, determine your preference for either 
the first
item of the pair (on the left), or the second (on the 
right). Use the
rating table to determine the strength of your preference, 
then fully
fill in the rectangle for that preference strength on the 
same line as
the component pairs. If you prefer the second more than the 
first,
also completely fill in the last box on the right.

  title = Economic Components

  out = open('omrPairs.tex', 'w')
  out.write(preamb)

  out.write(title)
  out.write(\vspace{6cm})   # space below title to line up first line 
with OMR form

  out.write('Fill in the box under \'Economic\' on this line --')
  out.write(vspace{1.5cm})
  out.write('Record your position on the project here --')
  out.write(\vspace{3cm})

  for left,right in pairData:
out.write(left)
out.write(\hspace{3cm})
out.write(right)

  out.write(ending)
  out.close()

if __name__ == __main__:
  econPairs()


Re[2]: Creating a Document Programmatically

2008-04-03 Thread Alan G Isaac
1. You need to use raw strings or double your backslashes.

2. Probably you should use LaTeX tables.

Cheers,
Alan Isaac





Re[2]: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Thu, 3 Apr 2008, Alan G Isaac wrote:


1. You need to use raw strings or double your backslashes.


Alan,

  Yes, doubling the backslashes worked.


2. Probably you should use LaTeX tables.


  I'll probably get to this for some of the reports. But, on this one the
text strings need to be aligned with bubbles on an OMR form. So I need to
tweak the horizontal and vertical spacings to get it all lined up
appropriately.

  BTW, I tried using PyX for this but didn't find enough information in the
docs to feel confident that I could.

Thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


[OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Dov Feldstern

Rich Shepard wrote:

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to 
that

since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as 
long as

you have python installed on your system, it will run.


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.


Enjoy!
Dov


Re: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Rich Shepard

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.

  The sample code I posted needs to be placed precisely on the page so the
pairs are aligned with a row of bubbles on the OMR form.

  Other reports need to incorporate plots with the text. Perhaps Cheetah
_could_ do this, but the learning curve and attempts to bend it to our needs
would consume the time it would take me to hand write the LaTeX code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re[2]: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Alan G Isaac
On Thu, 3 Apr 2008, Rich Shepard apparently wrote:
 The sample code I posted needs to be placed precisely on 
 the page so the pairs are aligned with a row of bubbles on 
 the OMR form.

It seems to me that this calls for a page description 
language, like PostScript of PDF.  However maybe you
could make a LaTeX picture that matches your page size.
Text and drawings can be placed extremely precisely in
a picture.

Cheers,
Alan Isaac





Re: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to that
since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as long as
you have python installed on your system, it will run.

  However, the output is not what I expected. I think it's really a Python
issue, not a LaTeX issue, so I've asked the local python geeks for help.
But, since I started this thread I thought to keep you all informed of
progress.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863#!/usr/bin/env python

import os, sys, config

preamb = 
  \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}
  
  

ending = \end{document}
  
def econPairs():
  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)]


  ratingHead = Importance   
Value   Definition
   

  ratingTab = 1   Equal importance
 3   Weak importance of one over the other
 5   Strong importance of one over the other
 7   Demonstrated importance of one over the other
 9   Absolute importance of one over the other
2, 4, 6, 8   Intermediate values between the two adjacent 
definitions


  instructPara = Using the table below, determine your preference for either 
the first
item of the pair (on the left), or the second (on the 
right). Use the
rating table to determine the strength of your preference, 
then fully
fill in the rectangle for that preference strength on the 
same line as
the component pairs. If you prefer the second more than the 
first,
also completely fill in the last box on the right.

  title = Economic Components

  out = open('omrPairs.tex', 'w')
  out.write(preamb)

  out.write(title)
  out.write(\vspace{6cm})   # space below title to line up first line 
with OMR form

  out.write('Fill in the box under \'Economic\' on this line --')
  out.write(vspace{1.5cm})
  out.write('Record your position on the project here --')
  out.write(\vspace{3cm})

  for left,right in pairData:
out.write(left)
out.write(\hspace{3cm})
out.write(right)

  out.write(ending)
  out.close()

if __name__ == __main__:
  econPairs()


Re[2]: Creating a Document Programmatically

2008-04-03 Thread Alan G Isaac
1. You need to use raw strings or double your backslashes.

2. Probably you should use LaTeX tables.

Cheers,
Alan Isaac





Re[2]: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Thu, 3 Apr 2008, Alan G Isaac wrote:


1. You need to use raw strings or double your backslashes.


Alan,

  Yes, doubling the backslashes worked.


2. Probably you should use LaTeX tables.


  I'll probably get to this for some of the reports. But, on this one the
text strings need to be aligned with bubbles on an OMR form. So I need to
tweak the horizontal and vertical spacings to get it all lined up
appropriately.

  BTW, I tried using PyX for this but didn't find enough information in the
docs to feel confident that I could.

Thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


[OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Dov Feldstern

Rich Shepard wrote:

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to 
that

since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as 
long as

you have python installed on your system, it will run.


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.


Enjoy!
Dov


Re: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Rich Shepard

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.

  The sample code I posted needs to be placed precisely on the page so the
pairs are aligned with a row of bubbles on the OMR form.

  Other reports need to incorporate plots with the text. Perhaps Cheetah
_could_ do this, but the learning curve and attempts to bend it to our needs
would consume the time it would take me to hand write the LaTeX code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re[2]: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Alan G Isaac
On Thu, 3 Apr 2008, Rich Shepard apparently wrote:
 The sample code I posted needs to be placed precisely on 
 the page so the pairs are aligned with a row of bubbles on 
 the OMR form.

It seems to me that this calls for a page description 
language, like PostScript of PDF.  However maybe you
could make a LaTeX picture that matches your page size.
Text and drawings can be placed extremely precisely in
a picture.

Cheers,
Alan Isaac





Re: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to that
since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as long as
you have python installed on your system, it will run.

  However, the output is not what I expected. I think it's really a Python
issue, not a LaTeX issue, so I've asked the local python geeks for help.
But, since I started this thread I thought to keep you all informed of
progress.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863#!/usr/bin/env python

import os, sys, config

preamb = """
  \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}
  
  """

ending = """\end{document}"""
  
def econPairs():
  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")]


  ratingHead = """Importance   
Value   Definition
   """

  ratingTab = """1   Equal importance
 3   Weak importance of one over the other
 5   Strong importance of one over the other
 7   Demonstrated importance of one over the other
 9   Absolute importance of one over the other
2, 4, 6, 8   Intermediate values between the two adjacent 
definitions
"""

  instructPara = """Using the table below, determine your preference for either 
the first
item of the pair (on the left), or the second (on the 
right). Use the
rating table to determine the strength of your preference, 
then fully
fill in the rectangle for that preference strength on the 
same line as
the component pairs. If you prefer the second more than the 
first,
also completely fill in the last box on the right."""

  title = "Economic Components"

  out = open('omrPairs.tex', 'w')
  out.write(preamb)

  out.write(title)
  out.write("""\vspace{6cm}""")   # space below title to line up first line 
with OMR form

  out.write('Fill in the box under \'Economic\' on this line -->')
  out.write("""vspace{1.5cm}""")
  out.write('Record your position on the project here -->')
  out.write("""\vspace{3cm}""")

  for left,right in pairData:
out.write(left)
out.write("""\hspace{3cm}""")
out.write(right)

  out.write(ending)
  out.close()

if __name__ == "__main__":
  econPairs()


Re[2]: Creating a Document Programmatically

2008-04-03 Thread Alan G Isaac
1. You need to use raw strings or double your backslashes.

2. Probably you should use LaTeX tables.

Cheers,
Alan Isaac





Re[2]: Creating a Document Programmatically

2008-04-03 Thread Rich Shepard

On Thu, 3 Apr 2008, Alan G Isaac wrote:


1. You need to use raw strings or double your backslashes.


Alan,

  Yes, doubling the backslashes worked.


2. Probably you should use LaTeX tables.


  I'll probably get to this for some of the reports. But, on this one the
text strings need to be aligned with bubbles on an OMR form. So I need to
tweak the horizontal and vertical spacings to get it all lined up
appropriately.

  BTW, I tried using PyX for this but didn't find enough information in the
docs to feel confident that I could.

Thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


[OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Dov Feldstern

Rich Shepard wrote:

On Tue, 25 Mar 2008, Rich Shepard wrote:


 Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file.


  After learning PyX (Python wrapper for TeX/LaTeX primarily for graphics),
and trying to use it to write the reports, I'm back to embedding LaTeX
markup in Python comments. Risking public humiliation (Hey! I'm used to 
that

since I testify at all sorts of government hearings.), I'm posting my first
abortive attempt to learn how to do the job. Small file attached; as 
long as

you have python installed on your system, it will run.


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.


Enjoy!
Dov


Re: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Rich Shepard

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.

  The sample code I posted needs to be placed precisely on the page so the
pairs are aligned with a row of bubbles on the OMR form.

  Other reports need to incorporate plots with the text. Perhaps Cheetah
_could_ do this, but the learning curve and attempts to bend it to our needs
would consume the time it would take me to hand write the LaTeX code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


Re[2]: [OT] templating latex (was: Re: Creating a Document Programmatically)

2008-04-03 Thread Alan G Isaac
On Thu, 3 Apr 2008, Rich Shepard apparently wrote:
> The sample code I posted needs to be placed precisely on 
> the page so the pairs are aligned with a row of bubbles on 
> the OMR form.

It seems to me that this calls for a page description 
language, like PostScript of PDF.  However maybe you
could make a LaTeX picture that matches your page size.
Text and drawings can be placed extremely precisely in
a picture.

Cheers,
Alan Isaac





Re: Creating a Document Programmatically

2008-03-31 Thread G. Milde
On 25.03.08, Rich Shepard wrote:

   Many moons ago I asked for opinions on using LaTeX as a report tool for a
 python application (a mathematical model, to be more precise)
...
   Has anyone done this? 

You might have a look, if pyreport is what you want:

  http://gael-varoquaux.info/computers/pyreport/
  
it lets you embed code to produce reports (or documentation) in your python
scripts.

Guenter  
  
  


Re: Creating a Document Programmatically

2008-03-31 Thread G. Milde
On 25.03.08, Rich Shepard wrote:

   Many moons ago I asked for opinions on using LaTeX as a report tool for a
 python application (a mathematical model, to be more precise)
...
   Has anyone done this? 

You might have a look, if pyreport is what you want:

  http://gael-varoquaux.info/computers/pyreport/
  
it lets you embed code to produce reports (or documentation) in your python
scripts.

Guenter  
  
  


Re: Creating a Document Programmatically

2008-03-31 Thread G. Milde
On 25.03.08, Rich Shepard wrote:

>   Many moons ago I asked for opinions on using LaTeX as a report tool for a
> python application (a mathematical model, to be more precise)
...
>   Has anyone done this? 

You might have a look, if pyreport is what you want:

  http://gael-varoquaux.info/computers/pyreport/
  
it lets you embed code to produce reports (or documentation) in your python
scripts.

Guenter  
  
  


Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, John wrote:


Not directly related to your task but ... Some years ago I used perl to
satisfy the need for an Insurance Co to write standard letters to a client
in processing claims, renewals, etc of policies. This was a challenge
because the amount of interpolated comment was derived from a database and
was unpredictable in size.


John,

  I've been working with ReportLab, a python library for database reporting.
Like LaTeX, it allows very fine control of placement of text on the page.
But, it is highly limited in the graphics it can handle ... only raster
images directly.

  After spending a long time -- too much time, IMO -- with ReportLab and
Matplotlib (plotting library based on MatLab) and not getting the results we
need, it became time to look for alternatives.

  There are two main reports from the approximate reasoning model: the input
variables and a detailed, step-by-step log of each model run. Neither is in
the realm of a database report writing tool (such as ReportLab), and the
data plots we need turn out to be much easier -- and better results -- using
PyX rather than mpl (nice .eps or .pdf with LaTeX handling of all text and
math). The data come from lists of tuples, not directly from the database
tables.


One of the difficulties with Python I foresee are that its reliance on
indentation might be broken by LyX collapsing consecutive spaces.


  After years of C I'm still bothered by Python's use of indentation to
delimit code blocks. Particularly when it's anally obsessive where comments
start.


So my advice. Do it with LyX rather than LaTeX. It makes it easier to play
with your output file using LyX rather than attacking .tex file with vi.


  What I intend to do is use the Python free-form comment delimiter ( ...
) to write the preamble and other multiline code, and the rest as
embedded strings. Using open(), write(), and close() I'll get a .tex file on
disk, then spawn a shell to execute a script to run latex-dvips-ps2pdf.

  Oh, I don't use vi and its children; strictly an emacs user. There's a
reason I don't like vi, but that's a long story for another forum.

Many thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Steve Litt
On Wednesday 26 March 2008 09:50, Rich Shepard wrote:

What I intend to do is use the Python free-form comment delimiter (
 ... ) to write the preamble and other multiline code, and the rest as
 embedded strings. Using open(), write(), and close() I'll get a .tex file
 on disk, then spawn a shell to execute a script to run
 latex-dvips-ps2pdf.

Why not put the preamble and other multiline code in one or more separate text 
files. Those things are data, not code. That way you or your assistant can 
change the preamble without changing the Python program and its indentation.

Once again, I'd recommend placing the entire template for the report in a LyX 
or LaTeX or TeX file, and within that template have placeholders which the 
Python program will replace with strings derived from data content. It would 
be quick, easy, clean, and very modifiable.

SteveT

Steve Litt
Books written in LyX:
Troubleshooting Techniques of the Successful Technologist
Twenty Eight Tales of Troubleshooting
Troubleshooting: Just the Facts


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
Sounds like you should consider docutils with 
reStructuredText.  This produces PDF via LaTeX.
(If you need math in your text, say so, and
I'll explain how it's done.)

Cheers,
Alan Isaac






Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Steve Litt wrote:


Why not put the preamble and other multiline code in one or more separate
text files. Those things are data, not code. That way you or your
assistant can change the preamble without changing the Python program and
its indentation.


Steve,

  Nothing to change that affects indentation. It's analogous to embedding
sql code in a Python docstring; for example,

 On Insert of a component 
stmt1 = CREATE TRIGGER fki_comp_cat
   BEFORE INSERT ON component
   FOR EACH ROW
   BEGIN
 SELECT CASE
   WHEN NEW.comp_cat IS NOT NULL AND
   (SELECT cat_name FROM category
WHERE cat_name = NEW.comp_cat) IS NULL
THEN RAISE(ROLLBACK, 'insert on table category violates
foreign key constraint fk_comp_cat')
 END
   END
 
self.cur.execute(stmt1)

  Writing the preamble lets me write it to the open file in a single
statement. And, everything's in a single module.


Once again, I'd recommend placing the entire template for the report in a
LyX or LaTeX or TeX file, and within that template have placeholders which
the Python program will replace with strings derived from data content. It
would be quick, easy, clean, and very modifiable.


  Perhaps. I suspect that it will be easier to read, understand, and debug
when the LaTeX and text flow within the code as they are needed/generated.
For example, what I now have starts with,

  def inputVals(self):
Title = self.rptinfo

# General Model Information. This goes on the top of the first page.
stmtA = SELECT proj_name, proj_desc, model_type, proj_owner,
   proj_location, proj_state, lead_agency, keName from
   Project
self.appData.cur.execute(stmtA)
projData = self.appData.cur.fetchall()
strings_tuple = projData[0]

labName = ['Name: ', 'Description: ', 'Model Type: ', 'Owner: ',
   'Location: ', 'State: ', 'Lead Agency: ',
   'Knowledge Engineers: ']

self.pg = canvas.Canvas('input_variables.pdf', pagesize=LETTER)

self.pg.setFont('Helvetica-Bold',14)

self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-180,Title)
self.pg.setFont('Helvetica-Oblique',11)


self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-198,self.ts)

  So the LaTeX code replaces the ReportLab code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Alan Isaac wrote:


Sounds like you should consider docutils with reStructuredText. This
produces PDF via LaTeX. (If you need math in your text, say so, and I'll
explain how it's done.)


Alan,

  Fancy meeting you here! :-) LyX mail list, PyX mail list, ... wonder to
how many others we're both subscribed.

  Don't need math, per se, in the text. But I do need data plots. I'm
re-writing the matplotlib code and need to integrate the output into the
report document.

  I'll look into docutils and reStructuredText.

Thank you,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
On Wed, 26 Mar 2008, Rich Shepard wrote:
 After looking at the docutils page on sourceforge.net, 
 I don't think that's what I want. I'm not trying to 
 produce program documentation, but the inputs and outputs 
 of a mathematical model whose UI and some code are written 
 in Python 

Take a look at this:
URL:http://docutils.sourceforge.net/rst.html
URL:http://docutils.sourceforge.net/docs/user/rst/quickref.html

reStructuredText is a super simple markup language.
It has an ``include`` directive.
So you can layout the basic document structure
and then simply include programmatically produced
sections.  It also has directives for including
graphics.

Output is produced with writers.
There are two simple scripts,
rst2html.py and rst2latex.py,
that may interest you.

So the process could work like this:

- create a shell for you report,
  comprising the stuff that does not change
- use the include directive to indicate
  inclusion of generated content
- use the ``image`` directive to indicate
  image files for inclusion (e.g., PDF
  figures)
- run rst2latex.py on your file to produce
  the equivalent LaTeX document
- process the LaTeX to PDF as usual

reStructuredText has only modest support for
citations, but it can be supplemented by
bibstuff if you have serious citation needs.

hth,
Alan Isaac

PS Make sure you look at ``rst2latex.py --help``
since there are some very useful options.






Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, John wrote:


Not directly related to your task but ... Some years ago I used perl to
satisfy the need for an Insurance Co to write standard letters to a client
in processing claims, renewals, etc of policies. This was a challenge
because the amount of interpolated comment was derived from a database and
was unpredictable in size.


John,

  I've been working with ReportLab, a python library for database reporting.
Like LaTeX, it allows very fine control of placement of text on the page.
But, it is highly limited in the graphics it can handle ... only raster
images directly.

  After spending a long time -- too much time, IMO -- with ReportLab and
Matplotlib (plotting library based on MatLab) and not getting the results we
need, it became time to look for alternatives.

  There are two main reports from the approximate reasoning model: the input
variables and a detailed, step-by-step log of each model run. Neither is in
the realm of a database report writing tool (such as ReportLab), and the
data plots we need turn out to be much easier -- and better results -- using
PyX rather than mpl (nice .eps or .pdf with LaTeX handling of all text and
math). The data come from lists of tuples, not directly from the database
tables.


One of the difficulties with Python I foresee are that its reliance on
indentation might be broken by LyX collapsing consecutive spaces.


  After years of C I'm still bothered by Python's use of indentation to
delimit code blocks. Particularly when it's anally obsessive where comments
start.


So my advice. Do it with LyX rather than LaTeX. It makes it easier to play
with your output file using LyX rather than attacking .tex file with vi.


  What I intend to do is use the Python free-form comment delimiter ( ...
) to write the preamble and other multiline code, and the rest as
embedded strings. Using open(), write(), and close() I'll get a .tex file on
disk, then spawn a shell to execute a script to run latex-dvips-ps2pdf.

  Oh, I don't use vi and its children; strictly an emacs user. There's a
reason I don't like vi, but that's a long story for another forum.

Many thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Steve Litt
On Wednesday 26 March 2008 09:50, Rich Shepard wrote:

What I intend to do is use the Python free-form comment delimiter (
 ... ) to write the preamble and other multiline code, and the rest as
 embedded strings. Using open(), write(), and close() I'll get a .tex file
 on disk, then spawn a shell to execute a script to run
 latex-dvips-ps2pdf.

Why not put the preamble and other multiline code in one or more separate text 
files. Those things are data, not code. That way you or your assistant can 
change the preamble without changing the Python program and its indentation.

Once again, I'd recommend placing the entire template for the report in a LyX 
or LaTeX or TeX file, and within that template have placeholders which the 
Python program will replace with strings derived from data content. It would 
be quick, easy, clean, and very modifiable.

SteveT

Steve Litt
Books written in LyX:
Troubleshooting Techniques of the Successful Technologist
Twenty Eight Tales of Troubleshooting
Troubleshooting: Just the Facts


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
Sounds like you should consider docutils with 
reStructuredText.  This produces PDF via LaTeX.
(If you need math in your text, say so, and
I'll explain how it's done.)

Cheers,
Alan Isaac






Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Steve Litt wrote:


Why not put the preamble and other multiline code in one or more separate
text files. Those things are data, not code. That way you or your
assistant can change the preamble without changing the Python program and
its indentation.


Steve,

  Nothing to change that affects indentation. It's analogous to embedding
sql code in a Python docstring; for example,

 On Insert of a component 
stmt1 = CREATE TRIGGER fki_comp_cat
   BEFORE INSERT ON component
   FOR EACH ROW
   BEGIN
 SELECT CASE
   WHEN NEW.comp_cat IS NOT NULL AND
   (SELECT cat_name FROM category
WHERE cat_name = NEW.comp_cat) IS NULL
THEN RAISE(ROLLBACK, 'insert on table category violates
foreign key constraint fk_comp_cat')
 END
   END
 
self.cur.execute(stmt1)

  Writing the preamble lets me write it to the open file in a single
statement. And, everything's in a single module.


Once again, I'd recommend placing the entire template for the report in a
LyX or LaTeX or TeX file, and within that template have placeholders which
the Python program will replace with strings derived from data content. It
would be quick, easy, clean, and very modifiable.


  Perhaps. I suspect that it will be easier to read, understand, and debug
when the LaTeX and text flow within the code as they are needed/generated.
For example, what I now have starts with,

  def inputVals(self):
Title = self.rptinfo

# General Model Information. This goes on the top of the first page.
stmtA = SELECT proj_name, proj_desc, model_type, proj_owner,
   proj_location, proj_state, lead_agency, keName from
   Project
self.appData.cur.execute(stmtA)
projData = self.appData.cur.fetchall()
strings_tuple = projData[0]

labName = ['Name: ', 'Description: ', 'Model Type: ', 'Owner: ',
   'Location: ', 'State: ', 'Lead Agency: ',
   'Knowledge Engineers: ']

self.pg = canvas.Canvas('input_variables.pdf', pagesize=LETTER)

self.pg.setFont('Helvetica-Bold',14)

self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-180,Title)
self.pg.setFont('Helvetica-Oblique',11)


self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-198,self.ts)

  So the LaTeX code replaces the ReportLab code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Alan Isaac wrote:


Sounds like you should consider docutils with reStructuredText. This
produces PDF via LaTeX. (If you need math in your text, say so, and I'll
explain how it's done.)


Alan,

  Fancy meeting you here! :-) LyX mail list, PyX mail list, ... wonder to
how many others we're both subscribed.

  Don't need math, per se, in the text. But I do need data plots. I'm
re-writing the matplotlib code and need to integrate the output into the
report document.

  I'll look into docutils and reStructuredText.

Thank you,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
On Wed, 26 Mar 2008, Rich Shepard wrote:
 After looking at the docutils page on sourceforge.net, 
 I don't think that's what I want. I'm not trying to 
 produce program documentation, but the inputs and outputs 
 of a mathematical model whose UI and some code are written 
 in Python 

Take a look at this:
URL:http://docutils.sourceforge.net/rst.html
URL:http://docutils.sourceforge.net/docs/user/rst/quickref.html

reStructuredText is a super simple markup language.
It has an ``include`` directive.
So you can layout the basic document structure
and then simply include programmatically produced
sections.  It also has directives for including
graphics.

Output is produced with writers.
There are two simple scripts,
rst2html.py and rst2latex.py,
that may interest you.

So the process could work like this:

- create a shell for you report,
  comprising the stuff that does not change
- use the include directive to indicate
  inclusion of generated content
- use the ``image`` directive to indicate
  image files for inclusion (e.g., PDF
  figures)
- run rst2latex.py on your file to produce
  the equivalent LaTeX document
- process the LaTeX to PDF as usual

reStructuredText has only modest support for
citations, but it can be supplemented by
bibstuff if you have serious citation needs.

hth,
Alan Isaac

PS Make sure you look at ``rst2latex.py --help``
since there are some very useful options.






Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, John wrote:


Not directly related to your task but ... Some years ago I used perl to
satisfy the need for an Insurance Co to write standard letters to a client
in processing claims, renewals, etc of policies. This was a challenge
because the amount of interpolated comment was derived from a database and
was unpredictable in size.


John,

  I've been working with ReportLab, a python library for database reporting.
Like LaTeX, it allows very fine control of placement of text on the page.
But, it is highly limited in the graphics it can handle ... only raster
images directly.

  After spending a long time -- too much time, IMO -- with ReportLab and
Matplotlib (plotting library based on MatLab) and not getting the results we
need, it became time to look for alternatives.

  There are two main reports from the approximate reasoning model: the input
variables and a detailed, step-by-step log of each model run. Neither is in
the realm of a database report writing tool (such as ReportLab), and the
data plots we need turn out to be much easier -- and better results -- using
PyX rather than mpl (nice .eps or .pdf with LaTeX handling of all text and
math). The data come from lists of tuples, not directly from the database
tables.


One of the difficulties with Python I foresee are that its reliance on
indentation might be broken by LyX collapsing consecutive spaces.


  After years of C I'm still bothered by Python's use of indentation to
delimit code blocks. Particularly when it's anally obsessive where comments
start.


So my advice. Do it with LyX rather than LaTeX. It makes it easier to play
with your output file using LyX rather than attacking .tex file with vi.


  What I intend to do is use the Python free-form comment delimiter (""" ...
""") to write the preamble and other multiline code, and the rest as
embedded strings. Using open(), write(), and close() I'll get a .tex file on
disk, then spawn a shell to execute a script to run latex->dvips->ps2pdf.

  Oh, I don't use vi and its children; strictly an emacs user. There's a
reason I don't like vi, but that's a long story for another forum.

Many thanks,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Steve Litt
On Wednesday 26 March 2008 09:50, Rich Shepard wrote:

>What I intend to do is use the Python free-form comment delimiter ("""
> ... """) to write the preamble and other multiline code, and the rest as
> embedded strings. Using open(), write(), and close() I'll get a .tex file
> on disk, then spawn a shell to execute a script to run
> latex->dvips->ps2pdf.

Why not put the preamble and other multiline code in one or more separate text 
files. Those things are data, not code. That way you or your assistant can 
change the preamble without changing the Python program and its indentation.

Once again, I'd recommend placing the entire template for the report in a LyX 
or LaTeX or TeX file, and within that template have placeholders which the 
Python program will replace with strings derived from data content. It would 
be quick, easy, clean, and very modifiable.

SteveT

Steve Litt
Books written in LyX:
Troubleshooting Techniques of the Successful Technologist
Twenty Eight Tales of Troubleshooting
Troubleshooting: Just the Facts


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
Sounds like you should consider docutils with 
reStructuredText.  This produces PDF via LaTeX.
(If you need math in your text, say so, and
I'll explain how it's done.)

Cheers,
Alan Isaac






Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Steve Litt wrote:


Why not put the preamble and other multiline code in one or more separate
text files. Those things are data, not code. That way you or your
assistant can change the preamble without changing the Python program and
its indentation.


Steve,

  Nothing to change that affects indentation. It's analogous to embedding
sql code in a Python docstring; for example,

""" On Insert of a component """
stmt1 = """CREATE TRIGGER fki_comp_cat
   BEFORE INSERT ON component
   FOR EACH ROW
   BEGIN
 SELECT CASE
   WHEN NEW.comp_cat IS NOT NULL AND
   (SELECT cat_name FROM category
WHERE cat_name = NEW.comp_cat) IS NULL
THEN RAISE(ROLLBACK, 'insert on table category violates
foreign key constraint fk_comp_cat')
 END
   END
 """
self.cur.execute(stmt1)

  Writing the preamble lets me write it to the open file in a single
statement. And, everything's in a single module.


Once again, I'd recommend placing the entire template for the report in a
LyX or LaTeX or TeX file, and within that template have placeholders which
the Python program will replace with strings derived from data content. It
would be quick, easy, clean, and very modifiable.


  Perhaps. I suspect that it will be easier to read, understand, and debug
when the LaTeX and text flow within the code as they are needed/generated.
For example, what I now have starts with,

  def inputVals(self):
Title = self.rptinfo

# General Model Information. This goes on the top of the first page.
stmtA = """SELECT proj_name, proj_desc, model_type, proj_owner,
   proj_location, proj_state, lead_agency, keName from
   Project"""
self.appData.cur.execute(stmtA)
projData = self.appData.cur.fetchall()
strings_tuple = projData[0]

labName = ['Name: ', 'Description: ', 'Model Type: ', 'Owner: ',
   'Location: ', 'State: ', 'Lead Agency: ',
   'Knowledge Engineers: ']

self.pg = canvas.Canvas('input_variables.pdf', pagesize=LETTER)

self.pg.setFont('Helvetica-Bold',14)

self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-180,Title)
self.pg.setFont('Helvetica-Oblique',11)


self.pg.drawCentredString(self.PAGE_SIZE[0]/2.0,self.PAGE_SIZE[1]-198,self.ts)

  So the LaTeX code replaces the ReportLab code.

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Rich Shepard

On Wed, 26 Mar 2008, Alan Isaac wrote:


Sounds like you should consider docutils with reStructuredText. This
produces PDF via LaTeX. (If you need math in your text, say so, and I'll
explain how it's done.)


Alan,

  Fancy meeting you here! :-) LyX mail list, PyX mail list, ... wonder to
how many others we're both subscribed.

  Don't need math, per se, in the text. But I do need data plots. I'm
re-writing the matplotlib code and need to integrate the output into the
report document.

  I'll look into docutils and reStructuredText.

Thank you,

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-26 Thread Alan Isaac
On Wed, 26 Mar 2008, Rich Shepard wrote:
> After looking at the docutils page on sourceforge.net, 
> I don't think that's what I want. I'm not trying to 
> produce program documentation, but the inputs and outputs 
> of a mathematical model whose UI and some code are written 
> in Python 

Take a look at this:



reStructuredText is a super simple markup language.
It has an ``include`` directive.
So you can layout the basic document structure
and then simply include programmatically produced
sections.  It also has directives for including
graphics.

Output is produced with writers.
There are two simple scripts,
rst2html.py and rst2latex.py,
that may interest you.

So the process could work like this:

- create a "shell" for you report,
  comprising the stuff that does not change
- use the include directive to indicate
  inclusion of generated content
- use the ``image`` directive to indicate
  image files for inclusion (e.g., PDF
  figures)
- run rst2latex.py on your file to produce
  the equivalent LaTeX document
- process the LaTeX to PDF as usual

reStructuredText has only modest support for
citations, but it can be supplemented by
bibstuff if you have serious citation needs.

hth,
Alan Isaac

PS Make sure you look at ``rst2latex.py --help``
since there are some very useful options.






Creating a Document Programmatically

2008-03-25 Thread Rich Shepard

  This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)

  Many moons ago I asked for opinions on using LaTeX as a report tool for a
python application (a mathematical model, to be more precise), and finally
decided that ReportLab would be the better solution. However, having learned
RL and started using it, I see the shortcomings. For the record, there are
two that concern me: 1) a very limited set of built-in PostScript fonts and
2) graphics support that is primarily bit-mapped and not vector based. The
former means using Times (ugly, IMNSHO) and the latter means writing .pdf
files of plots, then appending them to the rear of the generated ReportLab
document. RL is really good as a database report writer, but that's not
really how I'm using it.

  It occurred to me this afternoon that I can write a LaTeX doc preamble and
save it as a python string, wrap what I want written to the report in LaTeX
markup (pre-written strings), generate the plots as .eps files, then
programmatically call latex, dvips, and ps2pdf when the reports are
finished. Probably the report class would be most appropriate.

  Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file. The output
would look good, and I'd have a lot of flexibility in structuring the
reports.

Thoughts?

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-25 Thread John
On Wednesday 26 March 2008 03:58:47 pm Rich Shepard wrote:
This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)

Many moons ago I asked for opinions on using LaTeX as a report tool for
 a python application (a mathematical model, to be more precise), and
 finally decided that ReportLab would be the better solution. However,
 having learned RL and started using it, I see the shortcomings. For the
 record, there are two that concern me: 1) a very limited set of built-in
 PostScript fonts and 2) graphics support that is primarily bit-mapped and
 not vector based. The former means using Times (ugly, IMNSHO) and the
 latter means writing .pdf files of plots, then appending them to the rear
 of the generated ReportLab document. RL is really good as a database report
 writer, but that's not really how I'm using it.

It occurred to me this afternoon that I can write a LaTeX doc preamble
 and save it as a python string, wrap what I want written to the report in
 LaTeX markup (pre-written strings), generate the plots as .eps files, then
 programmatically call latex, dvips, and ps2pdf when the reports are
 finished. Probably the report class would be most appropriate.

Has anyone done this? Our model is written in Python, so we can use the
 open() and write() methods to squirt strings to a disk file. The output
 would look good, and I'd have a lot of flexibility in structuring the
 reports.
Not directly related to your task but ...
Some years ago I used perl to satisfy the need for an Insurance Co to write 
standard letters to a client in processing claims, renewals, etc of policies.
This was a challenge because the amount of interpolated comment was derived 
from a database and was unpredictable in size.

My approach was to create a LyX template with PERL { ...  } pieces in the text 
and ${colname} expressions interspersed in the appropriate places.
When the user created a new standard letter, (s)he ran a merge command which 
basically supplied a list of database records, and the LyX filename to a perl 
program which read the database record (which was a set of variable 
assignments of the form ${firstname}='John' ) and replaced the ${tags} with 
the data.  When it encountered a PERL tag it executed the {} delimited perl 
code and fed its output into the final LyX file. For example, the PERL 
statements might be {LyxTable(select * from claims where client=$client)}
The perl library function (written by me) would output LyX source for a table 
holding the rows of data).
No doubt a future upgrade of LyX will break this code (because of changes to 
the underlying table structure of LyX documents). This has already happened 
once when LyX changed to the semi-xml format they now use. But I will cope.

The perl script produced an instance of the standard letter for each database 
record all in a single file.
 The merge program also executed PERL command embedded in the LyX template to 
produce things like tables of covers, or payment installments etc. For these 
I used the perl access functions provides with LyX and added my own by 
reverse engineering LyX tables.
It all works brilliantly. I used perl because I knew it, and also because its 
use of $name made it easy for perl to read interpret and write a file.
The output is truly impressive - beautifully typeset regardless of variations 
in the interpolated content including tables of data.
This mechanism allows the users to alter the LyX template as their 
requirements change without breaking the merge capabilities (provided they 
don't mess up the perl interpolations).

No doubt the same sort of thing can be done with Python. 
One of the difficulties with Python I foresee are that its reliance on 
indentation might be broken by LyX collapsing consecutive spaces.
So you would need to have the tail wag the dog. The python program would have 
to be the master and hold the LyX components of the documents for melding in 
with your generated report matter.

So my advice. Do it with LyX rather than LaTeX. It makes it easier to play 
with your output file using LyX rather than attacking .tex file with vi.
regards
John O'Gorman

 Thoughts?

 Rich




Creating a Document Programmatically

2008-03-25 Thread Rich Shepard

  This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)

  Many moons ago I asked for opinions on using LaTeX as a report tool for a
python application (a mathematical model, to be more precise), and finally
decided that ReportLab would be the better solution. However, having learned
RL and started using it, I see the shortcomings. For the record, there are
two that concern me: 1) a very limited set of built-in PostScript fonts and
2) graphics support that is primarily bit-mapped and not vector based. The
former means using Times (ugly, IMNSHO) and the latter means writing .pdf
files of plots, then appending them to the rear of the generated ReportLab
document. RL is really good as a database report writer, but that's not
really how I'm using it.

  It occurred to me this afternoon that I can write a LaTeX doc preamble and
save it as a python string, wrap what I want written to the report in LaTeX
markup (pre-written strings), generate the plots as .eps files, then
programmatically call latex, dvips, and ps2pdf when the reports are
finished. Probably the report class would be most appropriate.

  Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file. The output
would look good, and I'd have a lot of flexibility in structuring the
reports.

Thoughts?

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
http://www.appl-ecosys.com Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-25 Thread John
On Wednesday 26 March 2008 03:58:47 pm Rich Shepard wrote:
This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)

Many moons ago I asked for opinions on using LaTeX as a report tool for
 a python application (a mathematical model, to be more precise), and
 finally decided that ReportLab would be the better solution. However,
 having learned RL and started using it, I see the shortcomings. For the
 record, there are two that concern me: 1) a very limited set of built-in
 PostScript fonts and 2) graphics support that is primarily bit-mapped and
 not vector based. The former means using Times (ugly, IMNSHO) and the
 latter means writing .pdf files of plots, then appending them to the rear
 of the generated ReportLab document. RL is really good as a database report
 writer, but that's not really how I'm using it.

It occurred to me this afternoon that I can write a LaTeX doc preamble
 and save it as a python string, wrap what I want written to the report in
 LaTeX markup (pre-written strings), generate the plots as .eps files, then
 programmatically call latex, dvips, and ps2pdf when the reports are
 finished. Probably the report class would be most appropriate.

Has anyone done this? Our model is written in Python, so we can use the
 open() and write() methods to squirt strings to a disk file. The output
 would look good, and I'd have a lot of flexibility in structuring the
 reports.
Not directly related to your task but ...
Some years ago I used perl to satisfy the need for an Insurance Co to write 
standard letters to a client in processing claims, renewals, etc of policies.
This was a challenge because the amount of interpolated comment was derived 
from a database and was unpredictable in size.

My approach was to create a LyX template with PERL { ...  } pieces in the text 
and ${colname} expressions interspersed in the appropriate places.
When the user created a new standard letter, (s)he ran a merge command which 
basically supplied a list of database records, and the LyX filename to a perl 
program which read the database record (which was a set of variable 
assignments of the form ${firstname}='John' ) and replaced the ${tags} with 
the data.  When it encountered a PERL tag it executed the {} delimited perl 
code and fed its output into the final LyX file. For example, the PERL 
statements might be {LyxTable(select * from claims where client=$client)}
The perl library function (written by me) would output LyX source for a table 
holding the rows of data).
No doubt a future upgrade of LyX will break this code (because of changes to 
the underlying table structure of LyX documents). This has already happened 
once when LyX changed to the semi-xml format they now use. But I will cope.

The perl script produced an instance of the standard letter for each database 
record all in a single file.
 The merge program also executed PERL command embedded in the LyX template to 
produce things like tables of covers, or payment installments etc. For these 
I used the perl access functions provides with LyX and added my own by 
reverse engineering LyX tables.
It all works brilliantly. I used perl because I knew it, and also because its 
use of $name made it easy for perl to read interpret and write a file.
The output is truly impressive - beautifully typeset regardless of variations 
in the interpolated content including tables of data.
This mechanism allows the users to alter the LyX template as their 
requirements change without breaking the merge capabilities (provided they 
don't mess up the perl interpolations).

No doubt the same sort of thing can be done with Python. 
One of the difficulties with Python I foresee are that its reliance on 
indentation might be broken by LyX collapsing consecutive spaces.
So you would need to have the tail wag the dog. The python program would have 
to be the master and hold the LyX components of the documents for melding in 
with your generated report matter.

So my advice. Do it with LyX rather than LaTeX. It makes it easier to play 
with your output file using LyX rather than attacking .tex file with vi.
regards
John O'Gorman

 Thoughts?

 Rich




Creating a Document Programmatically

2008-03-25 Thread Rich Shepard

  This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)

  Many moons ago I asked for opinions on using LaTeX as a report tool for a
python application (a mathematical model, to be more precise), and finally
decided that ReportLab would be the better solution. However, having learned
RL and started using it, I see the shortcomings. For the record, there are
two that concern me: 1) a very limited set of built-in PostScript fonts and
2) graphics support that is primarily bit-mapped and not vector based. The
former means using Times (ugly, IMNSHO) and the latter means writing .pdf
files of plots, then appending them to the rear of the generated ReportLab
document. RL is really good as a database report writer, but that's not
really how I'm using it.

  It occurred to me this afternoon that I can write a LaTeX doc preamble and
save it as a python string, wrap what I want written to the report in LaTeX
markup (pre-written strings), generate the plots as .eps files, then
programmatically call latex, dvips, and ps2pdf when the reports are
finished. Probably the report class would be most appropriate.

  Has anyone done this? Our model is written in Python, so we can use the
open() and write() methods to squirt strings to a disk file. The output
would look good, and I'd have a lot of flexibility in structuring the
reports.

Thoughts?

Rich

--
Richard B. Shepard, Ph.D.   |  IntegrityCredibility
Applied Ecosystem Services, Inc.|Innovation
 Voice: 503-667-4517  Fax: 503-667-8863


Re: Creating a Document Programmatically

2008-03-25 Thread John
On Wednesday 26 March 2008 03:58:47 pm Rich Shepard wrote:
>This is not specifically LyX, but LaTeX. I ask for your indulgence. :-)
>
>Many moons ago I asked for opinions on using LaTeX as a report tool for
> a python application (a mathematical model, to be more precise), and
> finally decided that ReportLab would be the better solution. However,
> having learned RL and started using it, I see the shortcomings. For the
> record, there are two that concern me: 1) a very limited set of built-in
> PostScript fonts and 2) graphics support that is primarily bit-mapped and
> not vector based. The former means using Times (ugly, IMNSHO) and the
> latter means writing .pdf files of plots, then appending them to the rear
> of the generated ReportLab document. RL is really good as a database report
> writer, but that's not really how I'm using it.
>
>It occurred to me this afternoon that I can write a LaTeX doc preamble
> and save it as a python string, wrap what I want written to the report in
> LaTeX markup (pre-written strings), generate the plots as .eps files, then
> programmatically call latex, dvips, and ps2pdf when the reports are
> finished. Probably the report class would be most appropriate.
>
>Has anyone done this? Our model is written in Python, so we can use the
> open() and write() methods to squirt strings to a disk file. The output
> would look good, and I'd have a lot of flexibility in structuring the
> reports.
Not directly related to your task but ...
Some years ago I used perl to satisfy the need for an Insurance Co to write 
standard letters to a client in processing claims, renewals, etc of policies.
This was a challenge because the amount of interpolated comment was derived 
from a database and was unpredictable in size.

My approach was to create a LyX template with PERL { ...  } pieces in the text 
and ${colname} expressions interspersed in the appropriate places.
When the user created a new standard letter, (s)he ran a merge command which 
basically supplied a list of database records, and the LyX filename to a perl 
program which read the database record (which was a set of variable 
assignments of the form ${firstname}='John' ) and replaced the ${tags} with 
the data.  When it encountered a PERL tag it executed the {} delimited perl 
code and fed its output into the final LyX file. For example, the PERL 
statements might be {LyxTable("select * from claims where client=$client")}
The perl library function (written by me) would output LyX source for a table 
holding the rows of data).
No doubt a future upgrade of LyX will break this code (because of changes to 
the underlying table structure of LyX documents). This has already happened 
once when LyX changed to the semi-xml format they now use. But I will cope.

The perl script produced an instance of the standard letter for each database 
record all in a single file.
 The merge program also executed PERL command embedded in the LyX template to 
produce things like tables of covers, or payment installments etc. For these 
I used the perl access functions provides with LyX and added my own by 
reverse engineering LyX tables.
It all works brilliantly. I used perl because I knew it, and also because its 
use of $name made it easy for perl to read interpret and write a file.
The output is truly impressive - beautifully typeset regardless of variations 
in the interpolated content including tables of data.
This mechanism allows the users to alter the LyX template as their 
requirements change without breaking the merge capabilities (provided they 
don't mess up the perl interpolations).

No doubt the same sort of thing can be done with Python. 
One of the difficulties with Python I foresee are that its reliance on 
indentation might be broken by LyX collapsing consecutive spaces.
So you would need to have the tail wag the dog. The python program would have 
to be the master and hold the LyX components of the documents for melding in 
with your generated report matter.

So my advice. Do it with LyX rather than LaTeX. It makes it easier to play 
with your output file using LyX rather than attacking .tex file with vi.
regards
John O'Gorman
>
> Thoughts?
>
> Rich