4

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:

\documentclass[11pt]{article}

\usepackage{pythonin}

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

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):
    pythonin(some_result)

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!

1 Answers1

5

Given this python:

#!/usr/bin/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.

\documentclass{article}

\begin{document}

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

\end{document}

Producing:

enter image description here

David Carlisle
  • 757,742