# Non-breaking spaces inside dashes

Exists a method or environment to write in French, exactly like a quote in « guillemets », a text in — en dashes — with automatic non-breaking spaces inside ? So, I used this trivial method, but it cut between dash & exemple inside at line break : beginning —~exemple~— end.

I'm using [frenchb]{scrbook}, [frenchb]{babel} & [babel,french=guillemets*]{csquotes} packages, with xelatex & encoding = UTF-8 Unicode. Thanks

You can define \dashquote which works in pairs. First (and each odd) occurrence of the \dashquote works like --~ and second (and each even) occurrence of the \dashqoute works like ~--. And finally, you can set (in XeTeX) the unicoded character — as an active character and define it as \dashquote.

\def\dashquote{\bgroup\def\dashquote{\unskip~--\egroup}--~\ignorespaces}
\catcode—=13 \def—{\dashquote} % the Unicode character — is defined here

Text — quoted example — text. % Works like: Text --~quoted example~-- text.

Text —quoted example— text. % Works the same, like: Text --~quoted example~-- text.

• It should be \protected\def–{\dashquote}. Forgetting a closing emdash inside a LaTeX environment will lead to a weird error message. – egreg Jan 31 '15 at 16:59

Use the UTF-8 character U+2014 (EM DASH) or \textemdash:

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[babel,french=guillemets*]{csquotes}

\begin{document}

\parbox{0pt}{beginning ---~exemple~--- end}

\bigskip

\parbox{0pt}{beginning \textemdash~exemple~\textemdash{} end}

\bigskip

\parbox{0pt}{beginning —~exemple~— end}

\end{document}


In the example the \parbox is just to force LaTeX to break as much as possible. The third \parbox contains the — character that is equivalent to typing \textemdash.

The problem with --- is that TeX adds an empty discretionary after a hyphen - or any ligature that ends with it.

For XeLaTeX there's a workaround (for mysterious reasons, XeTeX adds the empty discretionary after the emdash):

\documentclass{scrbook}
\usepackage{fontspec}
\usepackage[french]{babel}
\usepackage[babel,french=guillemets*]{csquotes}
\usepackage{newunicodechar}
\newunicodechar{—}{\mbox{—}}

\begin{document}

\parbox{0pt}{beginning ---~exemple~--- end}

\bigskip

\parbox{0pt}{beginning —~exemple~— end}

\end{document}


I don't know if there's a better system. This one only works between two em-dashes, though. EDIT: I didn't see that you used XeLaTeX

\documentclass{scrbook}
\usepackage{expl3}
\usepackage{newunicodechar}

\newunicodechar{—}{\delimitedbyemdash}
\def\delimitedbyemdash#1—{\textemdash~\csname tl_trim_spaces:n\endcsname{#1}~\textemdash}

\begin{document}

Is this —what you mean— in the question?

\end{document}
`