ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Wrong MetaPost text output
@ 2019-08-11 16:09 Henri Menke
  2019-08-11 17:30 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Henri Menke @ 2019-08-11 16:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear devs,

There seems to be a bug in the MetaPost integration of ConTeXt.  The MWE
below should produce three different labels “dummy foo bar” but instead
produces “bar bar bar”.  The same example works correctly in plain
MetaPost.  Originally reported on

    https://tex.stackexchange.com/questions/503773/strange-behaviour-of-the-btex-etex-construct

Cheers, Henri

---

\starttext
\startMPpage
def drawtest(expr i) = %i is not used here
    draw btex dummy etex shifted (0,0);
    draw btex foo   etex shifted (1.5cm,0);
    draw btex bar   etex shifted (3cm,0);
enddef;
drawtest(5);
\stopMPpage
\stoptext
___________________________________________________________________________________
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
___________________________________________________________________________________

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

* Re: Wrong MetaPost text output
  2019-08-11 16:09 Wrong MetaPost text output Henri Menke
@ 2019-08-11 17:30 ` Hans Hagen
       [not found]   ` <02a522d1-29a6-09f2-2818-8007f2bf088c@xs4all.nl>
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2019-08-11 17:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henri Menke

On 8/11/2019 6:09 PM, Henri Menke wrote:
> Dear devs,
> 
> There seems to be a bug in the MetaPost integration of ConTeXt.  The MWE
> below should produce three different labels “dummy foo bar” but instead
> produces “bar bar bar”.  The same example works correctly in plain
> MetaPost.  Originally reported on
> 
>      https://tex.stackexchange.com/questions/503773/strange-behaviour-of-the-btex-etex-construct
> 
> Cheers, Henri
> 
> ---
> 
> \starttext
> \startMPpage
> def drawtest(expr i) = %i is not used here
>      draw btex dummy etex shifted (0,0);
>      draw btex foo   etex shifted (1.5cm,0);
>      draw btex bar   etex shifted (3cm,0);
> enddef;
> drawtest(5);
> \stopMPpage
> \stoptext
It's not a really bug but a side effect. When metapost parses btex .. 
etex it immediately replaces its content. In mpost the program that is 
hardcoded as 'call out to tex and convert the dvi result into a 
picture'. This parsing is not 'delayed' by wrapping in macro.

So in this case, what happens is that where normally there is some 
interplay between context and the library, this kind of gets messed up. 
Using btex inside a macro body is just a bad idea.

def drawtest(expr i) = %i is not used here
       draw textext("dummy") shifted (0,0);
       draw textext("foo")   shifted (1.5cm,0);
       draw textext("bar")   shifted (3cm,0);
enddef;

works fine because it is not replaced in the macro body when parsed.

In context lmtx I will give a warning when "btex .. etex" is used inside 
a macro definition. Actually btex/etex is just supported in context as a 
kind of 'service' (we could just drop it).

Anyway, you can advice not to use "btex .. etex" but textext instead. As 
with all things tex (and mp) with some hasty programming much can be 
solved but in this case it's not worth the effort and for sure it will 
bring up other side effects.

(In a similar fashion it's not a good idea to have global textexts 
because there are local stored for them but in that case one can enforce 
a persistent textext if needed.)

Hans

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

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

* Re: Wrong MetaPost text output
       [not found]   ` <02a522d1-29a6-09f2-2818-8007f2bf088c@xs4all.nl>
@ 2019-08-11 18:12     ` Henri Menke
  2019-08-11 20:19       ` Alan Braslau
  0 siblings, 1 reply; 4+ messages in thread
From: Henri Menke @ 2019-08-11 18:12 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 8/11/19 10:51 AM, Hans Hagen wrote:
> I'll do this (lmtx):
> 
> metapost        > use 'textext(.....)' instead of 'btex ..... etex'
> metapost        > rewrapping btex ... etex at the outer level [[dummy]]
> metapost        > rewrapping btex ... etex at the outer level [["foo"]]
> metapost        > rewrapping btex ... etex at the outer level [[bar]]
> 
> when this is seen
> 
> def drawtest =
>     draw btex dummy etex shifted (0,0);
>     draw btex "foo" etex shifted (1.5cm,0);
>     draw btex bar   etex shifted (3cm,0);
> enddef;
> 
> rewrapping can work kind of ok, but it is still more fragile than textext (which can also be used with variables and concatinated strings and such, which probably is what one wants to do in macros)

Thank you for the quick repsonse.  This looks good to me.  However,
could you tell me a way to get the correct baseline with textext?  When
I use

    \startMPpage
    draw btex dummy etex shifted (0,0);
    draw btex foo   etex shifted (1.5cm,0);
    \stopMPpage

the baseline is the one that I would expect from TeX, i.e. at the depth
of the “y” is removed or otherwise correctly accounted for.  In contrast
when I use

    \startMPpage
    draw textext("dummy") shifted (0,0);
    draw textext("foo")   shifted (1.5cm,0);
    \stopMPpage

the baseline will be below the depth of the “y” which is sometimes
unwanted.

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

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

* Re: Wrong MetaPost text output
  2019-08-11 18:12     ` Henri Menke
@ 2019-08-11 20:19       ` Alan Braslau
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Braslau @ 2019-08-11 20:19 UTC (permalink / raw)
  To: Henri Menke; +Cc: mailing list for ConTeXt users

On Sun, 11 Aug 2019 11:12:55 -0700
Henri Menke <henrimenke@gmail.com> wrote:

> Thank you for the quick repsonse.  This looks good to me.  However,
> could you tell me a way to get the correct baseline with textext?  When
> I use
> 
>     \startMPpage
>     draw btex dummy etex shifted (0,0);
>     draw btex foo   etex shifted (1.5cm,0);
>     \stopMPpage
> 
> the baseline is the one that I would expect from TeX, i.e. at the depth
> of the “y” is removed or otherwise correctly accounted for.  In contrast
> when I use
> 
>     \startMPpage
>     draw textext("dummy") shifted (0,0);
>     draw textext("foo")   shifted (1.5cm,0);
>     \stopMPpage
> 
> the baseline will be below the depth of the “y” which is sometimes
> unwanted.

textext() is actually textext@#()
so you can use textext.top() for example
to put the *bottom* of the text bounding box at y=0.
Without any @# suffix, the text bounding box gets centered at y=0.

Metafun has a few *new* suffixes defined, so you can use
textext.d(), textext.dlft(), textext.drt(), I BELIEVE,
to position with respect to the tex baseline.
(you need to check this).

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

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

end of thread, other threads:[~2019-08-11 20:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11 16:09 Wrong MetaPost text output Henri Menke
2019-08-11 17:30 ` Hans Hagen
     [not found]   ` <02a522d1-29a6-09f2-2818-8007f2bf088c@xs4all.nl>
2019-08-11 18:12     ` Henri Menke
2019-08-11 20:19       ` Alan Braslau

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