[NTG-context] filter module / externalizing TikZ graphics

Aditya Mahajan adityam at umich.edu
Sat Jan 30 00:13:19 CET 2021

On Thu, 28 Jan 2021, Henning Hraban Ramm wrote:

> Still working on that.
> I hope you can help me here, Aditya!
> I’ll add these issues to the tracker of t-filter, if it makes sense.
> Testing with: ConTeXt  ver: 2021.01.24 16:07 LMTX  fmt: 2021.1.25
> The setup below works, but only with \starttikz ... \stoptikz so far, I don’t like the output file names, and using the working directory is tricky.
> (1) \processFILTERfile
> \processtikzfile{img/example.pgf}
> can’t find the file:
> t-filter        > cached output file 'tikztemp/example1.pgf.pdf' missing. Rerunning filter
> t-filter        > file 'tikztemp/example1.pgf.pdf' cannot be found
> t-filter        > current filter : tikzThick
> t-filter        > base file : example1.pgf
> t-filter        > input file : img/example1.pgf
> t-filter        > output file : tikztemp/example1.pgf.pdf
> ...
> system          >   13: filename=img/example1.pgf foundname=img/example1.pgf fullname=.../img/example1.pgf usedmethod=direct
> Looks like ConTeXt can find the file, but the filter module cannot.
> --trackers=resolvers.schemes (or \enabletrackers) doesn’t change anything WRT log/output.

For \processFILTER, t-filter does not even read the file... so it has to do with how the filtercommand is defined. 

> Since this fails already, I don’t know if \processFILTERfile also uses bufferbefore/-after (it should).

It does not. As I said, for processing external files, t-filter does not even read the file and just takes care of caching the result. It is assumed that the filter command can process the external file. 

I can see if it is possible to active before and after filters while processing external files. Another option is to write the external files as valid tex file (i.e., with a \startTEXpage .. \stopTEXpage wrapper), and when defining the filtercommand, use something like `context --environment=env filename`, where env is the environment file with all the settings for fonts etc. 

> (2) working directory
> Since ConTeXt can’t put generated (temporary) files into a directory and --result also only renames afterwards, the directory key doesn’t help, I had to add "mv" and "cd" to my filtercommand.
> I didn’t check yet if caching works.

Caching should work if \definefilter is configured correctly. 

From the point of view of t-filter module, this is a bug in the external program and you should contact upstream for a fix :-) Most (all?) other programs are happy to write a file in any directory (modulo write permissions, etc.). I do not want to increase the complexity of the module to handle such corner cases. 

> (3) file names
> Using \processFILTERfile the original file name base is preserved, according to the log entry above.
> If I use \starttikz[name=example], I get "JOBNAME-temp-tikzThick-example.tmp".
> I’d like to get something like "COMPONENTNAME-##-example.tmp" or a path like "COMPONENTNAME/example_##.tmp".
> Is there a configuration hook in the module to change name generation?

No. I don't quite understand the concern. How do you plan to use a `name=value` option?

> (4) subprocess parameters
> I’d like to forward some parameters from \starttikz to the temp buffer, e.g. 
> \starttikz[name=example][mystyle=thick]
> (using the same syntax as \startsection with a second pair of brackets for custom parameters).
> And then have
> \starttikzpicture[\filterusersetupvariable{mystyle}]
> in the buffer.
> My workaround so far is a copy of the filter setup (tikz/tikzThick), since we have only a few different configurations.

The code that I had posted already handles this, provided that the options start on the line after \startfilter:




    filtercommand={context --batchmode \externalfilterinputfile\space --purgeall --result=\externalfilteroutputfile},

\define[1]\readPDFfile{\externalfigure[#1]} % width and height could be added

    [very thick, ->]
  \draw (0,0) -- (1,1);



More information about the ntg-context mailing list