10

I don't know if I am right. Let's read the codes :)

\setbox0=\vbox{a\par
  \vskip2pt
  \kern2pt
  b}
\showbox0

the snippet of the log file:

.\glue 2.0
.\kern 2.0
.\glue(\parskip) 0.0 plus 1.0
.\glue(\baselineskip) 5.05556

When we

\setbox1=\vbox{\unvbox0
  \setbox2=\lastbox
  \unskip
  \unskip
  \global\skip0=\lastkern
  \unkern
  \global\skip1=\lastskip
  \unskip}

Sometimes, we have no chance of examining the log file, so, how can we decide the glue or the kern in some \skip<number> is glue or kern?

yanpengl
  • 2,691
  • 12
  • 24
  • You can use e-TeX's \lastnodetype (texdoc etex is your friend). – egreg Mar 31 '13 at 13:41
  • @egreg thank you, egreg, I will visit my friend :) – yanpengl Mar 31 '13 at 13:44
  • @egreg: I notice that when I input etex in the shell, it refers to pdfTeX. – yanpengl Mar 31 '13 at 13:49
  • Yes: the modern TeX distributions always use pdftex for etex, pdftex, latex and pdflatex. – egreg Mar 31 '13 at 13:50
  • 1
    BTW, use odd numbers for local assignments and even numbers for global assignments of the first ten scratch registers (\global\skip1=\lastkern and \global\skip3=\lastskip). This is the convention in plain TeX and LaTeX to prevent problems with "save stack buildup". – Heiko Oberdiek Mar 31 '13 at 15:00
  • @HeikoOberdiek: I will follow your useful and important advice. When reading the TeX codes, I have noticed the difference but don't know why. Thanks. – yanpengl Mar 31 '13 at 15:28

2 Answers2

8

This can be done with e-TeX (which is incorporated in pdftex):

\def\unkernorunskip#1{%
  \ifnum\lastnodetype=12 % kern
    \global\skip#1=\lastkern\unkern
  \else
    \ifnum\lastnodetype=11 % skip
      \global\skip#1=\lastskip\unskip
    \fi
  \fi}


\setbox0=\vbox{a\par
  \vskip4pt
  \kern2pt
  b}

\setbox1=\vbox{\unvbox0
  \setbox2=\lastbox
  \unskip
  \unskip
  \unkernorunskip{1}%
  \unkernorunskip{3}%
  }

\showthe\skip1
\showthe\skip3

The output is

> 2.0pt.
l.24 \showthe\skip1

?
> 4.0pt.
l.25 \showthe\skip3

?
egreg
  • 1,121,712
5

In classic TeX you can not tell. You can examine \lastskip or \lastkern but these will be 0pt whether the last item on the list is not a skip or if it is a skip of size 0pt, you can not distinguish those cases.

Using e-tex however you can examine the value of the integer \lastnodetype which will be 11 for a glue (skip) node and 12 for a kern node.

David Carlisle
  • 757,742