[XeTeX] Mysterious nonzero lastskip

Ross Moore ross at ics.mq.edu.au
Wed Dec 2 00:59:50 CET 2009


Hi Vadim,

On 02/12/2009, at 9:33 AM, Vadim Radionov wrote:

> Dear all,
>
> Can you explain me the strange behaviour of this short TeX script:
>
> % -*- tex-command: "xelatex" -*-
> \documentclass{minimal}
> \usepackage{xltxtra}
>
> \let\dash—
> \catcode`\—=\active
> \def—{\ifdim\lastskip>0pt\message{!!!}\showthe\lastskip\fi\dash}
>
> \begin{document}
> This is a test.—
> \end{document}
>
> In my case (XeTeX, Version 3.1415926-2.2-0.9994.1 (Web2C 7.5.6);  
> xltxtra 2008/07/29 v0.4) it executes the TRUE clause of \if with  
> message, but shows zero lastskip there.  But when I add a soft  
> hyphen in "te\-st", \if condition changes to FALSE, hence no message.

I cannot give the definitive explanation, but here's something
that might be relevant, from those dim misty days when I did
a lot of low-level TeX programming.


Start your macro's expansion with \relax .
    \def—{\relax\ifdim\lastskip...  }

The reason, as I understand it, is that the asynchronous nature
of the tasks that TeX performs internally mean that registers
and other special primitive constructs (such as \lastskip)
need not always be up-to-date with what you would expect,
when reading the input stream.

By putting in \relax you allow the TeX internals time to
"catch up". Now your \if... conditionals will work as expected
when required to read the value of a register.

So although the TeX book says that \relax "does nothing",
this is not entirely true. (There are other places where
it can be important to have a \relax too.)


> Without xltxtra, no message in both cases (with or without soft  
> hyphen).

I've checked that this indeed happens, but cannot explain why
it makes a difference. However,  xltxtra  causes several extensive
packages to be loaded, any one of which may have coding that affects
the value of \lastskip .


BTW, I'm not sure exactly what you have in mind for defining this
\dash  macro, but the TeXbook has a solution (6.6 on page 307),
which puts some flexible glue around the emdash character:

\def\extraspace{\nobreak\hskip 0pt plus.15em\relax}
\def\dash{\unskip\extraspace---\extraspace}

In XeTeX, if your font is loaded with  Mapping=tex-text
then this should work just fine.
Alternatively, you could use:
   \def\dash{\unskip\extraspace\char 8212\extraspace}
provided you were confident that the font would have
an appropriate glyph.  (Or include a test to see whether
the glyph is in the current font.)

With these, you still want to do:

\catcode`\—=\active
\let—\dash

to use the character to get the macro.

>
> Vadim


Hope this helps,

	Ross

------------------------------------------------------------------------
Ross Moore                                       ross at maths.mq.edu.au
Mathematics Department                           office: E7A-419
Macquarie University                             tel: +61 (0)2 9850 8955
Sydney, Australia  2109                          fax: +61 (0)2 9850 8114
------------------------------------------------------------------------





More information about the XeTeX mailing list