From: Henning Hraban Ramm <texml@fiee.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: filter module / externalizing TikZ graphics
Date: Thu, 28 Jan 2021 14:51:38 +0100 [thread overview]
Message-ID: <560EB8BB-B3A3-4598-81E9-FA9A04BC7392@fiee.net> (raw)
In-Reply-To: <1668C4D5-11BA-48CD-9F21-69A6B39BC37F@fiee.net>
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.
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.
\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.
Best regards, Hraban
""" % file: t-tikzfilter.tex
\startmodule[tikzfilter]
\usemodule[filter] % docs see https://github.com/adityam/filter
\def\TIKZTEMP{tikztemp} % name of folder for TikZ/buffer files
% normal setup
\startbuffer[tikz::before]
\environment env_world
\environment env_TikZ
\startTEXpage
\starttikzpicture
\stopbuffer
% setup for graphics with thicker lines
\startbuffer[tikzThick::before]
\environment env_world
\environment env_TikZ
\startTEXpage
\starttikzpicture[thick] % only difference
\stopbuffer
\startbuffer[tikz::after]
\stoptikzpicture
\stopTEXpage
\stopbuffer
\define[1]\ReadPDFFile% #1 is the name of the output file
{\ctxlua{thirddata.readpdffile("#1")}}
\startluacode
thirddata = thirddata or {}
local report_tikz = logs.reporter("tikzfilter")
-- create temp folder if missing
if not lfs.isdir("\TIKZTEMP") then
lfs.mkdir("\TIKZTEMP")
end
function thirddata.readpdffile(name)
-- name is like \TIKZTEMP/mainfile-temp-tikz-21.pdf
report_tikz("name='%s'", name) % doesn’t work
context("\\externalfigure[" .. name .. "]")
end
\stopluacode
\defineexternalfilter[tikz][
cache=yes,
% directory=\TIKZTEMP, % doesn’t work with ConTeXt
bufferbefore={tikz::before},
bufferafter={tikz::after},
readcommand=\ReadPDFFile,
output={\TIKZTEMP/\externalfilterbasefile.pdf},
filtercommand={mv \externalfilterbasefile.* \TIKZTEMP/ && cd \TIKZTEMP\space && context --batchmode --nodummy --once \externalfilterbasefile.tmp},
]
\defineexternalfilter[tikzThick][tikz][
bufferbefore={tikzThick::before},
]
\stopmodule
"""
""" % file: tikztest.tex
\usemodule[t-tikzfilter]
\usemodule[visual]
\starttext
\placefigure[margin,here][fig:example]{A box.}
{\vskip1in\noindent%
\starttikzThick[name=example0]
\draw[fill=black!10] (0,4.75) rectangle (1.5,-4.75);
\stoptikzThick
}
\fakewords{150}{200}
\processtikzThickfile{tests/example1.pgf}
\stoptext
"""
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2021-01-28 13:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 15:42 Henning Hraban Ramm
2021-01-25 15:54 ` Henri Menke
2021-01-25 16:31 ` Hans Hagen
2021-01-25 16:41 ` Henning Hraban Ramm
2021-01-25 17:58 ` Aditya Mahajan
2021-01-25 19:08 ` Henning Hraban Ramm
2021-01-27 21:27 ` Henning Hraban Ramm
2021-01-28 13:51 ` Henning Hraban Ramm [this message]
2021-01-29 23:13 ` filter module / " Aditya Mahajan
2021-01-30 9:32 ` Henning Hraban Ramm
2021-01-31 6:39 ` Aditya Mahajan
2021-03-06 8:12 ` Henning Hraban Ramm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=560EB8BB-B3A3-4598-81E9-FA9A04BC7392@fiee.net \
--to=texml@fiee.net \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).