On Fri, 14 May 2010 00:37:44 +0200, Mojca Miklavec
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 \& % OK \startMPcode label(textext("\&"),origin); % produces error \stopMPcode \stoptext
The compile time error message is as follows: ! Misplaced alignment tab character&. l.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).
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 know, 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 »string manipulation«. I've read your MyWay on \sometxt. Brilliant piece of doc. 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 »more reliable«? 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 »t.tex« 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=textext 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=sometxt 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. 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 work. -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 »withcolor« to work? \chardef\TeXtextcolormode\zerocount \setupbodyfont [sans,36pt] \starttext \startMPcode numeric r, g, b ; def ran= r := uniformdeviate 1 ; g := uniformdeviate 1 ; b := uniformdeviate 1 ; enddef; % Works as expected for i=0 downto -3: ran; label(textext("\bold\colored[r=" & decimal(r) & ",g=" & decimal(g) & ",b=" & decimal(b) & ",a=1, t=.2]{Test}"), (7cm,-1cm)) rotatedaround ((7cm,-1cm),i*20); endfor; % Produces empty rectangles for i=0 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