TeX/unskip

From Wikibooks, open books for an open world
< TeX
Jump to navigation Jump to search

Synopsis[edit | edit source]

\unskip will remove the last glue from the current list.

Description[edit | edit source]

IF the last item on the current list is glue, \unskip removes it; otherwise \unskip has no effect[1]. It does not remove kerns[2].

The command may not be used in vertical mode if the main vertical list-so-far has been entirely contributed to the current page [280][1]. However, \vskip-\lastskip has almost the same effect[1].

\unskip is used where you want to allow some flexibility in the input syntax[2].

For example, it's used in some of the centring code to avoid a space at the start of a line messing up the alignment[2].

Examples[edit | edit source]

%! See = [2] https://tex.stackexchange.com/a/104036
\space\space\unskip % similar to `\space`
\space\space\unskip\unskip % similar to ``
\space\kern0pt\unskip % similar to `\space\kern0pt` (kern doesn't get removed)

%! See = [1] https://www.tug.org/utilities/plain/cseq.html#unskip-rp
\ifdim\lastskip=0pt %test for glue.
\else
  \skip1=\lastskip %store last glue in \skip1.
  \unskip %remove glue from list
\fi
  1. a b c "TeX: Reference and Examples by David Bausum". www.tug.org. Retrieved 2024-04-22.
  2. a b c "When is it good practice to use \unskip". TeX - LaTeX Stack Exchange. Retrieved 2024-04-22.