[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [seul-edu] New Educational Applications



El Mié 29 Ene 2003 18:13, Doug Loss escribió:
> Dennis Daniels wrote:
> > Where do we get it? find it? test it?
> > cheers
> > dgd
> >
> > Seul/Edu Appdex wrote:
> >> Name: subpsx.pl
>
> http://www.seul.org/edu/packages/subpsx.pl

Well, I've hacked a quick and dirty version in python, much powerful, much 
clear, that produces pdf (more popular than postscript), easier to 
understand, shorter,... and GPL of course.
Enjoy it. 

---
mga 

python rules

boletines.50g.com  (just an add) 
"""
January 2003, Copyright Manuel Gutierrez Algaba

Distributed under GPL license

"""

import sys
import os
import random

class gentex:
    def __init__(self):
        pass
    def head(self):
        return r"""
        \documentclass{article}
        \usepackage{multicol}
        \begin{document}
        \begin{multicols}{5}
        \large
        """

    def tail(self):
        return r"""
        \end{multicols}
        \end{document}
        """

    def computation(self, topnumber, bottomnumber, op):
        assert type(topnumber) == type(3)
        assert type(bottomnumber) == type(3)
        a = r"""\begin{tabular}{r}
        """
        t = str(topnumber)
        b = str(bottomnumber)
        z =r"""
        \\
        \hline

        \end{tabular}
        \vspace{0.1cm} \hspace{0.5cm}
        """
        return a + t + r"\\" + op + r" \hfill" + " " + b +  z

    def genfile(self, d, string):
        f = open(d, "w")
        f.write(string)
        f.close()
        
    def test(self):
        print self.computation(20, 30, '-')
        self.genfile("/tmp/t.tex", self.head() + self.computation(20, 30, '-') + self.tail())
        os.system(" pdflatex /tmp/t.tex; cp t.pdf /tmp/t.pdf; gv /tmp/t.pdf" )

    def genseveralcomputations(self, arange, brange, op, howmanycomps):
        sc = r"\begin{enumerate}"
        for i in xrange(0, howmanycomps):
            anum = random.choice(xrange(arange))
            bnum = random.choice(xrange(brange))
            if anum <= bnum: continue
            sc += r"\item{ " + self.computation(anum, bnum, op) + "}"
        sc += r"\end{enumerate} "
        self.genfile("/tmp/t.tex", self.head() + sc + self.tail())
        os.system(" pdflatex /tmp/t.tex; cp t.pdf /tmp/t.pdf; gv /tmp/t.pdf" )
        
    def testseveralcomputations(self):
        sc = ""
        for i in xrange(0,1000):
            sc += self.computation(20,20, '-')
        self.genfile("/tmp/t.tex", self.head() + sc + self.tail())
        os.system(" pdflatex /tmp/t.tex; cp t.pdf /tmp/t.pdf; gv /tmp/t.pdf" )
        
        
#class gen

gentex().genseveralcomputations(1000, 50, r'/', 200)