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

Mojca Miklavec mojca.miklavec.lists at gmail.com
Tue Sep 18 16:59:47 CEST 2007


On 9/18/07, Michaël Cadilhac wrote:
> Hi list!
>
> But my very problem is that I can't get it to work.  See the following
> file:
>
> verbatimtex
> %&latex
> \documentclass{article}
> \usepackage[T1]{fontenc}
> \usepackage[nice]{nicefrac}
> \begin{document}
> etex;
>
> 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"
> enddef;
>
> prologues := 2;
> beginfig(1)
>  label (TEX("abc"), (0,0));
>  label (btex b etex, (2cm, 2cm));
>  label (TEX("def$\nicefrac{1}{2}$"), (4cm, 4cm));
> endfig;
> end.
>
>
> So, question is, am I searching for a feature beyond MP capacities?

Can you try to compile the following document with "texexec yourfile.tex"?

% 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

You can pass any string to textext(), but note that \sometxt is *much*
more efficient, so you should use \sometxt whenever possible.

There also seems to be a little bug if you put the last label in front
of the rest. I will check.

Mojca


More information about the metapost mailing list