Looking at the documentation for pweave here, it appears to be possible to access any data generated inside a template by the calling program, by setting the returnglobals
variable.
Is it possible to do the opposite?, i.e. have the template reference a global variable in the calling script?
My use case is that I first pull some data from an SQL database, and then call pweave.pweave()
using that data to populate the template. Currently I'm doing this by writing an intermediate file and then loading this in a preamble in the template. I would like to instead just pass this in as part of the global scope. I've tried declaring a variable global
in the template, but this doesn't appear to work; I keep getting exception NameError
.
This can be done as follows:
In the calling script :
In the tex template:
which will print "The value of foo is bar".
The reason for the weird dictionary is that the code uses the following call to evaluate your code:
You can get more information in the Python Documentation.