Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to use MetaObj to arrange some diagrams. I have some nice, color MetaPost drawings of components for my diagrams.

I create the picture objects like this:

input metaobj;

def picphone =
  begingroup;
    save pic;
    picture pic;
    pic := image(
      % lots of drawing commands generated by pstoedit
      drawoptions(); % <-- I added this
    );
    pic
  endgroup
enddef

beginfig(1);
begingroup;
  picture phone;
  phone := picphone scaled 0.1;
  newBox.alfa(phone);
  newBox.bravo(phone);

  %
  % equations for positioning
  %

  drawObj(alfa);
  drawObj(bravo);
endgroup;
endfig;

I expected to see my beautiful phones, but instead saw black rectangles. A little log reading made me realize that pictures inside MetaObj Box objects are drawn with this vardef:

vardef drawPicture@#(suffix p) text options=
  draw @#p transformed @#ctransform_ shifted @#p.off options
           withcolor OptionValue.@#("picturecolor");
enddef;

which basically turns into draw ... withcolor black.

So, I changed metaobj.mp (a copy in a local subdirectory) to be this:

vardef drawPicture@#(suffix p) text options=
  draw @#p transformed @#ctransform_ shifted @#p.off options
    if boolean OptionValue.@#("picturecolor") :
      ;
    else:
      withcolor OptionValue.@#("picturecolor");
    fi;
enddef;

and I added this:

setObjectDefaultOption("Box")("picturecolor")(false);

to my file.

Is there a way I could have done this without modifying metaobj.mp? Am I misusing (abusing?) MetaObj? Should I use something different to lay out my objects?

[Aside: I'm even more of a MetaPost novice than I am a TeX one, so please forgive any foolishness I've exhibited.]

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The most convenient way is to prepare a file metaobj-x.mp containing

vardef drawPicture@#(suffix p) text options=
  draw @#p transformed @#ctransform_ shifted @#p.off options
    if boolean OptionValue.@#("picturecolor") :
      ;
    else:
      withcolor OptionValue.@#("picturecolor");
    fi;
enddef;

and to start your Metapost file with

input metaobj;
input metaobj-x;

so that the new definition of drawPicture will overwrite the old one. Where to put metaobj-x? It depends on many factors. If you're going to use this modified definition only for a project, then saving the file in the same directory as the Metapost files of the project is fine. If you plan to use it for many projects, then the "personal TeX tree" is the best place; on GNU/Linux systems it's a subdirectory of ~/texmf, for MacTeX it's ~/Library/texmf (where ~ stands for the home directory). Create a path such as

~/texmf/metapost/colin

and save metaobj-x.mp there.

(Sorry for a late answer)

share|improve this answer
1  
Thanks, Enrico. I finally settled on doing just what you suggest. –  Colin Fraizer Oct 26 '11 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.