[NTG-context] filter module / externalizing TikZ graphics

Henning Hraban Ramm texml at fiee.net
Thu Jan 28 14:51:38 CET 2021

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

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.

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

(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.

(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?

(4) subprocess parameters

I’d like to forward some parameters from \starttikz to the temp buffer, e.g. 
(using the same syntax as \startsection with a second pair of brackets for custom parameters).
And then have
in the buffer.

My workaround so far is a copy of the filter setup (tikz/tikzThick), since we have only a few different configurations.

Best regards, Hraban

""" % file: t-tikzfilter.tex


\usemodule[filter] % docs see https://github.com/adityam/filter

\def\TIKZTEMP{tikztemp} % name of folder for TikZ/buffer files

% normal setup
\environment env_world
\environment env_TikZ


% setup for graphics with thicker lines
\environment env_world
\environment env_TikZ

\starttikzpicture[thick] % only difference


\define[1]\ReadPDFFile% #1 is the name of the output file

 thirddata = thirddata or {}

 local report_tikz = logs.reporter("tikzfilter")

 -- create temp folder if missing
 if not lfs.isdir("\TIKZTEMP") then

 function thirddata.readpdffile(name)
   -- name is like \TIKZTEMP/mainfile-temp-tikz-21.pdf
   report_tikz("name='%s'", name) % doesn’t work
   context("\\externalfigure[" .. name .. "]")

  % directory=\TIKZTEMP, % doesn’t work with ConTeXt
  filtercommand={mv \externalfilterbasefile.* \TIKZTEMP/ && cd \TIKZTEMP\space && context --batchmode --nodummy --once \externalfilterbasefile.tmp},



""" % file: tikztest.tex



\placefigure[margin,here][fig:example]{A box.}
	\draw[fill=black!10] (0,4.75) rectangle (1.5,-4.75);




More information about the ntg-context mailing list