[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Python and Latex

Hi

I'm trying to write a python program to generate a pdf document with LaTeX type equations.

At the moment, I am simply creating a tex file with all the commands in place e.g.

outfile.write( "\\documentclass{article}\n" )
outfile.write( "\\usepackage{graphicx}\n" )
outfile.write( "\\begin{document}\n" )
outfile.write( "\\end{document}\n" )

I have two questions:

(1) Is there an easier way to do this? That is, using this approach I will have to process the resulting file using LaTeX and get it to create a PDF document (possibly using pdflatex). Is there a way to do this using purely Python modules?
(2) If I do create the latex file, is there a way for me to get the python code to process the resulting file to create the pdf document automatically?

Thanks in advance

Issac
0
IssacJones
Asked:
IssacJones
  • 2
  • 2
1 Solution
 
LeeeRussellCommented:
I recently had a search around for a module to create tex files within python for a project I was assigned, and I couldn't find anything.  Hopefully someone else will have some better news for you.

You can always create the PDF directly from python by calling the command line pdflatex utility from within python using os.command("pdflatex [OPTION...] [COMMAND...]"
0
 
IssacJonesAuthor Commented:
Hi Lee

Yes, I did some searching. I came across PyTeX but the download only seemed to give .tex files. The homepage seems promising saying that this type of code can be used:

http://www.pytex.org/

    from tex import tex, plain
    document = 'My beautiful \\TeX\ document.\n'
    (dvi, log) = tex(plain, document)

to generate a dvi file.

However, if you download from the link given I can't see any python modules
0
 
LeeeRussellCommented:
I think I found PyTex and thought it was incomplete (as you say, it is lacking any python modules).  I didn't try contacting the developer though, that might be worthwhile.
0
 
IssacJonesAuthor Commented:
I've emailed PyTeX but not had a response so it looks like the project is on hold.

I wonder if there was a way for me to TeX source code and I could try and write something myself i.e. I can program in C++.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now