[metapost] Can't get write/scantokens to work.

Mojca Miklavec mojca.miklavec.lists at gmail.com
Tue Sep 18 19:09:03 CEST 2007

On 9/18/07, Michaël Cadilhac wrote:
> "Mojca Miklavec" writes:
> > Can you try to compile the following document with "texexec yourfile.tex"?

Oh, I'm sorry. It should have been

% MPpage, not MPcode
   label(\sometxt{b}, (2c,2cm));
   label(\sometxt{def\vulgarfraction{1}{2}}, (4cm,4cm));
   label(\sometxt{abc}, (0,0)); % if textext() doesn't work

> > % yourfile.txt should look like:
> > \starttext
> > \startMPcode
> >   label(\sometxt{b}, (2c,2cm));
> >   label(textext("def\vulgarfraction{1}{2}"), (4cm,4cm));
> >   label(textext("abc"), (0,0));
> > \stopMPcode
> > There is a way to get a different fraction, but please tell first if
> > this method works OK for you.
> > \stoptext
> Sure!  I'm not really sure what you're trying to make me understand, but
> well, texexec --mptex of this file gives a drawing with the `b' and
> where `def' and `abc' should be, the text `unknown'.

Why the switch --mptex?
The text "unknown" might have different reasons, usually it's
connected to some unlucky combinations of disabled/enabled write18 and
% \runMPgraphicstrue
% \runMPTEXgraphicstrue
inside cont-sys.tex or cont-sys.ori, but it should work, or at least be fixed.

I thought that you wanted to use variable text inside labels.
Otherwise you can always use \sometxt{...}.

> Well, I'm sorry, but I don't understand the very good point you're
> probably making.  I mean, the only thing I new user know to do, is
> create my beginfig..endfig file, call mpost or mptopdf, depending on the
> need, and include the file in a .tex.

You can include the resulting PDF to the .tex file.

Actually, you can make
... first mp graphic
... second mp graphic

And you will get a PDF document with two pages. Then, you can include
"page one of the file" and "page two of the file" instead of having to
have so many files with figures.

> Are you suggesting that I should use another way of using MetaPost?

Well, this way of creating metapost graphics is just one way to avoid
the need to write this lengthy portion of code at the top of every
metapost graphic:


vardef TEX primary s =
 write "verbatimtex"                    to "mptextmp.mp";
 write "%&latex"                        to "mptextmp.mp";
 write "\documentclass{article}"        to "mptextmp.mp";
 write "\usepackage[T1]{fontenc}"       to "mptextmp.mp";
 write "\usepackage[nice]{nicefrac}"    to "mptextmp.mp";
 write "\begin{document}"               to "mptextmp.mp";
 write "etex"                           to "mptextmp.mp";
 write "btex "&s&" etex"                to "mptextmp.mp";
 write EOF                              to "mptextmp.mp";
 scantokens "input mptextmp"

> Err... Maybe?:-)

But another one from what you saw ;-)

As a summary: the approach I have shown simplifies the usage of TeX
labels inside metapost graphics a bit, nothing more. You can use
exactly the same metapost code as you would inside a .mp file, with
the only exception that there's no need for verbatimtex and TEX()
trickery. Nothing else but that.


More information about the metapost mailing list