# [metapost] pdftex \pdflastxpos for metapost?

Daniel H. Luecking luecking at uark.edu
Tue May 10 20:03:59 CEST 2005

On Mon, 9 May 2005, Hartmut Henkel wrote:

> Thanks, Taco and Dan!
>
> On Mon, 9 May 2005, Dan Luecking wrote:
>
> > You could assign the value to a temporary dimension register (in
> > pdftex) and write that out. Example:
> >
> > \dimen0=\number\pdflastxpos sp %\dimen0=1\pdflastxpos should also work.
> > \write\myfile{\the\dimen0}
>
> yes, but problem is that the \pdfsavepos happens very late, only at
> shipout (else it won't know the absolute position), so you get a
> \pdflastxpos value only after a \pdfsavepos...\vfill\eject, or when
> using \write. Taco's version works if there is only one \pdfsavepos per
> page. If there are several, it seems one needs the \write. So what i'm
> looking for is conceptually something like:
>
> \def\foo#1\relax{% here goes the trick of scaling #1
> }

If etex is available, Hans' suggestion should work. Otherwise you can
perhaps postprocess the written file (even in the same tex run):

> a\pdfsavepos
> \write\mywrite{\expandafter\foo\the\pdflastxpos\relax}

Try:

a\pdfsavepos
\write\mywrite{\noexpand\foo{\number\pdflastxpos}}

Then the \mywrite file (call it temp1.tex) will contain entries like
\foo{12345}
\foo(2468888}
...
At the end of the document, define \foo to perform the dimension
assignment and write the result to another file:
\immediate\openout\otherfile=temp2.dat
\def\foo#1{\dimen0=#1sp \immediate\write\otherfile{\the\dimen0}}
\input temp
\immediate\closeout\otherfile
and get all the dimensions written to temp2.dat.

>
> where \foo would make the division/scaling (no clue, how).

You could also write them as strings. MP can easily insert a decimal
point character say 7 places from the right of the string. Then scantokens
can be used to read the string as a number:
string X;
X := "123456";
X := "0000000" & X; % ensure at least 7 places
numeric n, w;
n:=length X;
X := (substr (0,n-7) of X) & "." & (substr (n-7,n) of X);
scantokens ("w:=" & X & ";");

Or use sarith.mp (afraid I know very little about it).

Dan

--
Dan Luecking
Dept. of Mathematical Sciences
University of Arkansas
Fayetteville, AR 72101