From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/58804 Path: news.gmane.org!not-for-mail From: Marco Newsgroups: gmane.comp.tex.context Subject: Re: Ampersand in Metapost Date: Fri, 14 May 2010 12:06:21 +0200 Message-ID: <20100514120621.554d595d@vorbis> References: <20100513211856.48e15be4@vorbis> <4BEC6806.3010800@wxs.nl> <20100513234554.36d41c14@vorbis> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/dRSAUYBJmJF_1AIKLWPv99D" X-Trace: dough.gmane.org 1273832407 29181 80.91.229.12 (14 May 2010 10:20:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 14 May 2010 10:20:07 +0000 (UTC) To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Fri May 14 12:20:02 2010 connect(): No such file or directory Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OCrzr-0005e1-AH for gctc-ntg-context-518@m.gmane.org; Fri, 14 May 2010 12:19:59 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 80427C9AFD; Fri, 14 May 2010 12:19:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9hXt3aqm0DLo; Fri, 14 May 2010 12:19:55 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B507AC9AE3; Fri, 14 May 2010 12:19:55 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 64929C9AE3 for ; Fri, 14 May 2010 12:19:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 355Hy1nBJ2Ag for ; Fri, 14 May 2010 12:19:43 +0200 (CEST) Original-Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by balder.ntg.nl (Postfix) with ESMTP id 1C513C9ABB for ; Fri, 14 May 2010 12:19:42 +0200 (CEST) Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OCrzZ-0005VX-E3 for ntg-context@ntg.nl; Fri, 14 May 2010 12:19:41 +0200 Original-Received: from 202.58.85.36 ([202.58.85.36]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 May 2010 12:19:41 +0200 Original-Received: from netuse by 202.58.85.36 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 May 2010 12:19:41 +0200 X-Injected-Via-Gmane: http://gmane.org/ connect(): No such file or directory Original-Lines: 217 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 202.58.85.36 X-Newsreader: Claws Mail 3.7.6 (GTK+ 2.20.1; i486-pc-linux-gnu) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:58804 Archived-At: --MP_/dRSAUYBJmJF_1AIKLWPv99D Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Fri, 14 May 2010 00:37:44 +0200, Mojca Miklavec wrote: > On Thu, May 13, 2010 at 23:45, Marco wrote: > > On Thu, 13 May 2010 22:58:46 +0200, Hans Hagen > > wrote: > >> On 13-5-2010 9:18, Marco wrote: > >> > Hi, > >> > > >> > I have a problem producing an ampersand in metapost. In ConTeXt > >> > it works as expected. Have a look at the following example. > >> > > >> > \starttext > >> > \& =C2=A0% OK > >> > \startMPcode > >> > label(textext("\&"),origin); % produces error > >> > \stopMPcode > >> > \stoptext > >> > > >> > The compile time error message is as follows: > >> > =C2=A0 =C2=A0! Misplaced alignment tab character&. > >> > =C2=A0 =C2=A0l.1 \MPLIBsettext{1}{& > >> > >> \letterpercent > > Doesn't work. I suppose you mean \letterampersand. If I change \& > > into \letterampersand I get exactly the same error as \& produces > > (BTW: \letterpercent also produces an error, but a different one). >=20 > So: > - label(textext("\letterbackslash\letterampersand"),origin); > - label(textext("\letterbackslash\&"),origin); This both works. Thanks, Mojca. > This is because the commands are interpreted with TeX before they are > written to mpgraph.mp. The \letterampersand or \& generates the > character & alone: you need to preceed it with backslash, so that > metapost finally knows what to do. That sound like a double-escape. Intuitionally one would simply use &. I kn= ow, TeX doesn't like this, so we escape it, \&. However MetaPost doesn't like this, so we add a second escape: \letterbackslash\&. That's OK, as I rarely need ampersands in my graphics. > PS: I would say: better use \sometxt which is far more reliable unless > you have to use textext to do string manipulation. I don't know exactly which transformations are considered as =C2=BBstring manipulation=C2=AB. I've read your MyWay on \sometxt. Brilliant piece of do= c. But I've three questions. i) Is it about MkII, MkIV or both? ii) Is it still up-to-date? iii) Why should I better use \sometxt? What do you mean by =C2=BBmore reliable=C2=AB? After having read your MyWay= I would say that textext is more reliable because it can do dynamic text. I created a testfile to compare textext and \sometxt. The points to compare were those you mentionend in your MyWay as advantages of \sometxt. The testfile =C2=BBt.tex=C2=AB is attached. I processed it with ConTeXt ver: 2010.05.08 luatex, version beta-0.60.1-2010042821 Here are my results: -There is one obvious reason: speed $ for i in `seq 5`; do context -mode=3Dtextext t | tail -1; done MTXrun | total runtime: 128.008 MTXrun | total runtime: 37.893 MTXrun | total runtime: 37.900 MTXrun | total runtime: 38.391 MTXrun | total runtime: 38.029 $ rm t.{log,pdf,tuc} $ for i in `seq 5`; do context -mode=3Dsometxt t | tail -1; done MTXrun | total runtime: 127.195 MTXrun | total runtime: 40.131 MTXrun | total runtime: 41.071 MTXrun | total runtime: 37.424 MTXrun | total runtime: 39.121 Average runtime: textext variant: 56s \sometxt variant: 57s That is the same. Maybe my test file is not appropriate to test the speed. = I'm sure you have performed more advanced tests. -Document-wide definitions are seen [...] definitions with arguments will fail to work.=20 The first line, a document-wide definition with arguments works in both versions. -Problems with expansion [...] as far as I remember math expressions (fractions perhaps) never worked as they were supposed to The second definition is a math expressions with fractions. It seems to wor= k. -Less characters to escape Yes, that's the topic of this thread. I don't know, I didn't check. The only check I performed was the ampersand and it needs the same workaround using \letterbackslash as textext. I know, your MyWay is old. Maybe some things are fixed now. But I don't see many advantages for me using it. In fact, I have a problem getting random colors working. Take the following example (taken from my earlier thread). % This line is needed to get =C2=BBwithcolor=C2=AB to work? \chardef\TeXtextcolormode\zerocount \setupbodyfont [sans,36pt] \starttext \startMPcode numeric r, g, b ; def ran=3D r :=3D uniformdeviate 1 ; g :=3D uniformdeviate 1 ; b :=3D uniformdeviate 1 ; enddef; % Works as expected for i=3D0 downto -3: ran; label(textext("\bold\colored[r=3D" & decimal(r) & ",g=3D" & decimal(g) & ",b=3D" & decimal(b) & ",a=3D1, t=3D.2]{Test}"), (7cm,-1cm)) rotatedaround ((7cm,-1cm),i*20); endfor; % Produces empty rectangles for i=3D0 downto -3: ran; label(\sometxt{\bold{Test}}, (7cm,-4cm)) rotatedaround ((7cm,-4cm),i*20) withcolor transparent("normal", .2, (r,g,b)); endfor; \stopMPcode \stoptext Maybe there's a mistake in my code. It compiles without error but the result is incorrect. Marco --MP_/dRSAUYBJmJF_1AIKLWPv99D Content-Type: text/x-tex Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=t.tex \def\oklepaj#1{\left(#1\right)} \def\t{\dot N(t)=3D A\oklepaj{\exp\oklepaj{-\frac{t-t_0}{=CF=84_{\text{eksp.}}}}-\exp \oklepaj{-\frac{t-t_0}{=CF=84_{\text{fast}}}}}+ B\oklepaj{\exp\oklepaj{-\frac{t-t_0}{=CF=84_{\text{eksp.}}}}-\exp \oklepaj{-\frac{t-t_0}{=CF=84_{\text{slow}}}}}} \def\T{Test} \starttext \doifmode{textext}{Mode: textext} \doifmode{sometxt}{Mode: \letterbackslash sometxt} \startmode [textext] \startMPcode % label(textext("$\t$\&"),origin); % doesn't work label(textext("$\t$\letterbackslash\&"),origin); \stopMPcode \stopmode \startmode [sometxt] \startMPcode % label(\sometxt{$\t$\&},origin); % doesn't work, either label(\sometxt{$\t$\letterbackslash\&},origin); \stopMPcode \stopmode \switchtobodyfont [sans, 36pt] \bf \startmode [textext] \startMPcode for i=3D0 upto 100: label(textext("\colored [b=3D.7, a=3D1, t=3D.3]{\T}"),(i*1mm,0cm)) rotatedaround ((i*1mm,0cm),i*2); label(textext("\colored [g=3D.7, a=3D1, t=3D.2]{\T}"),(i*1.1mm,0cm)) rotatedaround ((i*1.1mm,0cm),i*2); endfor; \stopMPcode \stopmode \startmode [sometxt] \startMPcode for i=3D0 upto 100: label(\sometxt{\colored [b=3D.7, a=3D1, t=3D.3]{\T}},(i*1mm,0cm)) rotatedaround ((i*1mm,0cm),i*2); label(\sometxt{\colored [g=3D.7, a=3D1, t=3D.2]{\T}},(i*1.1mm,0cm)) rotatedaround ((i*1.1mm,0cm),i*2); endfor; \stopMPcode \stopmode \stoptext --MP_/dRSAUYBJmJF_1AIKLWPv99D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --MP_/dRSAUYBJmJF_1AIKLWPv99D--