TeX - LaTeX Asked on August 5, 2021
Suppose I typeset some text using an environment that places it in a box with a width that I specify. (I don’t really care if this is a minipage, tabular, or something else.) I want to write the coordinates of the box to a file. (I will probably use xetex, because this involves Greek text, and that seems too painful in the other tex implementations I’ve tried.) In pdftex and its extensions such as xetex, I can use pdfsavepos
at the beginning and end of the text, and use write18 to write the coordinates. But I think this won’t really give me the coordinates of the upper-left and lower-right coordinates of the box. I imagine it will record the positions of a point on the baseline (?) just before the first character and just after the last character.
Is there a way to output the actual coordinates of the box, or do I have to somehow estimate this by doing arithmetic based on the width of the box, the ascender and descender height of the font, and possibly the box/environment’s margins? If I have to do the arithmetic muself, is there some convenient, automated way to find out the relevant font dimensions for whatever font is being typeset?
You can place content in a box register then access its width height and depth along with the position from pdfsavepos
(which takes multiple runs of latex)
documentclass{article}
newsaveboxzzz
makeatletter
newcommandusewithpos[2]{%
ifcsname zz#1endcsnameelse
expandaftergdefcsname zz#1endcsname{{}{}{}{}{}}%
fi
pdfsavepos
protected@write@auxout{}{%
gdefexpandafterstringcsname zz#1endcsname{%
{noexpandthepdflastxpos}{noexpandthepdflastypos}{thewd#2}{theht#2}{thedp#2}}}%
usebox{#2}}
makeatother
newcommandboxdims[5]{%
par
position (#1sp,#2sp)par width #3, height #4, depth #5
}
begin{document}
saveboxzzz{parbox{3cm}{onetwooooothreeeeeeeee}}
A paragraph with no interest.
and here we use the box fbox{usewithpos{a}{zzz}}
saveboxzzz{makebox[2cm]{x}}
and a second box fbox{usewithpos{b}{zzz}}.
The first box is:
expandafterboxdimszza.
The second box is:
expandafterboxdimszzb.
end{document}
Correct answer by David Carlisle on August 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP