10

I discovered in a TeX document the following commands :

$$ u_n \hbox to 0pt{\hskip 3mm$/$\hss} \longrightarrow 0 $$

I don't uderstand what they do exactly and how exactly how to use them (all i can grasp here is that it allows to put some text on top of some other text).

Are \hbox to 0pt and {\hskip 3mm$/$\hss} somehow related ? What does \hbox to 0pt exactly do (what can it be used for) and what about {\hskip 3mm$/$\hss} ? Are they part of some sort of list of \hsomething commands installed by default if LaTeX ?

lucie
  • 101
  • 1
    These are TeX commands and are documented in the TeXbook bu Knuth. I would have used \rlap{\hskip 3mm$/$}. Basically it overlaps whatever is to the right (\longrightarrow) and inserts a math / 3mm in. See also \mathrlap from the mathtools package. – John Kormylo Jul 18 '21 at 17:58
  • thanks i didn't know about this book and this new command ! it will be very useful !! – lucie Jul 18 '21 at 18:08
  • @lucie: In terms of \hskips (or horizontal skips), consider reviewing What commands are there for horizontal spacing? – Werner Jul 18 '21 at 18:48
  • they are tex primitoves but they should not appear in a latex document. use the equivalent latex commands \makebox or at least the plain tex derived versions, \rlap – David Carlisle Jul 18 '21 at 20:30
  • This seems to be a “poor person's” hack instead of \centernot\longrightarrow that requires \usepackage{centernot}. – egreg Jul 18 '21 at 21:02
  • As David Carlisle said, you shouldn't be using these unless you are using plain TeX and not LaTeX. There can be weird interactions between these low-level commands and the higher-level commands in LaTeX (e.g. \hspace or \makebox) which mess up the document formatting in mysterious and unexpected ways. – alephzero Jul 19 '21 at 04:16

2 Answers2

12

\hbox to <len>{<stuff>} sets <stuff> inside a horizontal box of width <len>. If <len> is 0pt (or less than the width of <stuff>, the contents starts to overlap with surrounding elements. \hss (horizontal stretch/shrink) can be used to change the alignment within the horizontal box.

TeX introduced some shorthand for \hbox to 0pt{<stuff with \hss>} in the form of \clap, \llap and \rlap, while in LaTeX you can use the more familiar \makebox[0pt][<align>]{<stuff>}:

enter image description here

\documentclass{article}

\usepackage{amsmath,array}

\begin{document}

\begin{tabular}{ l @{\qquad} >{$\lvert$}c<{$\rvert$} } \verb|\hbox to 0pt{abc}| & \hbox to 0pt{abc} \ % right overlap \verb|\hbox to 0pt{\hss abc\hss}| & \hbox to 0pt{\hss abc\hss} \ % center overlap \verb|\hbox to 0pt{abc\hss}| & \hbox to 0pt{abc\hss} \ % right overlap \verb|\hbox to 0pt{\hss abc}| & \hbox to 0pt{\hss abc} \ % left overlap \verb|\clap{abc}| & \clap{abc} \ % center overlap \verb|\llap{abc}| & \llap{abc} \ % left overlap \verb|\rlap{abc}| & \rlap{abc} \ % right overlap \verb|\makebox[0pt]{abc}| & \makebox[0pt]{abc} \ % center overlap \verb|\makebox[0pt][c]{abc}| & \makebox[0pt][c]{abc} \ % center overlap (equivalent to \makebox[0pt]{abc}) \verb|\makebox[0pt][l]{abc}| & \makebox[0pt][l]{abc} \ % right overlap \verb|\makebox[0pt][r]{abc}| & \makebox[0pt][r]{abc} % left overlap \end{tabular}

\end{document}

Technically, \hss is defined a "horizontal skip equivalent to \hskip 0cm plus 1fil minus 1fil" which "absorbs any positive or negative width of the argument." (taken from TeX by Topic).

Werner
  • 603,163
4

Just out of academic interest.

\hbox to 0pt{...}

makes a box with zero width. However, this would produce an overfull box unless there is infinitely shrinking glue inside it, which the author of that hack provides as \hss, which is equivalent to

\hskip 0pt plus 1fil minus 1fil

so there is enough shrinkability and the text in the box will stick to the right. The text is a slash moved to the right by 3mm.

The output seems correct, but it's just by chance and if used in inline math the placement of the slash might be off.

A slightly better code that produces a seemingly right symbol that doesn't suffer from the mentioned problem would be

$$ u_n \mathrel{\hbox to 0pt{\hskip 2mm$/$\hss}}\longrightarrow 0 $$

(assuming plain TeX, of course).

In LaTeX you can do much better.

\documentclass{article}
\usepackage{amsmath}
\usepackage{centernot}

\begin{document}

[ u_n \centernot\longrightarrow 0 ]

\end{document}

enter image description here

egreg
  • 1,121,712