On 7/8/2021 7:55 PM, Gavin wrote:
Hello,
I have a book containing many margin figures drawn with TikZ, which is very
slow. By putting the TikZ code in a buffer and using \typesetbuffer only
altered TikZ code is executed on each run, saving tremendous time. This means
the code containsmany constructions like this, which I would like to simplify:
\startbuffer[BlueCircle]
\usemodule[tikz]% Actually this is many lines to load environments, define
fonts, etc.
\startTEXpage
\starttikzpicture
\draw[thick,blue] (0,0) circle (1.5cm)node{Ti{\it k}Z!};
\stoptikzpicture
\stopTEXpage
\stopbuffer
\placefigure[margin][fig:BlueCircle] % location, label
{Ti{\it k}Z drew this blue circle\dots slowly.} % caption text
{\hbox{\typesetbuffer[BlueCircle]}}
My plan is to replace the first block with a new \startTikZbuffer…\stop…, which
is defined using \definestartstop to include all of the stuff around the TikZ
code. Then I will replace the second block with a new command, \marginTikZ,
which has three arguments: a label, a caption, and the TikZ code. This command
will use my new \startTikZbuffer to create the buffer before using \placefigure
to put it in the margin. Only the \marginTikZ command will appear throughout
the book.
I’d like to do this in two steps because I will also have \textTikZ and
\wideTikZ for diagrams in the text block and diagrams spanning the full page
with. All of these can use the same \startTikZbuffer. However, I cannot get the
\startTikZbuffer to work as expected.
I put a small working example below. Removing the “This method works” block and adding the
"This method fails” block causes the an error that I cannot decipher: "Use of
\page_fitting_start doesn't match its definition."
Any advice is appreciated. Maybe I am doing this entirely the wrong way.
A couple notes: I considered using \definebuffer, but this doesn’t allow me to
create named buffers, which seems like a deal breaker. I considered using
\definefloat, but it don’t allow me include before and after commands, as far
as I can tell.
\starttext
\input knuth
\startbuffer[starttikz]
\usemodule[tikz]
\startTEXpage
\starttikzpicture
\stopbuffer
\startbuffer[stoptikz]
\stoptikzpicture
\stopTEXpage
\stopbuffer
\protected\def\MyTikzBuffer#1{\typesetbuffer[starttikz,BlueCircle,stoptikz]}
\startbuffer[BlueCircle]
\draw
[thick,blue] (0,0) circle (1.5cm)node{Ti{\it k}Z!};
\stopbuffer
\startplacefigure[location=margin,reference=fig:BlueCircle,title={Example A.}]
\typesetbuffer[starttikz,BlueCircle,stoptikz]
\stopplacefigure
\startplacefigure[location=margin,reference=fig:BlueCircle,title={Example B.}]
\MyTikzBuffer{BlueCircle}
\stopplacefigure
\input knuth
\stoptext
-----------------------------------------------------------------
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
___________________________________________________________________________________