ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Gavin <gavinpublic@comcast.net>
Subject: Re: TikZ in buffers: My struggle with \definestartstop
Date: Thu, 8 Jul 2021 23:26:36 +0200	[thread overview]
Message-ID: <c8c5c197-8f6a-3989-abc5-30c85f5c331b@xs4all.nl> (raw)
In-Reply-To: <77D9F950-6778-4DF8-ABF7-C203864B1277@comcast.net>

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
___________________________________________________________________________________

  reply	other threads:[~2021-07-08 21:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 16:35 [OT] TeXShop v4.66 adds support for new ConTeXt's syncing method Nicola
2021-07-08 16:48 ` Nicola
2021-07-08 17:55   ` TikZ in buffers: My struggle with \definestartstop Gavin
2021-07-08 21:26     ` Hans Hagen [this message]
2021-07-09  0:03       ` Gavin

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=c8c5c197-8f6a-3989-abc5-30c85f5c331b@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=gavinpublic@comcast.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).