6

The MWE is

A \hskip 0pt plus 2pt \foo B
\end

Then macro \foo will tell me the actual length of the previous \hskip in the log file.

Is it possible to write such macro \foo? How?

7

Not exactly what you ask but as you ask for the information in the log you can do

\tracingoutput1
    \showboxbreadth\maxdimen\showboxdepth\maxdimen

A \hskip 0pt plus 2pt  B

\parfillskip 0pt plus .5\hsize
A \hskip 0pt plus 2pt  B

\end

which produces

..\hbox(6.83331+0.0)x469.75499, glue set 431.83829fil
...\hbox(0.0+0.0)x20.0
...\tenrm A
...\glue 3.33333 plus 1.66498 minus 1.11221
...\glue 0.0 plus 2.0
...\tenrm B
...\penalty 10000
...\glue(\parfillskip) 0.0 plus 1.0fil
...\glue(\rightskip) 0.0

and

..\hbox(6.83331+0.0)x469.75499, glue set 1.81032
...\hbox(0.0+0.0)x20.0
...\tenrm A
...\glue 3.33333 plus 1.66498 minus 1.11221
...\glue 0.0 plus 2.0
...\tenrm B
...\penalty 10000
...\glue(\parfillskip) 0.0 plus 234.87749
...\glue(\rightskip) 0.0

From which you can deduce the first line the infinite glue stretch was used (so the finite 2pt stretch was not used) and in the second line finite stretch was used by a factor of 1.81032


If you are using an extended tex such as pdftex then you can measure the space within TeX (most of the effort is setting up the aux file, so it's easier in latex) but

%\tracingoutput1
%    \showboxbreadth\maxdimen\showboxdepth\maxdimen

\newread\test
\newwrite\aux
\openin\test=\jobname.aux
\ifeof\test\else
\closein\test
\input\jobname.aux
\fi
\immediate\openout\aux=\jobname.aux
\def\foo#1#2{%
\pdfsavepos
\write\aux{\def\expandafter\string\csname#1Xa\endcsname{\the\pdflastxpos}}%
#2%
\pdfsavepos
\write\aux{\def\expandafter\string\csname#1Xb\endcsname{\the\pdflastxpos}}%
\expandafter\ifx\csname#1Xa\endcsname\relax\else
\wlog{LENGTH: \the\dimexpr\csname#1Xb\endcsname sp-\csname#1Xa\endcsname sp}%
\fi}



%%%%%%%


A \foo{x}{\hskip 0pt plus 2pt }B

\parfillskip 0pt plus .5\hsize
A \foo{y}{\hskip 0pt plus 2pt }B

\end

produces

LENGTH: 0.0pt
LENGTH: 3.62064pt

Confirming the result shown in the classic trace information that the first space has a final length of 0pt and the second a final length of 0pt + 1.81032*2pt = 3.62064pt

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.