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.

ConTeXt version: 2021.07.06 18:49
Same results with MkIV and LMTX.

Thanks!
Gavin



\setuppapersize[letter]

\setuplayout[
  backspace=90pt, % Horizontal layout
  leftmargin=36pt, % 1/2 in
  leftmargindistance=9pt, % 3/8 in
  width=306pt, % 4 1/4 in
  rightmargindistance=27pt, % 3/8 in
  rightmargin=144pt,  % 2 in
]

\definestartstop[TikZbuffer][
  
before={\startbuffer[\tikzname]\usemodule[tikz]\startTEXpage\starttikzpicture},
  after={\stoptikzpicture\stopTEXpage\stopbuffer},
]

\starttext

\input knuth

% This method works:
\startbuffer[BlueCircle]
  \usemodule[tikz]      
  \startTEXpage
    \starttikzpicture
      \draw[thick,blue] (0,0) circle (1.5cm)node{Ti{\it k}Z!};                  
             
    \stoptikzpicture
  \stopTEXpage
\stopbuffer

% This method fails:
%\def\tikzname{BlueCircle}
%\startTikZbuffer
%       \draw[thick,blue] (0,0) circle (1.5cm)node{Ti{\it k}Z!};                
               
%\stopTikZbuffer

\placefigure[margin][fig:BlueCircle] % location, label
  {Ti{\it k}Z drew this blue circle\dots slowly.}        % caption text
{\hbox{\typesetbuffer[BlueCircle]}}

\input knuth

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

Reply via email to