8

Consider the following code:

\showboxdepth=20
\showboxbreadth=200
\hsize=5.33333in
\pdfoutput=0

\pdfprotrudechars=1 
\input protcode.tex
\setprotcode\tenrm


\vbox{\noindent  Test. Test. Test. Test. Test. Test. Test. Test.
Test. Test. Test. Test. Test. Test. Test. Test. Test. Test. Test. Test.
Test. Test. Test. Test. Test. Test. Test. Test. Test. Test.\par
\global\setbox3=\lastbox }
\showbox3 \setbox3=\hbox{\unhbox3 }%
\showbox3

\bye

Now run it with pdftex. The log file shows that the left and right margin \kerns disappear in reboxing. Why? Can it be prevented? Here are excerpts:

> \box3=
\hbox(6.83331+0.0)x385.43962, glue set 3.85056fil
.\kern-0.36 (left margin)
.\tenrm T
.\kern-0.83334
.\tenrm e
.\tenrm s
.\tenrm t
.\tenrm .
.\glue 4.44444 plus 4.99997 minus 0.37036
[cut]
.\tenrm T
.\kern-0.83334
.\tenrm e
.\tenrm s
.\tenrm t
.\tenrm .
.\penalty 10000
.\kern-1.94 (right margin)
.\glue(\parfillskip) 0.0 plus 1.0fil
.\glue(\rightskip) 0.0


! OK.
l.15 \showbox3 
               \setbox3=\hbox{\unhbox3 }%
? 
> \box3=
\hbox(6.83331+0.0)x383.88907
.\tenrm T
.\kern-0.83334
.\tenrm e
.\tenrm s
.\tenrm t
.\tenrm .
[cut]
.\tenrm T
.\kern-0.83334
.\tenrm e
.\tenrm s
.\tenrm t
.\tenrm .
.\penalty 10000
.\glue(\parfillskip) 0.0 plus 1.0fil
.\glue(\rightskip) 0.0

! OK.
l.16 \showbox3

This won't happen with ordinary \kerns, such as if we \setbox3=\hbox{\kern-1pt Test.\kern1pt}.

  • 4
    I'm afraid this is “by design”. – egreg Dec 22 '15 at 0:37
  • I believe this is related to the loss in pdfLaTeX if you use microtype: you lose protrusion in the headings of sections, for example. (You can get it back in a specific case, but you can't really compensate for all the eventualities which have the same effect.) – cfr Dec 22 '15 at 0:50
  • 1
    Related: tex.stackexchange.com/questions/262987/… (and probably earlier discussions - that's just the one I know and can find easily). – cfr Dec 22 '15 at 0:56
7

This is indeed, as @egreg has said in the comments, by design (margin kerning is lost after \unhboxing or \unhcopying). But there are two commands that come as remedy: \leftmarginkern and \rightmarginkern allow access to the the respective kerns of an hbox.

So to adapt your sample code, the following will reinsert margin kerning:

\showboxdepth=20
\showboxbreadth=200
\hsize=5.33333in
%\pdfoutput=0

\pdfprotrudechars=1
\input protcode.tex
\setprotcode\tenrm

\setbox0=\vbox{\noindent  Test. Test. Test. Test. Test. Test. Test. Test.
        Test. Test. Test. Test. Test. Test. Test. Test. Test. Test. Test. Test.
        Test. Test. Test. Test. Test. Test. Test. Test. Test. Test.\par}
\showbox0 

\newbox\splitbox
\setbox3=\vbox{%
  \loop\ifvbox0
    \vbadness=10000
    \splittopskip=0pt
    \setbox\splitbox\vsplit0 to\baselineskip
    \unvbox\splitbox\setbox\splitbox=\lastbox
    \hbox{\kern\leftmarginkern\splitbox
          \expandafter\unhbox\expandafter\splitbox\expandafter
          \kern\rightmarginkern\splitbox}%
  \repeat}

\showbox3
\unvbox3
\bye

(Mind you, there is bug with \rightmarginkern and stretchy \parfillskip as reported here.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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