Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-24 Thread Stefan Müller

Wikified: http://wiki.contextgarden.net/MetaObj_and_Labels
Please update/change as appropriate.

Best regards,
Stefan
___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-23 Thread Stefan Müller

On 22.01.2011 17:30, Aditya Mahajan wrote:

On Sat, 22 Jan 2011, Stefan Müller wrote:


So its either using text or using metaobj? Too bad, metaobj is quite
fun... I still hope you guys can fix this, but it's not urgent (to me).

Anyway, what does the [+] after \startMPinclusions? I did not find
documentation for that on the wiki.


\startMPinclusions
path a ;
\stopMPinclusions

\startMPinclusions
a := (0,0) -- (1cm,0) ;
\stopMPinclusions

will fail, because the second inclusions overwrites the first. If you
use [+], then the second inclusions in appended after the first.


Thank you for the explanation. So if I only have one inclusions 
section it doesn't matter?



Just as a wild guess I tested the example below today, trying to make
use of the things Aditya said, but to no avail.


The trick is to ensure that the offending code (assignObj) is not run
twice.


Your example works perfect. Many thanks for that as well. I didn't 
realize, that assignObj is causing the trouble, but now it's obvious. 
I'm just curious: the MP-code is only run twice by context if it 
contains labels, right? Otherwise I don't understand why the assignObj 
isn't always failing.



@Hans, can we have a `trialtypesetting` for MP code?

Aditya


Stefan
___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-23 Thread Stefan Müller

On 23.01.2011 12:40, Stefan Müller wrote:

On 22.01.2011 17:30, Aditya Mahajan wrote:

On Sat, 22 Jan 2011, Stefan Müller wrote:


So its either using text or using metaobj? Too bad, metaobj is quite
fun... I still hope you guys can fix this, but it's not urgent (to me).

Anyway, what does the [+] after \startMPinclusions? I did not find
documentation for that on the wiki.


\startMPinclusions
path a ;
\stopMPinclusions

\startMPinclusions
a := (0,0) -- (1cm,0) ;
\stopMPinclusions

will fail, because the second inclusions overwrites the first. If you
use [+], then the second inclusions in appended after the first.


Thank you for the explanation. So if I only have one inclusions
section it doesn't matter?


Just as a wild guess I tested the example below today, trying to make
use of the things Aditya said, but to no avail.


The trick is to ensure that the offending code (assignObj) is not run
twice.


Your example works perfect. Many thanks for that as well. I didn't
realize, that assignObj is causing the trouble, but now it's obvious.
I'm just curious: the MP-code is only run twice by context if it
contains labels, right? Otherwise I don't understand why the assignObj
isn't always failing.


Sorry for double posting... The method with if not flag is a bit 
arkward, because assignObj isn't the only problem. rotateObj(s, 90) 
would rotate the object 180 degrees instead of 90; when defining the 
relation between several objects some equations may became redundant (my 
script is rather complex and I'm not sure why some of the equations 
cause trouble).


Stefan
___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-23 Thread Aditya Mahajan

On Sun, 23 Jan 2011, Stefan Müller wrote:

Sorry for double posting... The method with if not flag is a bit arkward, 
because assignObj isn't the only problem. rotateObj(s, 90) would rotate the 
object 180 degrees instead of 90; when defining the relation between several 
objects some equations may became redundant (my script is rather complex and 
I'm not sure why some of the equations cause trouble).


Depends on the internal implementation of MetaObj (I have not looked at 
that). You can try to iteratively add stuff and see what breaks, and then 
add if not flag around them.


Sorry, but I do not know a more elegant way around this. In the worst 
case, you can switch to MkII to draw your figures :-\


Aditya___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-23 Thread Stefan Müller



On 23.01.2011 18:22, Aditya Mahajan wrote:

On Sun, 23 Jan 2011, Stefan Müller wrote:


Sorry for double posting... The method with if not flag is a bit
arkward, because assignObj isn't the only problem. rotateObj(s, 90)
would rotate the object 180 degrees instead of 90; when defining the
relation between several objects some equations may became redundant
(my script is rather complex and I'm not sure why some of the
equations cause trouble).


Depends on the internal implementation of MetaObj (I have not looked at
that). You can try to iteratively add stuff and see what breaks, and
then add if not flag around them.


Okay, that's what I do now. It seems it's savest to just put if not 
flags around the object constructors, object transformations and 
definition of inter-object relations. This does not produce graphical 
output, so it should be save to run it only once.



Sorry, but I do not know a more elegant way around this. In the worst
case, you can switch to MkII to draw your figures :-\

Aditya


Thank you very much!
Stefan.
___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-22 Thread Stefan Müller
So its either using text or using metaobj? Too bad, metaobj is quite 
fun... I still hope you guys can fix this, but it's not urgent (to me).


Just as a wild guess I tested the example below today, trying to make 
use of the things Aditya said, but to no avail. Anyway, what does the 
[+] after \startMPinclusions? I did not find documentation for that on 
the wiki.


Best regards,
Stefan.

\startMPinclusions
input metaobj;
boolean flag; flag := false;
\stopMPinclusions

\starttext
\startMPpage
vardef newSegment@\#=
assignObj(@\#,Segment);
ObjPoint a,b;
ObjCode @\#b-@\#a=(1cm,2cm);
enddef;

def drawSegment(suffix n)=
draw n.a--n.b;
enddef;

newSegment.s;
s.a=origin;
drawObj(s);

if flag: draw btex A etex; fi;

flag := true;
\stopMPpage
\stoptext

On 22.01.2011 02:38, Aditya Mahajan wrote:

On Sat, 22 Jan 2011, Hans Hagen wrote:


On 20-1-2011 9:59, Taco Hoekwater wrote:

On 01/18/2011 01:17 PM, Stefan Müller wrote:

Hi list,

I'm having some trouble with MetaPost in general and MetaObj in
particular.


The core problem is that context mkiv loads the metapost code twice
when you are typesetting labels, and that causes trouble for metaobj
which does not expect that. Sorry, I do not know of any solution.
Maybe Hans does?


not immediately


A suggestion: Currently, ConTeXt does not clear the state of mplib at
the end of each graphic. For example

\starttext
\startMPcode
path p;
p := fullcircle scaled 4cm ;
\stopMPcode

\startMPcode
draw p ;
\stopMPcode
\stoptext

draws a circle. I am not convinced that this is useful. Resetting the
state of
mplib after each graphic might be better. Then, after the first run, you
could
just set the value of mptopdf.texts[..], reset the state of mplib, and
then draw
the graphic in the second run.

This approach will have less surprises. For example, in simpleslides
module, we
provide a mechanism for highlighting a part of a picture using arrows.
These
arrows are thick (typically 5bp). In order to scale the arrows
correctly, we
set:

autoarrows := true ;

However, in the current implementation, this effect is global. It took a
while
to realize that this messed up all the figures with arrows that I was
drawing in
a presentation (where autoarrows := false) is better.

Not resetting the mplib state also has advantages. For example, it
allows an
easy way to do something on the second path (trivial example, but there are
cases when something like this makes the code much shorter):

\startMPinclusions[+]
newboolean flag ;
flag := false ;
\stopMPinclusions

\starttext
\startMPpage
if flag :
fill boundary withcolor 0.5[blue,white] ;
else :
path boundary ;
fi ;

path A, B;

A := fullsquare scaled 3cm ;
B := fullsquare scaled 3cm shifted (5cm,0) ;

fill A withcolor white ;
fill B withcolor white ;

draw A ; draw btex A etex ;
draw B ; draw btex B etex shifted (5cm,0) ;

boundary := (boundingbox currentpicture) enlarged 3mm ;

flag := true ;

\stopMPpage
\stoptext

So, perhaps, we can have a `reset` key to \defineMPinstance, and let the
user
choose whether to reset after each graphic or not. If `reset=yes` is
chosen,
then such errors would not occur.

Aditya



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

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


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-22 Thread Aditya Mahajan

On Sat, 22 Jan 2011, Stefan Müller wrote:

So its either using text or using metaobj? Too bad, metaobj is quite fun... I 
still hope you guys can fix this, but it's not urgent (to me).


Anyway, what does the [+] after 
\startMPinclusions? I did not find documentation for that on the wiki.


\startMPinclusions
  path a ;
\stopMPinclusions

\startMPinclusions
  a := (0,0) -- (1cm,0) ;
\stopMPinclusions

will fail, because the second inclusions overwrites the first. If you use 
[+], then the second inclusions in appended after the first.


Just as a wild guess I tested the example below today, trying to make use of 
the things Aditya said, but to no avail.


The trick is to ensure that the offending code (assignObj) is not run 
twice.


\startMPinclusions[+]
  input metaobj;
  boolean flag; flag := false;
\stopMPinclusions

\startMPdefinitions
  vardef newSegment@\#=
if not flag :
  assignObj(@\#,Segment);
  ObjPoint a,b;
  ObjCode @\#b-@\#a=(1cm,2cm);
fi ;
  enddef;

  def drawSegment(suffix n)=
draw n.a--n.b;
draw btex \tt \overbar{E} etex shifted n.a; % 1
  enddef;
\stopMPdefinitions

\starttext
\startMPpage
  newSegment.s;
  ObjLabel.s(btex hello! etex) labpoint(a); % 2
  s.a=origin;
  drawObj(s);
  flag := true ;
\stopMPpage
\stoptext

@Hans, can we have a `trialtypesetting` for MP code?

Aditya___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-21 Thread Hans Hagen

On 20-1-2011 9:59, Taco Hoekwater wrote:

On 01/18/2011 01:17 PM, Stefan Müller wrote:

Hi list,

I'm having some trouble with MetaPost in general and MetaObj in
particular.


The core problem is that context mkiv loads the metapost code twice
when you are typesetting labels, and that causes trouble for metaobj
which does not expect that. Sorry, I do not know of any solution.
Maybe Hans does?


not immediately

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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-21 Thread Aditya Mahajan

On Sat, 22 Jan 2011, Hans Hagen wrote:


On 20-1-2011 9:59, Taco Hoekwater wrote:

On 01/18/2011 01:17 PM, Stefan Müller wrote:

Hi list,

I'm having some trouble with MetaPost in general and MetaObj in
particular.


The core problem is that context mkiv loads the metapost code twice
when you are typesetting labels, and that causes trouble for metaobj
which does not expect that. Sorry, I do not know of any solution.
Maybe Hans does?


not immediately


A suggestion: Currently, ConTeXt does not clear the state 
of mplib at the end of each graphic. For example


\starttext
\startMPcode
  path p;
  p := fullcircle scaled 4cm ;
\stopMPcode

\startMPcode
  draw p ;
\stopMPcode
\stoptext

draws a circle. I am not convinced that this is useful. Resetting the state of
mplib after each graphic might be better. Then, after the first run, you could
just set the value of mptopdf.texts[..], reset the state of mplib, and then draw
the graphic in the second run.

This approach will have less surprises. For example, in simpleslides module, we
provide a mechanism for highlighting a part of a picture using arrows. These
arrows are thick (typically 5bp). In order to scale the arrows correctly, we
set:

  autoarrows := true ;

However, in the current implementation, this effect is global. It took a while
to realize that this messed up all the figures with arrows that I was drawing in
a presentation (where autoarrows := false) is better.

Not resetting the mplib state also has advantages. For example, it allows an
easy way to do something on the second path (trivial example, but there are
cases when something like this makes the code much shorter):

\startMPinclusions[+]
  newboolean flag ;
  flag := false ;
\stopMPinclusions

\starttext
\startMPpage
  if flag :
fill boundary withcolor 0.5[blue,white] ;
  else :
path boundary ;
  fi ;

  path A, B;

  A := fullsquare scaled 3cm ;
  B := fullsquare scaled 3cm shifted (5cm,0) ;

  fill A withcolor white ;
  fill B withcolor white ;

  draw A ; draw btex A etex ;
  draw B ; draw btex B etex shifted (5cm,0) ;

  boundary := (boundingbox currentpicture) enlarged 3mm ;

  flag := true ;

\stopMPpage
\stoptext

So, perhaps, we can have a `reset` key to \defineMPinstance, and let the user
choose whether to reset after each graphic or not. If `reset=yes` is chosen,
then such errors would not occur.

Aditya___
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
___


Re: [NTG-context] Labels in MetaPost (MetaObj)

2011-01-20 Thread Taco Hoekwater

On 01/18/2011 01:17 PM, Stefan Müller wrote:

Hi list,

I'm having some trouble with MetaPost in general and MetaObj in
particular.


The core problem is that context mkiv loads the metapost code twice
when you are typesetting labels, and that causes trouble for metaobj
which does not expect that. Sorry, I do not know of any solution.
Maybe Hans does?

Best wishes,
Taco
___
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
___


[NTG-context] Labels in MetaPost (MetaObj)

2011-01-18 Thread Stefan Müller

Hi list,

I'm having some trouble with MetaPost in general and MetaObj in 
particular. I hope someone on this list can assist me here. I'm trying 
to run the appended ConTeXt file with a quite simple object Segment 
(from the manual [1], section 2.1). This script works fine as it is. I 
wanted to add a simple TeX label (\tt \overbar{E}) to the drawing 
macro, but failed.


When including the line marked with % 1 the TeX run fails. I don't 
understand why.


The line with % 2 is taken frome the metaobj manual (section 5.8) [1], 
but including this doesn't work either.


It would be great if someone could tell me what's wrong with the mp-code 
below and explain how to place a (TeX) label inside a metaobj object.


Thanks in advance,
Stefan.


[1] http://tex.loria.fr/prod-graph/momanual.pdf

PS: Both variants fail with mp error messages like this:

mplibmp terminal: ! Inconsistent equation (off by 1).
to be read again
   ;
assignObj-(SUFFIX0)=incr(nObj_);

iname_[(SUFFIX0)]=str(SUFFIX0);addclass_((S...

newSegment-...roup.assignObj((SUFFIX2),Segment)

;ObjPoint.a,b;ObjCode@##b...
to be read again
   ;
* ...ar {E}) shifted n.a; enddef; newSegment.s;
   s.a=origin; 
drawObj(s); ;

! Redundant equation.
to be read again
   ;
assignObj-...bj_);iname_[(SUFFIX0)]=str(SUFFIX0);

addclass_((SUFFIX0),(EXPR1...

newSegment-...roup.assignObj((SUFFIX2),Segment)

;ObjPoint.a,b;ObjCode@##b...


===
\startMPinclusions
input metaobj;
\stopMPinclusions

\startMPpage
vardef newSegment@#=
assignObj(@#,Segment);
ObjPoint a,b;
ObjCode @#b-@#a=(1cm,2cm);
enddef;

def drawSegment(suffix n)=
draw n.a--n.b;
%   draw btex \tt \overbar{E} etex shifted n.a; % 1
enddef;

newSegment.s;
%   ObjLabel.s(btex hello! etex) labpoint(a); % 2
s.a=origin;
drawObj(s);
\stopMPpage
===
___
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
___