ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm <texml@fiee.net>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: externalizing TikZ graphics
Date: Mon, 25 Jan 2021 20:08:57 +0100	[thread overview]
Message-ID: <8CE2D9BB-F297-4BE7-9761-2440B4C415AB@fiee.net> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2101251242460.831318@nqv-guvaxcnq>


> Am 25.01.2021 um 18:58 schrieb Aditya Mahajan <adityam@umich.edu>:
> 
> or some variant of that should also work. But the filter module does make it easier to store the results in another directory so that they are out of sight.

No, you need additional file system commands.

> Here is a simple example:

Thank you!
Meanwhile, looking at my LilyPond module, I got as far as:

"""
\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
\starttikzpicture[thick,domain=-90:90]% TODO: make this configurable
\stopbuffer

\startbuffer[tikz::after]
\stoptikzpicture
\stoppagefigure
\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


Hraban
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2021-01-25 19:08 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 [this message]
2021-01-27 21:27         ` Henning Hraban Ramm
2021-01-28 13:51           ` filter module / " Henning Hraban Ramm
2021-01-29 23:13             ` 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=8CE2D9BB-F297-4BE7-9761-2440B4C415AB@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).