I'm currently working on a package that supposedly takes the output of a function in a Python script, and adds it to the PDF. For example, one function may scrape data from a website automatically, so that the PDF can be automatically updated and uploaded to a server without human intervention.

I did stumble across this package on CTAN, but it seems to be way outdated, and instead of finding output from a script it embeds the code in the .tex file. The usage would be as follows:



\pyin{scripts/script.py}{function}{arg1,type}{arg2,type} %...

As you can see, the \pyin{} command should have optional arguments with the type supplied. For example, the actual code may be \pyin{scripts/scrape_data.py}{scrape_data}{http://tex.stackexchange.com/questions/ask,str}.

How could I, if possible, recieve output from a Python file with Python code such as:

import pythonin

def scrape_data(url):

yet again, I have no idea how I would go about writing up the actual code for both the pythonin module and the pythonin.sty package. Any ideas would be appreciated, since I'm kind of out of my depth here.

Many thanks!

  • To be clear.... you're trying to write a new package called pythonin that will run a Python function with the arguments you specify? – darthbith Oct 27 '14 at 19:24
  • @darthbith Indeed, or none at all. To be honest, I think whatever works, no matter how basic, would be fine, if I could then work on it. – HarryCBurn Oct 27 '14 at 19:34
  • thanks for the edit (not too bad since I think that was my first ever published python:-) – David Carlisle Oct 27 '14 at 19:56
  • No problem! It was just a few nitpicks about spacing that caught my eye. Thanks for the answer by the way, I'll have to investigate pdflatex a little more, I think. – HarryCBurn Oct 27 '14 at 20:01
  • Oh there is nothing pdflatex specific there, the pipe symbol for input scripting comes from web2c so applies to latex or tex or xetex etc as well as pdftex – David Carlisle Oct 27 '14 at 20:05

Given this python:


import sys

print sum(map(int, sys.argv[1:]))

Then running the following TeX with pdflatex --shell-escape shows that the python has been passed a script and some arguments with the result being typeset by TeX.



sum is \input{"|python tst.py 1 2 3 2>/dev/null"}



enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.