[portland] Generating .tex From Python Code

Rich Shepard rshepard at appl-ecosys.com
Fri Apr 4 00:00:27 CEST 2008

Hi, folks!

   I'm starting to figure out how to generate a .tex file from within a
Python program. For some reason, my initial attempts are producing screwy
results. I suspect those reasons are more python-related than they are LaTeX

   The attached code runs, but the output is not what I expected to see. Have
I made python mistakes in the code? For example, why is the last line of the
preamb comment truncated by two letters? Why are other letters missing, and
the LaTeX commands written as output strings embedded in the list, rather
than as LaTeX commands?



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

import os, sys, config

preamb = """
  \usepackage[dvips] {geometry}




ending = """\end{document}"""
def econPairs():
  pairData = [("Jobs","Tax base"),
              ("Jobs","Medical care"),
              ("Jobs","Traffic volume"),
              ("Tax base","Infrastructure"),
              ("Tax base","Schools"),
              ("Tax base","Housing"),
              ("Tax base","Medical care"),
              ("Tax base","Sustainability"),
              ("Tax base","Traffic volume"),
              ("Infrastructure","Medical care"),
              ("Infrastructure","Traffic volume"),
              ("Schools","Medical care"),
              ("Schools","Traffic volume"),
              ("Housing","Medical care"),
              ("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("""\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('Record your position on the project here -->')

  for left,right in pairData:


if __name__ == "__main__":

More information about the Portland mailing list