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.

How do I insert a small space that looks like the space I get with \, but allows a line break like a normal space does? I.e., I'm looking for a non-stretching, non-non-breaking space whose width is identical to \,.

I have already tried some\,\allowbreak{}text but, in case of a line break, this keeps the \, space at the end of the line which is not what I want.

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

The biblatex package provides the \addthinspace macro which "[a]dds a breakable thin space" (manual, section 4.7.4). Here's a variant that omits the biblatex-specific stuff. (Note that \, in text mode uses \thinspace which is defined as \kern 0.16667em.)

\documentclass{article}

\newcommand*{\addthinspace}{\hskip0.16667em\relax}

\textwidth=52pt

\begin{document}

\noindent xxx xxx xxx xxx xxx\addthinspace aaa\addthinspace aaa

\bigskip

\noindent xxx xxx xxx xxx xxx\,aaa\,aaa

\end{document}

enter image description here

share|improve this answer
    
Is there a simple way to express this in a generic way so that one could write something like \breakingspace{\,} to insert the space? –  Bloops Oct 24 '12 at 15:17
    
@Bloops Locally redefining \, is beyond my abilities. –  lockstep Oct 24 '12 at 15:21
add comment

The \breakingspace macro can be obtained quite easily:

\newcommand{\breakingspace}[1]{#1\hspace{0pt}}

Quoting from the TeXbook (p. 96):

Line breaks can occur only in certain places within a horizontal list. Roughly speaking, they occur between words and after hyphens, but in actuality they are permitted in the following five cases:

a) at glue, provided that this glue is immediately preceded by a non-discardable item, and that it is not part of a math formula (i.e., not between math-on and math-off). A break “at glue” occurs at the left edge of the glue space.

b) at a kern, provided that this kern is immediately followed by glue, and that it is not part of a math formula.

c) at a math-off that is immediately followed by glue.

d) at a penalty (which might have been inserted automatically in a formula).

e) at a discretionary break.

Another way might be

\newcommand{\breakingspace}[1]{{\let\kern\hskip#1}}

Example:

\documentclass{article}
\usepackage{calc}
\newcommand{\breakingspace}[1]{#1\hspace{0pt}}

\begin{document}
\fboxsep=0pt
\fbox{\parbox{\widthof{a\,a}}{
a\breakingspace{\,}a\breakingspace{\,}%
a\breakingspace{\,}a\breakingspace{\,}%
a\breakingspace{\,}a\breakingspace{\,}%
a}}

\renewcommand{\breakingspace}[1]{{\let\kern\hskip#1}}

\fbox{\parbox{\widthof{a\,a}}{
a\breakingspace{\,}a\breakingspace{\,}%
a\breakingspace{\,}a\breakingspace{\,}%
a\breakingspace{\,}a\breakingspace{\,}%
a}}
\end{document}

enter image description here

With both definitions, \breakingspace will not do anything in math mode other than adding glue or kerns; with the other possibility

\newcommand{\badbreakingspace}[1]{\penalty 0 #1}

one would add a break point also in math mode.

share|improve this answer
add comment

Just to mention that the simple \allowbreak\, seems to respond to the OP's demands. In this answer, I first tried with \allowbreak\,\allowbreak but this is a bit silly so I then turned to \allowbreak\,. As the OP said \,\allowbreak is a no-go. In passing, a funny effect is noticed when the text in the testing \parbox is not ended by a \\ or a \par.


In my testing \allowbreak\,\allowbreak works (in text mode, did not try math mode). To illustrate it and check that no thin space is present at the end of the line I replace in the following code the \, by a \bigspace of 2em.

\documentclass{article}
\begin{document}\thispagestyle{empty}

\ttfamily 

\newcommand\bigspace{\kern 2em}

\newlength\awidth
\settowidth{\awidth}{A\bigspace A\bigspace A}

\newcommand\breakingspace{\allowbreak\bigspace\allowbreak}

\fboxsep=0pt

\fbox{\parbox{\awidth}{
A\rule{2em}{1pt}A\rule{2em}{1pt}A\\
A\breakingspace
B\breakingspace
C\breakingspace
D\breakingspace
E\breakingspace
F\breakingspace
G\breakingspace
H\breakingspace
I\breakingspace
J\breakingspace
K\breakingspace
L\\
A\breakingspace
B\breakingspace
C\breakingspace
D\breakingspace
E\breakingspace
F\breakingspace
G\breakingspace
H\breakingspace
I\breakingspace
J\breakingspace
K\breakingspace
L\breakingspace
}}
\end{document}

output of the code

Hope somebody will explain the behavior at the end of the text when it is ended by \breakingspace. . .


Actually, \allowbreak\, works about the same as \allowbreak\,\allowbreak. As shown by this variant:

\renewcommand\breakingspace{\allowbreak\bigspace}

\fbox{\parbox{\awidth}{
A\rule{2em}{1pt}A\rule{2em}{1pt}A\\
A\breakingspace
B\breakingspace
C\breakingspace
D\breakingspace
E\breakingspace
F\breakingspace
G\breakingspace
H\breakingspace
I\breakingspace
J\breakingspace
K\breakingspace
L\breakingspace
}}
\fbox{\parbox{\awidth}{
A\rule{2em}{1pt}A\rule{2em}{1pt}A\\
A\breakingspace
B\breakingspace
C\breakingspace
D\breakingspace
E\breakingspace
F\breakingspace
G\breakingspace
H\breakingspace
I\breakingspace
J\breakingspace
K\breakingspace
L\breakingspace
M\breakingspace
}}

second image

I deliberately left \breakingspace at the end, rather than \par to show a funny effect. It is also interesting how the behavior is slightly different for the two definitions of \breakingspace. Note though that in both cases nothing surprising happens if one ends the thing with a \par rather than a \breakingspace.

share|improve this answer
    
\allowbreak\, is exactly my third solution. At the end of a paragraph kerns are not discarded; only one trailing glue item is. –  egreg Dec 4 '12 at 11:55
    
@egreg: sorry I overlooked that, but it is good news as it means it does the expected thing in math mode, correct? and about the behavior of TeX's paragraph builder when such a thing rather than \\ or \par ends it? (you say kerns are not discarded, but how does it end up influencing the /first/ line of the paragraph?) –  jfbu Dec 4 '12 at 12:29
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.