web2py report pdflatex template

166 views
Skip to first unread message

Peter Pan

unread,
May 5, 2014, 3:29:34 PM5/5/14
to web...@googlegroups.com
Hey 
I' m a teacher and work with pdflatex. I think its a good idea to learn LaTeX with web2py.
The Students create theire own reports with pdflatex. 
I do Not know how to implement a pdflatex-Template in web2py. I read the informations about markmin
But i couldn' t find the answer. 

Massimo Di Pierro

unread,
May 6, 2014, 9:14:33 AM5/6/14
to web...@googlegroups.com
Look into this file:


there is a function markmin2pdf that uses markmin2latex and then calls pdflatex. Only a subset of markmin is supported. Formulas go in between $$...$$ in markmin.

Massimo

Peter Pan

unread,
May 7, 2014, 2:37:25 PM5/7/14
to web...@googlegroups.com
Hey Massimo,

i follwo the link, read the manual and download your markmin-app,
but i could not find the answer - sorry iam a beginner in web2py.

Look, i have a grid with a Button "print" :

grid = SQLFORM.grid(query, orderby=~db.task.modified_on,create=False,details=False,editable=False,
         lambda row: A('print',_href=(URL('print_task',args=row.id),_class="btn"))

and i have a template = "template.tex"


But i do not know - how i connect the button "print" with the markmin and i do not know how i implement the "template.tex."

can you help me?

Massimo Di Pierro

unread,
May 7, 2014, 2:59:29 PM5/7/14
to web...@googlegroups.com


On Wednesday, 7 May 2014 13:37:25 UTC-5, Peter Pan wrote:
Hey Massimo,

i follwo the link, read the manual and download your markmin-app,
but i could not find the answer - sorry iam a beginner in web2py.

Look, i have a grid with a Button "print" :

grid = SQLFORM.grid(query, orderby=~db.task.modified_on,create=False,details=False,editable=False,
         lambda row: A('print',_href=(URL('print_task',args=row.id),_class="btn"))

You need this:

def print_task():
      task = db.task(request.args(0,cast=int))
      from gluon.contrib.markmin.markmin2pdf import latex2pdf
      template = open('yourtemplate.tex','r').read() # check path
      latex = template % task # or something similar
      pdf, warning, errors = latex2pdf(latex)
      if errors: pass # log errors
      response.headers['Content-Type'] = 'application/pdf'
      return pdf

Peter Pan

unread,
May 8, 2014, 6:33:18 AM5/8/14
to web...@googlegroups.com
thanks!
web2py create very good  the pdf with the template.tex but without args in the pdf.

Its right that i have to create a class like this:
class LaTeXTemplate(string.Template):
delimiter = "%%"

Or understand the markmin a special operator to insert the args?

My template.tex is:

\documentclass{article}

\begin{document}

The task is: $$args

\end{document}

Peter Pan

unread,
May 8, 2014, 6:31:53 PM5/8/14
to web...@googlegroups.com
Ok, i find a  way to work with the template and it works well:

I use this code in web2py:


def print_task():
      task = db.task(request.args(0,cast=int))
      from gluon.contrib.markmin.markmin2pdf import latex2pdf
      template = open('//home/user/web2py/applications/Tagesaufgaben/tex/tex/templatee.tex','r').read() # check path
      latex = template.format(status=task.status) # args of the dbase

      pdf, warning, errors = latex2pdf(latex)
      if errors: pass # log errors
      response.headers['Content-Type'] = 'application/pdf'
      return pdf

And this code in the template.tex

\documentclass{{article}}

\begin{{document}}

{status}

\end{{document}}


thanks for help Massimo



Reply all
Reply to author
Forward
0 new messages