I am trying to write a custom command eins such that when you have
\eins{id}{text}
, it outputs the relative box position and depth and height of text in mm (or points) within the printed document together with an identifier that tells me which text element is at that position.
So far I have:
\newcommand\dimtomm[1]{%
\strip@pt\dimexpr 0.351459804\dimexpr#1\relax\relax %
}
\newcommand{\eins}[2][1]{%
\zsavepos{#1-ll}
\newlength{\dd}
\settodepth{\dd}{#2-ll}
\write\mywrite{#2: \dimtomm{\zposx{#1-ll}sp}, \dimtomm{\zposy{#1-ll}sp, \the\dd, } }%
}
If I specify output file:
\newwrite\mywrite
\openout\mywrite=\jobname.72.280.pos \relax
and I later insert
\eins{title}{\huge \textbf {Big Title} }
It gets me the identifier and the x and y positions (relative) of the text #1 (checked by drawing at printed position on image...) but it does not print the depth
Can it be done? the Answer is yes!
thanks to accepted answer from @gernot. Leaving the original (confusing and confused) question above for context but recording my final implementation bellow for those with the exact same problem: how to get the geometric boundaries of rendered text in a single pdf page.
\makeatletter
\newcommand\dimtomm[1]{%
\strip@pt\dimexpr 0.351459804\dimexpr#1\relax\relax %
}
\makeatother
\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
\newwrite\mywrite
\immediate\openout\mywrite=\jobname.72.280.pos\relax
\newlength{\dd}
\newlength{\ww}
\newlength{\hh}
\newcommand{\eins}[2][1]%
{\zsavepos{#1-ll}% Store the current position as #1-ll
{#2}% Output the text provided as mandatory argument
\settodepth{\dd}{#2}% Measure the depth of the mandatory argument
\settowidth{\ww}{#2}% Measure the width of the mandatory argument
\settoheight{\hh}{#2}% Measure the height of the mandatory argument
\immediate\write\mywrite{#1: \dimtomm{\zposx{#1-ll}sp}, \dimtomm{\zposy{#1-ll}sp}, \convertto{mm}{\the\dd}, \convertto{mm}{\the\hh}, \convertto{mm}{\the\ww} }%
}
\begin{document}
\eins[title]{\huge \textbf {Huge Title}}
\eins[title]{\Large \textbf {Large Title}}
\end{document}