From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/114220 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Aditya Mahajan via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: Reset environment between MetaPost graphics? Date: Thu, 20 Jan 2022 09:26:42 -0500 (EST) Message-ID: References: <02d5d0c2ea4b0cbcf8c8693a8e89db1e9dc73721.camel@gmail.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-1974096534-1642688803=:453707" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14954"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Alpine 2.23 (LNX 453 2020-06-18) Cc: Aditya Mahajan To: Vincent Hennebert via ntg-context Original-X-From: ntg-context-bounces@ntg.nl Thu Jan 20 15:27:22 2022 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAYPK-0003iq-Aj for gctc-ntg-context-518@m.gmane-mx.org; Thu, 20 Jan 2022 15:27:22 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7E249285EB9; Thu, 20 Jan 2022 15:26:50 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z0fXS_5rdlDp; Thu, 20 Jan 2022 15:26:48 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 54BAD282FF2; Thu, 20 Jan 2022 15:26:48 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B70CD282FF2 for ; Thu, 20 Jan 2022 15:26:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h4OCTrEt_gd2 for ; Thu, 20 Jan 2022 15:26:46 +0100 (CET) Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=132.206.73.2; helo=orford.cim.mcgill.ca; envelope-from=adityam@umich.edu; receiver= Original-Received: from orford.cim.mcgill.ca (smtp.cim.mcgill.ca [132.206.73.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id E27BC282F95 for ; Thu, 20 Jan 2022 15:26:45 +0100 (CET) Original-Received: from adi-thinkpad.local (135-23-198-80.cpe.pppoe.ca [135.23.198.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adityam) by orford.cim.mcgill.ca (Postfix) with ESMTPSA id C150D189458 for ; Thu, 20 Jan 2022 09:26:43 -0500 (EST) In-Reply-To: <02d5d0c2ea4b0cbcf8c8693a8e89db1e9dc73721.camel@gmail.com> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:114220 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1974096534-1642688803=:453707 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Thu, 20 Jan 2022, Vincent Hennebert via ntg-context wrote: > Hi, >=20 > Say I=E2=80=99m writing a document containing many independent MetaPost > figures. I don=E2=80=99t want to bother with enclosing each and every gra= phics > in a =E2=80=98begingroup...endgroup=E2=80=99 with the appropriate =E2=80= =98save=E2=80=99 statement. But > I don=E2=80=99t want variables from previous graphics to leak into follow= ing > ones either. >=20 > Like this: >=20 > % SOF > \starttext >=20 > Text about some topic. >=20 > \startMPcode > u=3D1cm; > draw (-u, u)--origin--(u ,u); > \stopMPcode >=20 > Now on to another topic. >=20 > \startMPcode > u=3D2cm; % Triggers an error: Inconsistent equation (off by 28.34645) > draw (-u, u)..origin..(u ,u); > \stopMPcode >=20 > \stoptext > % EOF >=20 > Is that achievable? AFAIK, there is no in-built support for this.=20 I workaround this as follows. Instead of defining new variables using=20 numeric u; pair p; path q; etc. use: newnumeric u; newpair p; newpath p; etc. which automatically does a save beforehand. The only place where the abstra= ction leaks is arrays. You cannot do,=20 newpair p[]; but need save p; pair p[] instead.=20 Another option is to use assignment rather than equality: u :=3D 2cm; Aditya --8323329-1974096534-1642688803=:453707 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --8323329-1974096534-1642688803=:453707--