You can use \pfdsavepos
for measuring the depth of the previous line while using \vadjust
. But this is not classical TeX, this is from pdfTeX extension:
This is the line in the paragraph%
\pdfsavepos\write16{\the\pdflastypos}%
\vadjust{\pdfsavepos\write16{\the\pdflastypos}}
this continues the line in the paragraph,
this continues the line in the paragraph.
You can write the result to the output file (replace 16 by something more appropriate) and you can read this file again in the next step. The information in the file (from this example) is in the form:
49989344
49861913
This means that the depth of the measured line is 49989344-49861913 = 127431 sp
. This is approximately 1.944pt.
Edit Because the name of the thread, I show a full implementation of this feature:
\newcount\marnum \newcount\tmpnum
\newwrite\marfile \newread\testin
\def\marX#1#2{\advance\marnum by1 \tmpnum=#1 \advance\tmpnum by-#2
\expandafter \edef \csname mar:\the\marnum\endcsname{\the\tmpnum}}
\openin\testin=\jobname.mar
\ifeof\testin \message{Warning: file \jobname.mar does not exist, TeX me again}%
\else \closein\testin \input \jobname.mar \fi
\immediate\openout\marfile=\jobname.mar
\marnum=0
\def\marginalnote#1{\global\advance\marnum by1
\expandafter\ifx\csname mar:\the\marnum\endcsname \relax
\def\kernR{0pt}\else\edef\kernR{\csname mar:\the\marnum\endcsname sp}\fi
\pdfsavepos\write\marfile{\string\marX{\the\pdflastypos}}%
\vadjust{\pdfsavepos\write\marfile{{\the\pdflastypos}}%
\kern-\kernR\smash{\llap{#1 }}\kern\kernR}}
This is the line in the paragraph%
\marginalnote{XX}
this continues the line in the paragraph,
this continues the line in the paragraph.
Second m. note:\marginalnote{YY}
\end
All marginal notes have unique number in the document \marnum
. If the temporary file \jobname.mar
exists then it is read using \input
and the information is saved using \marX
to the macro \mar:mar-num
. The \marginalnote
reads this information if exists else it uses R=0pt
.