Re: [NTG-context] externalizing TikZ graphics

2021-01-27 Thread Henning Hraban Ramm

> Am 25.01.2021 um 20:08 schrieb Henning Hraban Ramm :
> 
> """
> \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



___
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
___


Re: [NTG-context] externalizing TikZ graphics

2021-01-25 Thread Henri Menke
On Mon, 2021-01-25 at 16:42 +0100, Henning Hraban Ramm wrote:
> Hi,
> 
> did anyone succeed in externalizing TikZ graphics with ConTeXt?

The external library is LaTeX-only and that unfortunately won't change because
it heavily relies on implementation detail of LaTeX's output routine.

> It’s about a project with hundreds of diagrams that (in the current state)
> clutter the main directory with cryptically-named PDFs (at least sorted by
> component name) and that on each ConTeXt run take a lot of runtime (I guess
> also the many log lines slow the process).
> 
> In 2013, Aditya said it wasn’t possible to externalize pgf/TikZ graphics as
> documented in the pgf manual, and "perhaps" it would make sense to use his
> filter module:

filter is your best bet, in my opinion.

> https://mailman.ntg.nl/pipermail/ntg-context/2013/071162.html
> 
> Did anyone try to do that? I didn’t find anything in this list’s archives.
> 
> The original pgf way is two-pass, and you’d need to call LaTeX with the
> intended graphics name as --jobname; that’s far too much of a hassle for that
> many graphics.
> 
> I generally like how the filter module works, as you can also define the name
> of every buffer, but my only experience with that is my LilyPond setup.
> 
> If nobody has better advice, I’ll try to come up with a filter setup. That
> would mean we’d avoid the tikz module, every TikZ diagram will get written to
> a buffer of configurable name, and that (with preamble setup) will get run
> through LaTeX. I read pgf had some restrictions in plain TeX mode, but perhaps
> we can also use LuaTeX in plain mode to avoid the LaTeX dependency.
> 
> Best, 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
> __
> _

___
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
___


Re: [NTG-context] externalizing TikZ graphics

2021-01-25 Thread Henning Hraban Ramm

> Am 25.01.2021 um 18:58 schrieb Aditya Mahajan :
> 
> 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
___


Re: [NTG-context] externalizing TikZ graphics

2021-01-25 Thread Aditya Mahajan
On Mon, 25 Jan 2021, Henning Hraban Ramm wrote:

> 
> > Am 25.01.2021 um 17:31 schrieb Hans Hagen :
> > 
> >> If nobody has better advice, I’ll try to come up with a filter setup. That 
> >> would mean we’d avoid the tikz module, every TikZ diagram will get written 
> >> to a buffer of configurable name, and that (with preamble setup) will get 
> >> run through LaTeX. I read pgf had some restrictions in plain TeX mode, but 
> >> perhaps we can also use LuaTeX in plain mode to avoid the LaTeX dependency.
> > In the following case the buffer only gets typeset when it changes:
> 
> Thank you (and Henri)! But we’d need to include the same setup header every 
> time, so the filter module is probably really the best way.

It is not only the tikz setup; you also need to copy the font setup etc. 

\typesetbuffer[setups,figure]

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.

> There’s just a problem with labels, I guess, if I go the filter-LaTeX or 
> filter-TeX route. So filter-ConTeXt might make sense.
> I think I understand now why integrating MetaPost made a lot of sense.

Here is a simple example:


\usemodule[filter]

\startbuffer[tikz-before]
\usemodule[tikz]
\startTEXpage
\starttikzpicture
\stopbuffer

\startbuffer[tikz-after]
\stoptikzpicture
\stopTEXpage
\stopbuffer

\defineexternalfilter
  [externaltikz]
  [
bufferbefore=tikz-before,
bufferafter=tikz-after,
cache=yes,
filtercommand={context --batchmode \externalfilterinputfile\space 
--purgeall --result=\externalfilteroutputfile},
output={\externalfilterbasefile.pdf},
readcommand=\readPDFfile,
  ]

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

\starttext
\startexternaltikz
  \draw (0,0) -- (1,1);
\stopexternaltikz

\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
___


Re: [NTG-context] externalizing TikZ graphics

2021-01-25 Thread Henning Hraban Ramm

> Am 25.01.2021 um 17:31 schrieb Hans Hagen :
> 
>> If nobody has better advice, I’ll try to come up with a filter setup. That 
>> would mean we’d avoid the tikz module, every TikZ diagram will get written 
>> to a buffer of configurable name, and that (with preamble setup) will get 
>> run through LaTeX. I read pgf had some restrictions in plain TeX mode, but 
>> perhaps we can also use LuaTeX in plain mode to avoid the LaTeX dependency.
> In the following case the buffer only gets typeset when it changes:

Thank you (and Henri)! But we’d need to include the same setup header every 
time, so the filter module is probably really the best way.

There’s just a problem with labels, I guess, if I go the filter-LaTeX or 
filter-TeX route. So filter-ConTeXt might make sense.
I think I understand now why integrating MetaPost made a lot of sense.

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
___


Re: [NTG-context] externalizing TikZ graphics

2021-01-25 Thread Hans Hagen

On 1/25/2021 4:42 PM, Henning Hraban Ramm wrote:

Hi,

did anyone succeed in externalizing TikZ graphics with ConTeXt?

It’s about a project with hundreds of diagrams that (in the current state) 
clutter the main directory with cryptically-named PDFs (at least sorted by 
component name) and that on each ConTeXt run take a lot of runtime (I guess 
also the many log lines slow the process).

In 2013, Aditya said it wasn’t possible to externalize pgf/TikZ graphics as documented in 
the pgf manual, and "perhaps" it would make sense to use his filter module:

https://mailman.ntg.nl/pipermail/ntg-context/2013/071162.html

Did anyone try to do that? I didn’t find anything in this list’s archives.

The original pgf way is two-pass, and you’d need to call LaTeX with the 
intended graphics name as --jobname; that’s far too much of a hassle for that 
many graphics.

I generally like how the filter module works, as you can also define the name 
of every buffer, but my only experience with that is my LilyPond setup.

If nobody has better advice, I’ll try to come up with a filter setup. That 
would mean we’d avoid the tikz module, every TikZ diagram will get written to a 
buffer of configurable name, and that (with preamble setup) will get run 
through LaTeX. I read pgf had some restrictions in plain TeX mode, but perhaps 
we can also use LuaTeX in plain mode to avoid the LaTeX dependency.

In the following case the buffer only gets typeset when it changes:

\starttext

\startbuffer[foo]
% maybe include a style / enviroment
\usemodule[tikz] \usetikzlibrary[patterns]
\startTEXpage
\starttikzpicture
   \draw[pattern color=red,pattern=bricks] (0,0) circle (1cm);
\stoptikzpicture
\stopTEXpage
\stopbuffer

\framed[offset=overlay]{\typesetbuffer[foo]}

\stoptext

Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
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
___


[NTG-context] externalizing TikZ graphics

2021-01-25 Thread Henning Hraban Ramm
Hi,

did anyone succeed in externalizing TikZ graphics with ConTeXt?

It’s about a project with hundreds of diagrams that (in the current state) 
clutter the main directory with cryptically-named PDFs (at least sorted by 
component name) and that on each ConTeXt run take a lot of runtime (I guess 
also the many log lines slow the process).

In 2013, Aditya said it wasn’t possible to externalize pgf/TikZ graphics as 
documented in the pgf manual, and "perhaps" it would make sense to use his 
filter module:

https://mailman.ntg.nl/pipermail/ntg-context/2013/071162.html

Did anyone try to do that? I didn’t find anything in this list’s archives.

The original pgf way is two-pass, and you’d need to call LaTeX with the 
intended graphics name as --jobname; that’s far too much of a hassle for that 
many graphics.

I generally like how the filter module works, as you can also define the name 
of every buffer, but my only experience with that is my LilyPond setup.

If nobody has better advice, I’ll try to come up with a filter setup. That 
would mean we’d avoid the tikz module, every TikZ diagram will get written to a 
buffer of configurable name, and that (with preamble setup) will get run 
through LaTeX. I read pgf had some restrictions in plain TeX mode, but perhaps 
we can also use LuaTeX in plain mode to avoid the LaTeX dependency.

Best, 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
___