[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
related.

   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?

Puzzled,

Rich

-- 
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 = """
  \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("""\end{document}""")
  out.close()

if __name__ == "__main__":
  econPairs()


More information about the Portland mailing list