[NTG-context] externalizing TikZ graphics

Henning Hraban Ramm texml at fiee.net
Wed Jan 27 22:27:49 CET 2021


> Am 25.01.2021 um 20:08 schrieb Henning Hraban Ramm <texml at fiee.net>:
> 
> """
> \startmodule[tikzfilter]
> 
> \usemodule[filter]
> % docs see https://github.com/adityam/filter
> 
> \def\TIKZTEMP{tikztemp} % name of folder for TikZ/buffer files
> 
> \startbuffer[tikz::before]
> \environment env_world % contains font setup etc.
> \environment env_TikZ % contains TikZ settings
> 
> \startpagefigure

Wrong, I need \startTEXpage

> \starttikzpicture[thick,domain=-90:90]% TODO: make this configurable

Now, how can I forward options from
\starttix[anything]
to this place?

> \stopbuffer
> 
> \startbuffer[tikz::after]
> \stoptikzpicture
> \stoppagefigure

\stopTEXpage

> \stopbuffer
> 
> \define[1]\ParseTikZFile% #1 is the name of the output file
>  {\ctxlua{thirddata.parsetikzfile("#1")}}
> 
> \startluacode
> thirddata = thirddata or {}
> 
> -- create temp folder if missing
> if not lfs.isdir("\TIKZTEMP") then
>   lfs.mkdir("\TIKZTEMP")
> end
> 
> function thirddata.parsetikzfile(name)
>   -- name is like \TIKZTEMP/mainfile-temp-tikz-21.pdf
>   logs.report("TIKZFILTER","name='" .. name .. "'")
>   context("\\externalfigure[" .. name .. "]")
> end
> \stopluacode
> 
> \defineexternalfilter[tikz][
>  cache=yes,
>  purge=no,
>  directory=\TIKZTEMP,
>  bufferbefore={tikz::before},
>  bufferafter={tikz::after},
>  readcommand=\ParseTikZFile,
>  output={\externalfilterbasefile.pdf},
> % ConTeXt never writes results to other directories
>  filtercommand={context --batchmode --once --autopdf=auto --result=\externalfilterbasefile\space \externalfilterinputfile\space && mv \externalfilterbasefile.pdf\space \TIKZTEMP/},
> ]
> 
> \stopmodule





More information about the ntg-context mailing list