Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to typeset post--World War II with what Adobe InDesign calls a "quarter space". The en-dash is there to be wider than a normal space, to clarify the constituent structure ([post-[[World War] II]]), but in good typesetting, the two spaces in this expression should, unlike other spaces in the same typeset line, not stretch.

How do I typeset a fixed-width "quarter space" in LaTeX?

(I used to think that the right way was post--World\ War\ II, but I just found out that \␣ isn't a fixed space at all but is just a line-breaking variant of the line␣break--preventing ~.)

Really, I need two different macros: one that allows for a linebreak and one that doesn't. For example, the expression above should be linebroken in the following ways:

  • ok: post--/World␣War␣II
  • ok: post--World/War␣II
  • bad: post--World␣War/II

(Let's just assume that this is how we want it and leave the question of whether the second linebreak option is typographically good or not for another debate.)

Let's also assume that linebreaking points in a component word are to be retained. Two examples (from Wikipedia's "Dash" article):

  • "Fran·cis·co" in non--San␣Francisco
  • "min·is·ter" in ex--prime␣minister

Related:

share|improve this question
1  
Should they prevent line-breaking as well? \mbox{post--World War II} See When to use a \mbox or a tilde for words that have to stay together –  Qrrbrbirlbel Feb 23 '13 at 4:25
    
@Qrrbrbirlbel Thanks; good question. I was meaning to write about this but then forgot. See my edit. –  Lover of Structure Feb 23 '13 at 4:56
add comment

3 Answers

up vote 12 down vote accepted

Just set \spaceskip; if this parameter is nonzero, TeX will use it for the interword space, ignoring the font defined parameters.

\documentclass{article}
\usepackage{xcolor}
\newcommand{\fixedspaceword}[2][1]{%
  \begingroup
  \spaceskip=#1\fontdimen2\font
  \xspaceskip=0pt\relax % just to be sure
  #2%
  \endgroup
}
\newcommand{\WWII}{{\color{blue}post--World War II}}
\begin{document}

\makebox[\textwidth][s]{a text \fixedspaceword{\WWII} and so ends}

\makebox[\textwidth][s]{a text \fixedspaceword[.75]{\WWII} and so ends}

\end{document}

With \makebox[\textwidth][s]{...} interword spaces that can stretch do.

enter image description here

With the optional argument you can reduce (or expand) the interword space in the \fixedspaceword bit.


If you prefer that spaces are allowed to shrink together with the other spaces in the line, change the definition into

\newcommand{\fixedspaceword}[2][1]{%
  \begingroup
  \spaceskip=#1\fontdimen2\font minus \fontdimen4\font
  \xspaceskip=0pt\relax % just to be sure
  #2%
  \endgroup
}

The space won't be allowed to stretch, because \spaceskip has zero stretch component.

share|improve this answer
    
Is there a difference between \fixedspaceword{\textsc{van Beethoven}} and \textsc{\fixedspaceword{van Beethoven}}? I use times-itsc (which I know has alternatives). –  Lover of Structure Feb 23 '13 at 15:04
1  
The difference is in which font is used to set the interword space (the normal font in the former case, the small caps one in the second); it shouldn't be a big concern. –  egreg Feb 23 '13 at 17:14
    
Question: What about a macro where the fixed space is adapted with font changes? Arguably the two "fixed" spaces in Ludwig \textsc{van Beethoven} should be different. –  Lover of Structure Feb 23 '13 at 19:27
    
Is there a way of defining this so that the space will shrink proportionally but will stay constant if the text around it is stretched? –  Lover of Structure Feb 23 '13 at 19:28
    
I would never use different spaces in "Ludwig van Beethoven"; about the second question, I don't understand it. –  egreg Feb 23 '13 at 19:51
show 6 more comments

The inter-word stretch and shrink can be adjusted (or removed). The following minimal example tries to highlight this:

enter image description here

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newdimen\origiwstr% inter-word stretch
\newdimen\origiwshr% inter-word shrink
\makeatletter
\newcommand{\fixedspaceword}[1]{%
  \origiwstr=\fontdimen3\font% original inter-word stretch
  \origiwshr=\fontdimen4\font% original inter-word shrink
  \fontdimen3\font=\z@% No inter-word stretch
  \fontdimen4\font=\z@% No inter-word shrink
  #1%
  \fontdimen3\font=\origiwstr% Restore inter-word stretch
  \fontdimen4\font=\origiwshr% Restore inter-word shrink  
}
\makeatother
\newcommand{\vertruleL}{\llap{\smash{\color{red}\rule[-10\baselineskip]{1pt}{11\baselineskip}}}}
\newcommand{\vertruleR}{\rlap{\smash{\color{red}\rule[-10\baselineskip]{1pt}{11\baselineskip}}}}
\newcommand{\WWII}{{\color{blue}post--World War II}}
\begin{document}
% \mboxed
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam \vertruleL\mbox{\WWII}\vertruleR{} tortor metus, adipiscing sitalo amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

% Plain
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam \WWII{} tortor metus, adipiscing sitalo amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

% No shrink/stretch
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam \fixedspaceword{\WWII} tortor metus, adipiscing sitalo amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

\hrulefill

% \mboxed
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam tortor metus, adipiscing sitalo \mbox{\WWII} amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

% Plain
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam tortor metus, adipiscing sitalo \vertruleL\WWII\vertruleR{} amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

% No shrink/stretch
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse semper 
mauris a odio vestibulum et eleifend quam gravida. Maecenas facilisis odio 
sed velit semper imperdiet. Nullam tortor metus, adipiscing sitalo \fixedspaceword{\WWII} amet elementum 
lacinia, ullamcorper at velit. Suspendisse nulla elit, bibendum a tempus eu, 
gravida non est.

\end{document}

In the first three examples of Lorem Ipsum text, the second one clearly has a change in the inter-word spacing, since the red vertical rules overlay the blue post--World War II with nothing else changed.

The dimensions relating to inter-word stretch/shrink are given by

  • \fontdimen3\font (for stretch)
  • \fontdimen4\font (for shrink)

The macro \fixedspaceword{<stuff>} stores the original stretch/shrink before setting it to zero (\z@) and typesetting <stuff>. Finally, it restores the original stretch/shrink. This allows for breaking across the line boundary as well, as shown in the second set of examples. \mbox, of course, does not allow this.


As reference, see How to shorten/shrink spaces between words?

share|improve this answer
    
Btw see my very recent edits to this question. –  Lover of Structure Feb 23 '13 at 5:17
    
@LoverofStructure: I would say the "do not break" macro is \mbox. The breakable one could be \fixedspaceword, while the author should write post--World War~II to avoid a bad break of the numeral. –  Werner Feb 23 '13 at 5:20
    
So breakableprefix--\fixedspaceword{breakableword \mbox{unbreakableword} breakableword~\mbox{unbreakableword}~breakableword} or \fixedspaceword{breakableprefix--breakableword \mbox{unbreakableword} breakableword~\mbox{unbreakableword}~breakableword}? Note that I have not tested whether an en-dash preserves the hyphenation points of the word on its immediate left and/or right. –  Lover of Structure Feb 23 '13 at 5:46
2  
@Lover Presence of -, -- or --- in a compound word removes all other hyphenation points. You can use ngerman shorthand "= for hyphen. For en-dash, see tex.stackexchange.com/a/99336/11002 –  tohecz Feb 23 '13 at 22:26
    
@tohecz About my comment-question above: The two seem to behave identically (with the hyphenation as intended, except for -- disabling hyphenation on both sides in both cases). –  Lover of Structure Mar 3 '13 at 3:05
add comment

About two aspects of my (final, edited) question that both present answers (of user egreg and of user Werner) do not address:

  1. With the macro \fixedspaceword from either solution, the following will do it for my expression "post–World War II" [<- Unicode en-dash inside, though it doesn't appear visually as such on Stack Exchange right now]:

    \fixedspaceword{post--World War~II}
    

    It is better not to use \fixedspaceword{post--World \mbox{War II}} in this case; see this answer to a question about the difference between \mbox and ~.

  2. As user tohecz has pointed out, this answer of his addresses the hyphenation issue for en-dashes (not handled by my code immediately above).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.