11

I have implemented the horrific document

\documentclass{article}
\newcommand{\testspace}[1]{\hspace*{\fill}\(\vert\)\hspace*{\fill}\\
                           \null\space\(\vert\)\hspace*{3.3pt plus #1pt}\break}
\begin{document}
\noindent
\(\vert\)\space\(\vert\)\\
\(\vert\)\hspace{3.3pt}\(\vert\)\\
\testspace{1.665}
\end{document}

This allows me to visually examine each vertical bar to see which ones line up the best, and therefore discover how much stretch an individual control space has. I estimate the width of a space to be about 3.3pt plus 1.665pt, however, I can't shake the feeling that this is awful. Nevertheless, TeX (and I think it is TeX and not LaTeX) will not let me use \the\space. How should I figure out the length of a single space?

  • possible duplicate of Retrieve length of a character – Maarten Dhondt Feb 23 '15 at 7:24
  • Surely you don't just want the length of a space. What are you going to do with that length? – Werner Feb 23 '15 at 7:30
  • @MaartenDhondt I think this is slightly different, as \widthof{\space} gives 5.0pt, which is considerably larger than a single space, and has no stretch besides. I have no idea how the \widthof macro works, and I won't hazard any guesses. @Werner I am mostly just curious, but it came up when I was trying to make a space that would be the width of a space plus \fill. – Program man Feb 23 '15 at 7:43
  • @Programman: You can measure the width of a space in pts and use that measurement. The rubber length doesn't give the real width when used within some other context; just the width that it could possible be between. – Werner Feb 23 '15 at 8:14
  • 1
    note \space is not a "control space" (the\ primitive) it is simply a macro that expands to a space, \widthof{\space} is same as \widthof{ } – David Carlisle Feb 23 '15 at 9:07
21

The width of normal space depends on current font. There are global metric items in each font called \fontdimen. The \fontdimen2 includes the basic width of normal space, \fontdimen3 includes value atfer plus and \fontdimen4 includes value after minus. The \fontdimen7 includes additional space used when \spacefactor\ge 2000.

Because the \font primitive used in the context \fontdimen<number>\font denotes the current font (and no normal declaration primitive), we can print the values of normal space by the code:

\message{space: \the\fontdimen2\font\space 
   plus \the\fontdimen3\font\space minus \the\fontdimen4\font}

Computer Modern roman at 10 pt gives the following result:

space: 3.33333pt plus 1.66666pt minus 1.11111pt

And you can use \hskip primitive for creating normal space by

\hskip \fontdimen2\font plus\fontdimen3\font minus\fontdimen4\font

but this is only for illustration purposes. Normal people use \spaceor \ (control space).

EDIT: The normal space doesn't generate the space mentioned by \hskip above at all circumstances, because there are many exceptions. If the register \spaceskip is nonzero then \fontdimens are not used but \spaceskip register is used. Moreover, if \xspaceskip is nonzero and the current \spacefactor\ge 2000 then \xspaceskip is used.

There are two differences between \ (control space) and \space (or normal space between words, token of catcode 10):

  • \space is ignored in vertical mode but \ in vertical mode starts horizontal mode.
  • \space respects the current \spacefactor but \ does the same as \space when \spacefactor=1000.

Finally, what does mean that the space respects current \spacefactor. Let f=\spacefactor/1000 and b is basic width of the space, p is plus value and m is minus value. Then p is modified by p:=p*f and m is modified by m:=m/f and b is kept unchanged. But, if \spacefactor\ge2000 then b:=b+\fontdimen7 (or \xspaceskip is used if it is nonzero).

I add an example from my TeXbook naruby, page 105: Suppose the normal space (when \spacefactor=1000) as 10pt plus10pt minus10pt. When \spacefactor=600 then the space 10pt plus 6pt minus16.666pt is inserted, when \spacefactor=1500 then 10pt plus15pt minus6.666 is inserted. Finally when \spacefactor=3000 then 10pt+\fontdimen7 plus 30pt minus 3.333pt is inserted.

Normally, \spacefactor is 1000, but in some languages the \nonfrenchspacing macro sets special \sfcodes to several characters. The \spacefactor is set to the \sfcode value of the last typeset character in horizontal mode. (There is an exception when \spacefactor<1000 and \sfcode>1000. Then new \spacefactor=1000.) For example plain TeX sets \sfcode of period, question and exclamation mark to 3000, comma to 1250, semicolon to 1500 and colon to 2000.

  • Yes thank you, this is exactly what I was looking for. – Program man Feb 23 '15 at 8:02
  • @Programman OK. Maybe it would be better to change the LaTeX to TeX in the title of your post. – wipet Feb 23 '15 at 8:23
  • @wipet I'm always hesitant to refer to TeX instead of LaTeX, but I think in this case its definitely TeX through and through. I will take your suggestion. – Program man Feb 23 '15 at 8:24

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.