Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
The length \baselineskip may be what you are looking for. –  Steven B. Segletes Mar 4 '13 at 20:40
    
I would suspect this could be done in luaTeX (which I don't know well). Anybody? –  mbork Mar 4 '13 at 21:47
add comment

1 Answer

up vote 10 down vote accepted

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

enter image description here

\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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.