Re: [OT] Programmatically Creating a LaTeX Document

2007-10-11 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  Expediency won: I can do the reports using ReportLab's table layout. Fewer
than two dozen lines of code, and I can fine-tune placement on the page,
have headers that are defined once and printed on each page, and meet our
needs.

  It's not a generic solution, but it fits the application's structure and
works for our purposes.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-11 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  Expediency won: I can do the reports using ReportLab's table layout. Fewer
than two dozen lines of code, and I can fine-tune placement on the page,
have headers that are defined once and printed on each page, and meet our
needs.

  It's not a generic solution, but it fits the application's structure and
works for our purposes.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-11 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  Expediency won: I can do the reports using ReportLab's table layout. Fewer
than two dozen lines of code, and I can fine-tune placement on the page,
have headers that are defined once and printed on each page, and meet our
needs.

  It's not a generic solution, but it fits the application's structure and
works for our purposes.

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


[OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 09:21 AM:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

Rich



I have done such a beast, therefore it can be done. :)
The method I used involved having a LaTeX file[1], which at an appropriate 
place[2] in the file, uses \input{MyVariableData.tex} and then when I want the 
data from a variable I just use \MyFirstVar at the appropriate place in the 
template file.


I had to be careful in my C program to properly escape LaTeX special chars 
before it wrote the data to MyVariableData.tex, i.e., at least _, * and 
\ become \_, {*} and \textbackslash{}.

There are probably others you need to look out for like %  @.

in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}




then with a script passing all the appropriate options to LaTeX, dvips (I 
needed PostScript output) and an rm of LaTeX temporary data, I have the 
program create the postscript for sending to the printer.



Hope this helps.


[1] a full LaTeX document which uses a lot stuff from \usepackage{ifthen} 
\usepackage{soul} \usepackage{pstricks} \usepackage{pst-text} 
\usepackage{pst-eps} \usepackage[dvips]{graphicx} \usepackage[dvips]{geometry}
I love the funky stuff you can do with LaTeX... like making CD labels with 
curved words on top of pictures.  I started from:

http://www.aldil.org/projets/TeX_cd_label.html

[2] appropriate from the perspective that you may need some packages defined 
before the variable file is pulled in, and you need to pull in the variable 
file before you try to use one of it's variables in the main LaTeX file.



--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter
http://www.crane.navy.mil/custfeedback


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


  Thank you, Todd!


I had to be careful in my C program to properly escape LaTeX special chars
before it wrote the data to MyVariableData.tex, i.e., at least _, *
and \ become \_, {*} and \textbackslash{}. There are probably
others you need to look out for like %  @.


  This should not be an issue in our model. The data are extracted from the
database to a Python list (or a list of tuples; analogous to a
two-dimensional array), and I can use indices to extract the strings and
numbers I want.

  There will be plots (created, no doubt, with PSTricks), to be included in
the audit log report of each run. So I expect the templates to be as
inclusive as your example.


in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}


  I do need to better learn programming in LaTeX; this project needs that
increased knowledge.


Hope this helps.


  Yes, it does.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Paul A. Rubin

Rich Shepard wrote:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?



I would write the template as an ordinary document (and of course would 
write it in LyX, then export to .tex), using some distinctive 
placeholders where the good stuff would be inserted (e.g., %%variable 
1%% or some such).  Then have a script create a copy of the .tex file 
(so as not to corrupt the master template) and use sed to substitute the 
good stuff for the placeholders.  Depending on what the good stuff looks 
like, you might have to escape a character here or there.


Or am I missing something fundamental here?

/Paul



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Ernesto Posse
Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


On 10/10/07, Rich Shepard [EMAIL PROTECTED] wrote:
 On Wed, 10 Oct 2007, Todd Denniston wrote:

  I have done such a beast, therefore it can be done. :)

Thank you, Todd!

  I had to be careful in my C program to properly escape LaTeX special chars
  before it wrote the data to MyVariableData.tex, i.e., at least _, *
  and \ become \_, {*} and \textbackslash{}. There are probably
  others you need to look out for like %  @.

This should not be an issue in our model. The data are extracted from the
 database to a Python list (or a list of tuples; analogous to a
 two-dimensional array), and I can use indices to extract the strings and
 numbers I want.

There will be plots (created, no doubt, with PSTricks), to be included in
 the audit log report of each run. So I expect the templates to be as
 inclusive as your example.

  in MyVariableData.tex there are lines of the form:
  \def\MyFirstVar{{*}Data{*} for Var\_1}

I do need to better learn programming in LaTeX; this project needs that
 increased knowledge.

  Hope this helps.

Yes, it does.

 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



-- 
Ernesto Posse
Modelling, Simulation and Design Lab - School of Computer Science
McGill University - Montreal, Quebec, Canada
url: http://moncs.cs.mcgill.ca/people/eposse


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive placeholders
where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.


Or am I missing something fundamental here?


  Honestly don't know at this time.

  I was expecting to find a Python library, because Python has libraries for
almost everything, but the PyTeX project apparently died 2-4 years ago.
Ideally, there would be the equivalent of, for example, pysqlite which is
the connection between Python code and the SQLite database (there are
equivalents for postgres and other dbms).

  How it would work or what it would need I've no idea now.

  But, you've contributed to the ideas, and that's a Good Thing(R). Many
thanks,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


  Thank you very much, Ernesto.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose.


  The example on that 'man' page suggests the path to ultimate happiness,
using the Python shell:


from string import Template
s = Template('$who likes $what')
s.substitute(who='tim', what='kung pao')

'tim likes kung pao'

  I think what might work is writing the LaTeX template as a series of print
statements (writing to an output file with the .tex extension), and using
the Template class to replace each variable as needed, before printing that
line to the output file, too.

  I'll play with this. It looks promising.

Thanks, all,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 12:09 PM:

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive 
placeholders

where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.



Almost, except I was using [La]TeX variables so that you do not have to modify 
the template file, just the variable defining file.


--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Steve Litt
On Wednesday 10 October 2007 13:16, Rich Shepard wrote:


I'll play with this. It looks promising.

Rich -- please share whatever your final solution with the list. I think most 
of us need to do this exact thing from time to time.

SteveT

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread William Adams

On Oct 10, 2007, at 12:15 PM, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


Me too!

My approach was a bit different though --- I templated a bunch of  
buttons using Runtime Revolution (a HyperCard clone) which were then  
output into a text file concatenated along w/ the content of various  
text fields. The commands either set the output, or re-defined other  
commands --- worked out quite nicely, allowing people to set  
telephone line ads w/ a fair bit of flexibility (the system was later  
up-dated to be server-driven w/ a .html JavaScript front-end).


William

--
William Adams
senior graphic designer
Fry Communications




Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  I will. I'll try both LaTeX and ReportLab and see which seems to be easier
to implement using one report as a test.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Daniel Lohmann



Rich Shepard schrieb:


  There will be plots (created, no doubt, with PSTricks), to be 
included in

the audit log report of each run. So I expect the templates to be as
inclusive as your example.


If you haven't worked with PSTricks so far (meaning that you have to 
learn something new anyway) you should also consider PGF/TikZ as a more 
modern alternative.


http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html

PGF is the graphics engine that is also internally used by LaTeX beamer; 
TikZ is the user-friendly layer on top of it. People who worked quite a 
lot with both told me that, compared to PSTricks, the TikZ syntax is way 
more consistent and in many cases more convenient (take a look at 
http://www.fauskes.net/pgftikzexamples/all/ for some examples). Some 
things that are possible with PSTricks (especially embedded postscript 
functions) are not available with PGF/TikZ, though.


The best thing, however, is that unlike PSTricks which work only with 
back-end processors that generate postscript code (dvips), TikZ works 
perfectly well with any major back-end processor, especially  pdfTeX / 
pdfLaTeX. (PDF has always been a kind of show-stopper for PSTricks.)


Daniel


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Daniel Lohmann wrote:


If you haven't worked with PSTricks so far (meaning that you have to learn
something new anyway) you should also consider PGF/TikZ as a more modern
alternative.


  Thanks, Daniel. I've used PSTricks some, but use Xfig most of the time. I
started to look at PGF/TikZ a few years ago when I started using the beamer
class, but never followed through.

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


[OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 09:21 AM:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

Rich



I have done such a beast, therefore it can be done. :)
The method I used involved having a LaTeX file[1], which at an appropriate 
place[2] in the file, uses \input{MyVariableData.tex} and then when I want the 
data from a variable I just use \MyFirstVar at the appropriate place in the 
template file.


I had to be careful in my C program to properly escape LaTeX special chars 
before it wrote the data to MyVariableData.tex, i.e., at least _, * and 
\ become \_, {*} and \textbackslash{}.

There are probably others you need to look out for like %  @.

in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}




then with a script passing all the appropriate options to LaTeX, dvips (I 
needed PostScript output) and an rm of LaTeX temporary data, I have the 
program create the postscript for sending to the printer.



Hope this helps.


[1] a full LaTeX document which uses a lot stuff from \usepackage{ifthen} 
\usepackage{soul} \usepackage{pstricks} \usepackage{pst-text} 
\usepackage{pst-eps} \usepackage[dvips]{graphicx} \usepackage[dvips]{geometry}
I love the funky stuff you can do with LaTeX... like making CD labels with 
curved words on top of pictures.  I started from:

http://www.aldil.org/projets/TeX_cd_label.html

[2] appropriate from the perspective that you may need some packages defined 
before the variable file is pulled in, and you need to pull in the variable 
file before you try to use one of it's variables in the main LaTeX file.



--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter
http://www.crane.navy.mil/custfeedback


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


  Thank you, Todd!


I had to be careful in my C program to properly escape LaTeX special chars
before it wrote the data to MyVariableData.tex, i.e., at least _, *
and \ become \_, {*} and \textbackslash{}. There are probably
others you need to look out for like %  @.


  This should not be an issue in our model. The data are extracted from the
database to a Python list (or a list of tuples; analogous to a
two-dimensional array), and I can use indices to extract the strings and
numbers I want.

  There will be plots (created, no doubt, with PSTricks), to be included in
the audit log report of each run. So I expect the templates to be as
inclusive as your example.


in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}


  I do need to better learn programming in LaTeX; this project needs that
increased knowledge.


Hope this helps.


  Yes, it does.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Paul A. Rubin

Rich Shepard wrote:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in Guide to LaTeX or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?



I would write the template as an ordinary document (and of course would 
write it in LyX, then export to .tex), using some distinctive 
placeholders where the good stuff would be inserted (e.g., %%variable 
1%% or some such).  Then have a script create a copy of the .tex file 
(so as not to corrupt the master template) and use sed to substitute the 
good stuff for the placeholders.  Depending on what the good stuff looks 
like, you might have to escape a character here or there.


Or am I missing something fundamental here?

/Paul



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Ernesto Posse
Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


On 10/10/07, Rich Shepard [EMAIL PROTECTED] wrote:
 On Wed, 10 Oct 2007, Todd Denniston wrote:

  I have done such a beast, therefore it can be done. :)

Thank you, Todd!

  I had to be careful in my C program to properly escape LaTeX special chars
  before it wrote the data to MyVariableData.tex, i.e., at least _, *
  and \ become \_, {*} and \textbackslash{}. There are probably
  others you need to look out for like %  @.

This should not be an issue in our model. The data are extracted from the
 database to a Python list (or a list of tuples; analogous to a
 two-dimensional array), and I can use indices to extract the strings and
 numbers I want.

There will be plots (created, no doubt, with PSTricks), to be included in
 the audit log report of each run. So I expect the templates to be as
 inclusive as your example.

  in MyVariableData.tex there are lines of the form:
  \def\MyFirstVar{{*}Data{*} for Var\_1}

I do need to better learn programming in LaTeX; this project needs that
 increased knowledge.

  Hope this helps.

Yes, it does.

 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



-- 
Ernesto Posse
Modelling, Simulation and Design Lab - School of Computer Science
McGill University - Montreal, Quebec, Canada
url: http://moncs.cs.mcgill.ca/people/eposse


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive placeholders
where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.


Or am I missing something fundamental here?


  Honestly don't know at this time.

  I was expecting to find a Python library, because Python has libraries for
almost everything, but the PyTeX project apparently died 2-4 years ago.
Ideally, there would be the equivalent of, for example, pysqlite which is
the connection between Python code and the SQLite database (there are
equivalents for postgres and other dbms).

  How it would work or what it would need I've no idea now.

  But, you've contributed to the ideas, and that's a Good Thing(R). Many
thanks,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


  Thank you very much, Ernesto.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose.


  The example on that 'man' page suggests the path to ultimate happiness,
using the Python shell:


from string import Template
s = Template('$who likes $what')
s.substitute(who='tim', what='kung pao')

'tim likes kung pao'

  I think what might work is writing the LaTeX template as a series of print
statements (writing to an output file with the .tex extension), and using
the Template class to replace each variable as needed, before printing that
line to the output file, too.

  I'll play with this. It looks promising.

Thanks, all,

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 12:09 PM:

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive 
placeholders

where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.



Almost, except I was using [La]TeX variables so that you do not have to modify 
the template file, just the variable defining file.


--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Steve Litt
On Wednesday 10 October 2007 13:16, Rich Shepard wrote:


I'll play with this. It looks promising.

Rich -- please share whatever your final solution with the list. I think most 
of us need to do this exact thing from time to time.

SteveT

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread William Adams

On Oct 10, 2007, at 12:15 PM, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


Me too!

My approach was a bit different though --- I templated a bunch of  
buttons using Runtime Revolution (a HyperCard clone) which were then  
output into a text file concatenated along w/ the content of various  
text fields. The commands either set the output, or re-defined other  
commands --- worked out quite nicely, allowing people to set  
telephone line ads w/ a fair bit of flexibility (the system was later  
up-dated to be server-driven w/ a .html JavaScript front-end).


William

--
William Adams
senior graphic designer
Fry Communications




Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  I will. I'll try both LaTeX and ReportLab and see which seems to be easier
to implement using one report as a test.

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Daniel Lohmann



Rich Shepard schrieb:


  There will be plots (created, no doubt, with PSTricks), to be 
included in

the audit log report of each run. So I expect the templates to be as
inclusive as your example.


If you haven't worked with PSTricks so far (meaning that you have to 
learn something new anyway) you should also consider PGF/TikZ as a more 
modern alternative.


http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html

PGF is the graphics engine that is also internally used by LaTeX beamer; 
TikZ is the user-friendly layer on top of it. People who worked quite a 
lot with both told me that, compared to PSTricks, the TikZ syntax is way 
more consistent and in many cases more convenient (take a look at 
http://www.fauskes.net/pgftikzexamples/all/ for some examples). Some 
things that are possible with PSTricks (especially embedded postscript 
functions) are not available with PGF/TikZ, though.


The best thing, however, is that unlike PSTricks which work only with 
back-end processors that generate postscript code (dvips), TikZ works 
perfectly well with any major back-end processor, especially  pdfTeX / 
pdfLaTeX. (PDF has always been a kind of show-stopper for PSTricks.)


Daniel


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Daniel Lohmann wrote:


If you haven't worked with PSTricks so far (meaning that you have to learn
something new anyway) you should also consider PGF/TikZ as a more modern
alternative.


  Thanks, Daniel. I've used PSTricks some, but use Xfig most of the time. I
started to look at PGF/TikZ a few years ago when I started using the beamer
class, but never followed through.

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


[OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in "Guide to LaTeX" or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 09:21 AM:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in "Guide to LaTeX" or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?

  Suggestions appreciated.

TIA,

Rich



I have done such a beast, therefore it can be done. :)
The method I used involved having a LaTeX file[1], which at an appropriate 
place[2] in the file, uses \input{MyVariableData.tex} and then when I want the 
data from a variable I just use \MyFirstVar at the appropriate place in the 
"template" file.


I had to be careful in my C program to properly escape LaTeX special chars 
before it wrote the data to MyVariableData.tex, i.e., at least "_", "*" and 
"\" become "\_", "{*}" and "\textbackslash{}".

There are probably others you need to look out for like "%" & "@".

in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}




then with a script passing all the appropriate options to LaTeX, dvips (I 
needed PostScript output) and an rm of LaTeX temporary data, I have the 
program create the postscript for sending to the printer.



Hope this helps.


[1] a full LaTeX document which uses a lot stuff from \usepackage{ifthen} 
\usepackage{soul} \usepackage{pstricks} \usepackage{pst-text} 
\usepackage{pst-eps} \usepackage[dvips]{graphicx} \usepackage[dvips]{geometry}
I love the funky stuff you can do with LaTeX... like making CD labels with 
curved words on top of pictures.  I started from:

http://www.aldil.org/projets/TeX_cd_label.html

[2] appropriate from the perspective that you may need some packages defined 
before the variable file is pulled in, and you need to pull in the variable 
file before you try to use one of it's variables in the main LaTeX file.



--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter
http://www.crane.navy.mil/custfeedback


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


  Thank you, Todd!


I had to be careful in my C program to properly escape LaTeX special chars
before it wrote the data to MyVariableData.tex, i.e., at least "_", "*"
and "\" become "\_", "{*}" and "\textbackslash{}". There are probably
others you need to look out for like "%" & "@".


  This should not be an issue in our model. The data are extracted from the
database to a Python list (or a list of tuples; analogous to a
two-dimensional array), and I can use indices to extract the strings and
numbers I want.

  There will be plots (created, no doubt, with PSTricks), to be included in
the audit log report of each run. So I expect the templates to be as
inclusive as your example.


in MyVariableData.tex there are lines of the form:
\def\MyFirstVar{{*}Data{*} for Var\_1}


  I do need to better learn programming in LaTeX; this project needs that
increased knowledge.


Hope this helps.


  Yes, it does.

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Paul A. Rubin

Rich Shepard wrote:

  This is not LyX specific, but I'm hoping that some of you can provide
direction to help me find the solution I need.

  In brief: we're developing an approximate reasoning model (a type of
expert system) in Python and C, with data maintained in an embedded SQLite
database. I'd like to produce reports via LaTeX and pdflatex. To do so, I
need to write report-specific LaTeX templates that have replaceable
variables where the content goes. Then, the applicaion would
programmatically extract the required information from a database table and
fill in the template for the report.

  I cannot find how to create such a LaTeX template in "Guide to LaTeX" or
TLC2. LaTeX document classes are templates themselves, but are used to
manually fill in the document content. Can this content be provided
programmatically?



I would write the template as an ordinary document (and of course would 
write it in LyX, then export to .tex), using some distinctive 
placeholders where the good stuff would be inserted (e.g., %%variable 
1%% or some such).  Then have a script create a copy of the .tex file 
(so as not to corrupt the master template) and use sed to substitute the 
good stuff for the placeholders.  Depending on what the good stuff looks 
like, you might have to escape a character here or there.


Or am I missing something fundamental here?

/Paul



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Ernesto Posse
Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


On 10/10/07, Rich Shepard <[EMAIL PROTECTED]> wrote:
> On Wed, 10 Oct 2007, Todd Denniston wrote:
>
> > I have done such a beast, therefore it can be done. :)
>
>Thank you, Todd!
>
> > I had to be careful in my C program to properly escape LaTeX special chars
> > before it wrote the data to MyVariableData.tex, i.e., at least "_", "*"
> > and "\" become "\_", "{*}" and "\textbackslash{}". There are probably
> > others you need to look out for like "%" & "@".
>
>This should not be an issue in our model. The data are extracted from the
> database to a Python list (or a list of tuples; analogous to a
> two-dimensional array), and I can use indices to extract the strings and
> numbers I want.
>
>There will be plots (created, no doubt, with PSTricks), to be included in
> the audit log report of each run. So I expect the templates to be as
> inclusive as your example.
>
> > in MyVariableData.tex there are lines of the form:
> > \def\MyFirstVar{{*}Data{*} for Var\_1}
>
>I do need to better learn programming in LaTeX; this project needs that
> increased knowledge.
>
> > Hope this helps.
>
>Yes, it does.
>
> Rich
>
> --
> Richard B. Shepard, Ph.D.   |The Environmental Permitting
> Applied Ecosystem Services, Inc.| Accelerators(TM)
>  Voice: 503-667-4517  Fax: 503-667-8863
>


-- 
Ernesto Posse
Modelling, Simulation and Design Lab - School of Computer Science
McGill University - Montreal, Quebec, Canada
url: http://moncs.cs.mcgill.ca/people/eposse


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive placeholders
where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.


Or am I missing something fundamental here?


  Honestly don't know at this time.

  I was expecting to find a Python library, because Python has libraries for
almost everything, but the PyTeX project apparently died 2-4 years ago.
Ideally, there would be the equivalent of, for example, pysqlite which is
the connection between Python code and the SQLite database (there are
equivalents for postgres and other dbms).

  How it would work or what it would need I've no idea now.

  But, you've contributed to the ideas, and that's a Good Thing(R). Many
thanks,

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose. I think the only thing that you would have to be
careful about is with the $: You would have to replace the normal $'s
of your LaTeX template by $$, since this class uses $ for marking
placeholders. Here's the link to the documentation

http://docs.python.org/lib/node40.html


  Thank you very much, Ernesto.

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Ernesto Posse wrote:


Since you are using Python, I suggest using the string.Template class
for this purpose.


  The example on that 'man' page suggests the path to ultimate happiness,
using the Python shell:


from string import Template
s = Template('$who likes $what')
s.substitute(who='tim', what='kung pao')

'tim likes kung pao'

  I think what might work is writing the LaTeX template as a series of print
statements (writing to an output file with the .tex extension), and using
the Template class to replace each variable as needed, before printing that
line to the output file, too.

  I'll play with this. It looks promising.

Thanks, all,

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Todd Denniston

Rich Shepard wrote, On 10/10/2007 12:09 PM:

On Wed, 10 Oct 2007, Paul A. Rubin wrote:


I would write the template as an ordinary document (and of course would
write it in LyX, then export to .tex), using some distinctive 
placeholders

where the good stuff would be inserted (e.g., %%variable 1%% or some
such).  Then have a script create a copy of the .tex file (so as not to
corrupt the master template) and use sed to substitute the good stuff for
the placeholders.  Depending on what the good stuff looks like, you might
have to escape a character here or there.


Paul,

  I think this is fundamentally the same approach Todd used.



Almost, except I was using [La]TeX variables so that you do not have to modify 
the template file, just the variable defining file.


--
Todd Denniston
Crane Division, Naval Surface Warfare Center (NSWC Crane)
Harnessing the Power of Technology for the Warfighter



Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Steve Litt
On Wednesday 10 October 2007 13:16, Rich Shepard wrote:

>
>I'll play with this. It looks promising.

Rich -- please share whatever your final solution with the list. I think most 
of us need to do this exact thing from time to time.

SteveT

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


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread William Adams

On Oct 10, 2007, at 12:15 PM, Todd Denniston wrote:


I have done such a beast, therefore it can be done. :)


Me too!

My approach was a bit different though --- I templated a bunch of  
buttons using Runtime Revolution (a HyperCard clone) which were then  
output into a text file concatenated along w/ the content of various  
text fields. The commands either set the output, or re-defined other  
commands --- worked out quite nicely, allowing people to set  
telephone line ads w/ a fair bit of flexibility (the system was later  
up-dated to be server-driven w/ a .html JavaScript front-end).


William

--
William Adams
senior graphic designer
Fry Communications




Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Steve Litt wrote:


Rich -- please share whatever your final solution with the list. I think
most of us need to do this exact thing from time to time.


Steve,

  I will. I'll try both LaTeX and ReportLab and see which seems to be easier
to implement using one report as a test.

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Daniel Lohmann



Rich Shepard schrieb:


  There will be plots (created, no doubt, with PSTricks), to be 
included in

the audit log report of each run. So I expect the templates to be as
inclusive as your example.


If you haven't worked with PSTricks so far (meaning that you have to 
learn something new anyway) you should also consider PGF/TikZ as a more 
modern alternative.


http://www.ctan.org/tex-archive/help/Catalogue/entries/pgf.html

PGF is the graphics engine that is also internally used by LaTeX beamer; 
TikZ is the user-friendly layer on top of it. People who worked quite a 
lot with both told me that, compared to PSTricks, the TikZ syntax is way 
more consistent and in many cases more convenient (take a look at 
http://www.fauskes.net/pgftikzexamples/all/ for some examples). Some 
things that are possible with PSTricks (especially embedded postscript 
functions) are not available with PGF/TikZ, though.


The best thing, however, is that unlike PSTricks which work only with 
back-end processors that generate postscript code (dvips), TikZ works 
perfectly well with any major back-end processor, especially  pdfTeX / 
pdfLaTeX. (PDF has always been a kind of show-stopper for PSTricks.)


Daniel


Re: [OT] Programmatically Creating a LaTeX Document

2007-10-10 Thread Rich Shepard

On Wed, 10 Oct 2007, Daniel Lohmann wrote:


If you haven't worked with PSTricks so far (meaning that you have to learn
something new anyway) you should also consider PGF/TikZ as a more modern
alternative.


  Thanks, Daniel. I've used PSTricks some, but use Xfig most of the time. I
started to look at PGF/TikZ a few years ago when I started using the beamer
class, but never followed through.

Rich

--
Richard B. Shepard, Ph.D.   |The Environmental Permitting
Applied Ecosystem Services, Inc.| Accelerators(TM)
 Voice: 503-667-4517  Fax: 503-667-8863