ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Ampersand in Metapost
@ 2010-05-13 19:18 Marco
  2010-05-13 20:58 ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Marco @ 2010-05-13 19:18 UTC (permalink / raw)
  To: ntg-context

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}{&


Marco


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 19:18 Ampersand in Metapost Marco
@ 2010-05-13 20:58 ` Hans Hagen
  2010-05-13 21:40   ` Mojca Miklavec
  2010-05-13 21:45   ` Marco
  0 siblings, 2 replies; 15+ messages in thread
From: Hans Hagen @ 2010-05-13 20:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

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


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 20:58 ` Hans Hagen
@ 2010-05-13 21:40   ` Mojca Miklavec
  2010-05-13 21:45   ` Marco
  1 sibling, 0 replies; 15+ messages in thread
From: Mojca Miklavec @ 2010-05-13 21:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

On Thu, May 13, 2010 at 22:58, Hans Hagen wrote:
> On 13-5-2010 9:18, Marco wrote:
>>
>> 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

Or maybe \letterampersand if you want to get the desired glyph :)

Alternatively you could try to use
    label(\sometxt{\&},origin);

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 20:58 ` Hans Hagen
  2010-05-13 21:40   ` Mojca Miklavec
@ 2010-05-13 21:45   ` Marco
  2010-05-13 22:37     ` Mojca Miklavec
  1 sibling, 1 reply; 15+ messages in thread
From: Marco @ 2010-05-13 21:45 UTC (permalink / raw)
  To: ntg-context

On Thu, 13 May 2010 22:58:46 +0200, Hans Hagen <pragma@wxs.nl> 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).

I discovered that the ugly \char`\& works as a workaround (or is this
the final solution?).
 
Thanks for your help.
Marco


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 21:45   ` Marco
@ 2010-05-13 22:37     ` Mojca Miklavec
  2010-05-14  1:07       ` Aditya Mahajan
  2010-05-14 10:06       ` Marco
  0 siblings, 2 replies; 15+ messages in thread
From: Mojca Miklavec @ 2010-05-13 22:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, May 13, 2010 at 23:45, Marco <netuse@lavabit.com> wrote:
> On Thu, 13 May 2010 22:58:46 +0200, Hans Hagen <pragma@wxs.nl> 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 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.

Mojca

PS: I would say: better use \sometxt which is far more reliable unless
you have to use textext to do string manipulation.
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 22:37     ` Mojca Miklavec
@ 2010-05-14  1:07       ` Aditya Mahajan
  2010-05-14 10:09         ` Marco
  2010-05-14 13:32         ` Hans Hagen
  2010-05-14 10:06       ` Marco
  1 sibling, 2 replies; 15+ messages in thread
From: Aditya Mahajan @ 2010-05-14  1:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1451 bytes --]

On Fri, 14 May 2010, Mojca Miklavec wrote:

> On Thu, May 13, 2010 at 23:45, Marco <netuse@lavabit.com> wrote:
>> On Thu, 13 May 2010 22:58:46 +0200, Hans Hagen <pragma@wxs.nl> 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 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.

So, should all the \letter... commands (basically anything generated from 
char-def.lua) be unexpandable?

You can also try \noexpand\letterampersand

Aditya

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-13 22:37     ` Mojca Miklavec
  2010-05-14  1:07       ` Aditya Mahajan
@ 2010-05-14 10:06       ` Marco
  2010-05-14 10:39         ` Hans Hagen
                           ` (2 more replies)
  1 sibling, 3 replies; 15+ messages in thread
From: Marco @ 2010-05-14 10:06 UTC (permalink / raw)
  To: ntg-context

[-- Attachment #1: Type: text/plain, Size: 4957 bytes --]

On Fri, 14 May 2010 00:37:44 +0200, Mojca Miklavec
<mojca.miklavec.lists@gmail.com> wrote:

> On Thu, May 13, 2010 at 23:45, Marco <netuse@lavabit.com> wrote:
> > On Thu, 13 May 2010 22:58:46 +0200, Hans Hagen <pragma@wxs.nl>
> > 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: t.tex --]
[-- Type: text/x-tex, Size: 1388 bytes --]

\def\oklepaj#1{\left(#1\right)}
\def\t{\dot N(t)=
  A\oklepaj{\exp\oklepaj{-\frac{t-t_0}{τ_{\text{eksp.}}}}-\exp
    \oklepaj{-\frac{t-t_0}{τ_{\text{fast}}}}}+
  B\oklepaj{\exp\oklepaj{-\frac{t-t_0}{τ_{\text{eksp.}}}}-\exp
    \oklepaj{-\frac{t-t_0}{τ_{\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=0 upto 100:
  label(textext("\colored [b=.7, a=1, t=.3]{\T}"),(i*1mm,0cm))
    rotatedaround ((i*1mm,0cm),i*2);
  label(textext("\colored [g=.7, a=1, t=.2]{\T}"),(i*1.1mm,0cm))
    rotatedaround ((i*1.1mm,0cm),i*2);
endfor;
\stopMPcode
\stopmode

\startmode [sometxt]
\startMPcode
for i=0 upto 100:
  label(\sometxt{\colored [b=.7, a=1, t=.3]{\T}},(i*1mm,0cm))
    rotatedaround ((i*1mm,0cm),i*2);
  label(\sometxt{\colored [g=.7, a=1, t=.2]{\T}},(i*1.1mm,0cm))
    rotatedaround ((i*1.1mm,0cm),i*2);
endfor;
\stopMPcode
\stopmode
\stoptext

[-- Attachment #3: Type: text/plain, Size: 486 bytes --]

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14  1:07       ` Aditya Mahajan
@ 2010-05-14 10:09         ` Marco
  2010-05-14 13:32         ` Hans Hagen
  1 sibling, 0 replies; 15+ messages in thread
From: Marco @ 2010-05-14 10:09 UTC (permalink / raw)
  To: ntg-context

> > - label(textext("\letterbackslash\letterampersand"),origin);
> > - label(textext("\letterbackslash\&"),origin);
> >
> > 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.
> 
> So, should all the \letter... commands (basically anything generated
> from char-def.lua) be unexpandable?
What are the disadvantages of unexpandable commands? I'm not an expert.
Why is this not done by default if it works better?

> You can also try \noexpand\letterampersand
Produces compile error.

Marco


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 10:06       ` Marco
@ 2010-05-14 10:39         ` Hans Hagen
  2010-05-14 10:44         ` Hans Hagen
  2010-05-14 15:20         ` Mojca Miklavec
  2 siblings, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2010-05-14 10:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

On 14-5-2010 12:06, Marco wrote:

>   iii) Why should I better use \sometxt?

sometxt was introduced in mkii to avoid text processing mp, i.e. it is 
done at the context end in the current run and mp only gets dimensions; 
so, it avoids the nested tex run

in mkii there is some more trickery and much showed up whem for in 
instance Mojca wanted gnuplot to spit out mp

> 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.

in mkiv textext is implemented differently; because we use mplib, 
processing time is less an issue anyway

> 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

in mkiv there should be no big difference as it all boils down to the 
same (sometxt has a command applied which textext doesn't)

> 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.

you use mkiv

> -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.

th emkii variant has some more limitations than the mkiv version

> -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.

don't expect mkii and mkiv to be 100% compatible in this area (mkii is 
somewhat stretching things to the limit)

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 10:06       ` Marco
  2010-05-14 10:39         ` Hans Hagen
@ 2010-05-14 10:44         ` Hans Hagen
  2010-05-14 11:45           ` Marco
  2010-05-14 15:20         ` Mojca Miklavec
  2 siblings, 1 reply; 15+ messages in thread
From: Hans Hagen @ 2010-05-14 10:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

On 14-5-2010 12:06, Marco wrote:
> 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;

because transparent overloads the mechanism that sometxt (textext) uses 
for passing info to tex and back ... maybe some future version will 
handle that (just comment the withcolor)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 10:44         ` Hans Hagen
@ 2010-05-14 11:45           ` Marco
  2010-05-14 12:17             ` Hans Hagen
  0 siblings, 1 reply; 15+ messages in thread
From: Marco @ 2010-05-14 11:45 UTC (permalink / raw)
  To: ntg-context

On Fri, 14 May 2010 12:44:47 +0200, Hans Hagen <pragma@wxs.nl> wrote:

> On 14-5-2010 12:06, Marco wrote:
> > 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;
> 
> because transparent overloads the mechanism that sometxt (textext)
> uses for passing info to tex and back ... maybe some future version
> will handle that (just comment the withcolor)
Ah, I see. I don't need it at the moment as I can use textext with the
code you provided.

Thanks for your explanation. I hope I'm not completely mistaken if I
conclude, that there are some advantages when using \sometxt in MkII,
but in MkIV both variants are basically the same.

Marco


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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 11:45           ` Marco
@ 2010-05-14 12:17             ` Hans Hagen
  0 siblings, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2010-05-14 12:17 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Marco

On 14-5-2010 1:45, Marco wrote:
> On Fri, 14 May 2010 12:44:47 +0200, Hans Hagen<pragma@wxs.nl>  wrote:
>
>> On 14-5-2010 12:06, Marco wrote:
>>> 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;
>>
>> because transparent overloads the mechanism that sometxt (textext)
>> uses for passing info to tex and back ... maybe some future version
>> will handle that (just comment the withcolor)
> Ah, I see. I don't need it at the moment as I can use textext with the
> code you provided.
>
> Thanks for your explanation. I hope I'm not completely mistaken if I
> conclude, that there are some advantages when using \sometxt in MkII,
> but in MkIV both variants are basically the same.

indeed

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14  1:07       ` Aditya Mahajan
  2010-05-14 10:09         ` Marco
@ 2010-05-14 13:32         ` Hans Hagen
  1 sibling, 0 replies; 15+ messages in thread
From: Hans Hagen @ 2010-05-14 13:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 14-5-2010 3:07, Aditya Mahajan wrote:

>> 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.
>
> So, should all the \letter... commands (basically anything generated
> from char-def.lua) be unexpandable?
>
> You can also try \noexpand\letterampersand

The problem is that some definitions, likt \& and \# expand to letters 
which is needed when used in mp itself. That also means that resetting 
them to their normal meaning is not possible as textext is handled in mp 
and then already an \& has become a &.

As & is rather common, I added it to \nonknuthmode, so you can say:

\nonknuthmode

\starttext
     \startMPcode
         draw textext("Underscores, Superscripts & Ampersands" & "?") ;
     \stopMPcode
\stoptext

Aditya: I also changed the definition of \_ in math ... it now looks 
better when used in script(scripts) .. see \fakeunderscore.

Hans



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 10:06       ` Marco
  2010-05-14 10:39         ` Hans Hagen
  2010-05-14 10:44         ` Hans Hagen
@ 2010-05-14 15:20         ` Mojca Miklavec
  2010-05-14 19:34           ` Marco
  2 siblings, 1 reply; 15+ messages in thread
From: Mojca Miklavec @ 2010-05-14 15:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Fri, May 14, 2010 at 12:06, Marco wrote:
> On Fri, 14 May 2010 00:37:44 +0200, Mojca Miklavec wrote:
>
>> 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?

It's mostly about MkII. In MKIV it should work, but it doesn't make
such a huge difference since textext works as well as \sometxt in
MkII. textext in MkII can sometimes be very inefficient.

>  ii) Is it still up-to-date?

Apart from a recently reported bug I don't know of any changes in
MkII, but maybe I should write a few words about MkIV.

>  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.

Dynamic text counts as "feature" for me, not as "something that'"

> 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

As already mentioned by Hans, the only difference,

> Here are my results:
>
> -There is one obvious reason: speed
>
> 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.

For gnuplot-generated graphics compile time has been reduced from 10
minutes to 20 seconds. But that's another story (many graphics, many
text labels inside each graphic; textext was not optimized).

> -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.

But that's only true with MkIV. In MKII it's another story.

> -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.

Many math expressions have later been made unexpandable and started
working, but it felt like a neverending story. Almost the same as the
example that you were asking for.

> I know, your MyWay is old. Maybe some things are fixed now. But I don't see
> many advantages for me using it.

If you are using MkIV and don't run into the same problem again, there
is hardly a difference.

> 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?
Yes, in MkII. In MkIV Hans wanted to take a different approach.
> \chardef\TeXtextcolormode\zerocount

> % 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;

Hans replied.

All in all - true, the most difference is seen in MkII.

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Ampersand in Metapost
  2010-05-14 15:20         ` Mojca Miklavec
@ 2010-05-14 19:34           ` Marco
  0 siblings, 0 replies; 15+ messages in thread
From: Marco @ 2010-05-14 19:34 UTC (permalink / raw)
  To: ntg-context

On Fri, 14 May 2010 17:20:35 +0200, Mojca Miklavec wrote:

[...]
> > Here are my results:
> >
> > -There is one obvious reason: speed
> >
> > 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.
> 
> For gnuplot-generated graphics compile time has been reduced from 10
> minutes to 20 seconds. But that's another story (many graphics, many
> text labels inside each graphic; textext was not optimized).
Wow! That's what I'd call optimization. Now I understand your opinion and
your advice to use \sometxt (in MkII).

> > -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.
> 
> But that's only true with MkIV. In MKII it's another story.
Don't know. I don't use it.

> > -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.
> 
> Many math expressions have later been made unexpandable and started
> working, but it felt like a neverending story. Almost the same as the
> example that you were asking for.
I think I can comprehend the problems you had with textext.

> > 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?
> Yes, in MkII. In MkIV Hans wanted to take a different approach.
> > \chardef\TeXtextcolormode\zerocount
> 
> > % 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;
> 
> Hans replied.
Yes. I will use textext for this job.

> 
> > I know, your MyWay is old. Maybe some things are fixed now. But I
> > don't see many advantages for me using it.
> 
> If you are using MkIV and don't run into the same problem again, there
> is hardly a difference.
> 

I conclude by saying that \sometxt ist first choice if using MkII. In MkIV
first choice is textext.

Thanks for your reply (and your MyWay), it helped me get some insight into
proper use of text in metapost.

Marco


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-05-14 19:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-13 19:18 Ampersand in Metapost Marco
2010-05-13 20:58 ` Hans Hagen
2010-05-13 21:40   ` Mojca Miklavec
2010-05-13 21:45   ` Marco
2010-05-13 22:37     ` Mojca Miklavec
2010-05-14  1:07       ` Aditya Mahajan
2010-05-14 10:09         ` Marco
2010-05-14 13:32         ` Hans Hagen
2010-05-14 10:06       ` Marco
2010-05-14 10:39         ` Hans Hagen
2010-05-14 10:44         ` Hans Hagen
2010-05-14 11:45           ` Marco
2010-05-14 12:17             ` Hans Hagen
2010-05-14 15:20         ` Mojca Miklavec
2010-05-14 19:34           ` Marco

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).