[NTG-context] reading from standard input

Aditya Mahajan adityam at umich.edu
Fri Jun 8 15:31:24 CEST 2012

On Fri, 8 Jun 2012, <stdin> | Alexandre Leray wrote:

> Hi,
> I was wondering if there was a way to make context read from stdin instead of 
> reading from a file?
>    cat /path/to/src.tex | context --result=/path/to/result.pdf
> I'd like to do something like this in python:
>    def generate_pdf(self):
>        src = """
>        \starttext
>        \section[éléments-de-transmission]{Éléments de transmission}
>        Un module dans lequel une communauté temporaire d'étudiants et
>        d'enseignants s'exerce à mettre en situation des réflexions et des
>        moments de transmission en interrogeant sans cesse la question de
>        l'enseignement. La configuration des enseignants est variable selon
>        les situations. Les situations seront mises en place en semaine A et 
> B
>        selon l'emploi du temps. Chaque nouvelle situation invente sa 
> méthode.
>        \stoptext
>        """
>        cmd = 'context --result=/tmp/result.pdf'
>        p1 = subprocess.Popen(cmd.split(" "), stdout=subprocess.PIPE, 
> stdin=subprocess.PIPE)
>        (stdout, stderr) = p1.communicate(stdin=src)

You can try context --pipe --result=/tmp/result.pdf but that only runs the 
document once, so cross referencings, TOC, etc won't work correctly. The 
other options is to write to a file, and then run "context --purgeall 
--result=/tmp/result.pdf filename"; this will run the document appropriate 
number of times, and then delete the temp files, leaving only the .tex and 
the .pdf file.


More information about the ntg-context mailing list