TransWikia.com

Absolute page coordinates of metapost figures using luamplib/lualatex

TeX - LaTeX Asked on March 23, 2021

How can one draw/place metapost figure elements (using luamplib in lualatex) as if the pdf page were a graph paper? So there is origin: (xorigin, yorigin), and all the elements are placed relative to the origin or relative to each other? For instance, place a circle of diameter 2 at (3,4). Where (3,4) is an absolute position on page w.r.t origin (xorigin=0pt,yorigin=0pt would mean top left of the page). Also, numbers 2,3,4 get scaled by scale/xscale/yscale which can be in pt/cm/inch. I know it is possible to do this with tikz, though I haven’t come across a post that dives into how one could do this in metapost (metapost/luamplib manual doesn’t dive much in origin, and absolute page placement). I tried using textpos, though that’s not a real solution as let’s say if I add labels to the top/left of the circle then the center of the circle shifts away from (xorigin+3*xscale,yorigin+4*yscale) on pdf page; because it is trying to align the left/top boundry of figure to the anchor point of textpos (instead of anchoring center of circle to the anchor point of textpos). And making manual adjustments would be a nightmare if the figure changes in future. A solution would provide/demonstrate a systematic way of placing any/all figure elements at absolute/relative locations on page.

A more formal spec with an example: So for instance, after placing the circle at some absolute
location on the pdf page: (xorigin+X*xscale,yorigin+Y*yscale) with a
diameter of D*xscale or D*yscale; I would also like to position other
elements like labels relative to this circle at an offset of
(Xoff*xscale,Yoff*yscale). All the while only specifying
X/Y/D/Xoff/Yoff, or less preferably (but still acceptable) with the
multiplier *(x|y)scales.

Here’s a simple figure + code to being with:

example metapost figure

% Command: >> lualatex abspicture.tex
documentclass{article}
usepackage[paper=letterpaper,left=0in,right=0in,top=0in,bottom=0in]{geometry}
usepackage{luamplib}


begin{document}
thispagestyle{empty}

begin{mplibcode}
beginfig(1)
u=50;
draw fullcircle scaled u;
pickup pencircle scaled 2;
draw (u/2,0); draw(0,u/2); draw(-u/2,0); draw(0,-u/2);
label.rt(btex $theta = 0$ etex scaled .5, (u/2,0));
label.top(btex $theta = displaystyle{frac{pi}{2}}$ etex scaled .5, (0,u/2));
label.lft(btex $theta = pi$ etex scaled .5, (-u/2,0));
label.bot(btex $theta =displaystyle{frac{3pi}{2}}$ etex scaled .5, (0,-u/2));
endfig;
end;

end{mplibcode}

end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP