Is there a way in PDFLaTeX to determine the height of the line you are in? Maybe something similar to PDFsavepos.
In a normal line (i.e. no heading etc.), you might approximate the height by a fixed multiple of ex. But is there a better way?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityIs there a way in PDFLaTeX to determine the height of the line you are in? Maybe something similar to PDFsavepos.
In a normal line (i.e. no heading etc.), you might approximate the height by a fixed multiple of ex. But is there a better way?
Short answer: no.
Longer answer as noted in comments the current target baseline spacing is \baselineskip
so perhaps that is what you are looking for, but if you mean can you determine the height of the current line which may have large inline tables or math expression then it gets harder.
There is no way of having a macro that gives this information at the point that macros expand as an entire paragraph is set (and all macros expanded) before TeX breaks the paragraph into lines and the question has any possible answer.
If you are in a vbox rather than on the main vertical list you can mark the point that you are interested in with \vadjust{\penalty some special value less than -10000}
and then \vsplit
the box at that point, then look with \lastbox
to get the last line box before the forced break, and then looking at the height of that box gives the answer. If the text is on the main vertical list it is a lot harder (you would need a special output routine to take apart and re-assemble the page.
You could use \pdfsaveposition
to access the vertical position of the current point on the next latex run, however you can not easily insert this on every line so it isn't clear that you can use this to determine the height of the line at that point.
The following plain TeX file marks two lines (with !
) and reports their heights as:
marked line 1: height: 6.94444pt, depth 1.94444pt
marked line 2: height: 12.38954pt, depth 6.14844pt
\tracingonline2
\showboxbreadth=\maxdimen
\newcount\linecount
\hsize=3in
\def\a{One two three four five six seven eight nine ten. }
\def\thislineinfo{\global\advance\linecount1 !\vadjust{\break}}
\setbox0=\vbox{\global\linecount=0
\a\a\thislineinfo\a\thislineinfo $A^{^A}A\over B_{B_B}$ \a\a\a
}
\setbox2=\copy0
{\vbadness\maxdimen\count0=1
\immediate\write20{}
\loop
\setbox4=\vsplit2 to \maxdimen
\setbox4=\vbox{\unvbox4\setbox0\lastbox
\immediate\write20{marked line \the\count0: height: \the\ht0, depth \the\dp0}}
\ifnum\count0<\linecount
\advance\count0 1
\repeat
\immediate\write20{}
}
\box0
\bye