2

Using version control it is nice to have my source done more or less with single grammatical units (sentences, phrases, whatever) occupying single source lines. But that tends to result (at least for me) in lots of lines either beginning or ending with an M-dash (--- in the source).

I am finding that when that happens the line break is typeset as a space in the document. That is, there is an space between the M-dash and one, but only one, of the words to which it is adjacent. That is, specifically numbers 1 and 2 look wrong to me in the below code. Lines 4, 5 and 6 look fine if you like it that way, but only line 3 looks the way I would like it.

\documentclass{article}
\begin{document}
1. A line in the source with an M-dash at the end---
like that one; with no space before it in the source.

2. A line in the source with an M-dash at the beginning
---like this one; also with no spaces around it.

3. A line---this one, I mean---with M-dashes in the middle,
and no spaces around them.

4. This line has an M-dash at the end of the line ---
like that; but with a space before it.

5. This one has the M-dash at the beginning of a line
--- like it? But there is a space after it.

6. This line --- the last line --- has M-dashes in the
middle, with spaces around them.
\end{document}

I would really like to A) not have to resort to something ungainly for proofreading like a macro ("\sensiblemdash" or something like that) everywhere I use a dash; B) be able to end or begin lines with dashes; C) be able to use something in source that looks more or less like a dash; and D) not have to have my document typeset with spaces on both ends of the dash. (Regarding this last, I know that it is some people's preference, but, well, not mine, although I'm open to an argument.) I don't mind typing a space on both sides in my source, but I'd like it not typeset that way.

Edit: Forgot to say:

$ latex --version
pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016/Cygwin)
kpathsea version 6.2.2
6
  • You need to add a % to the end of the lines, else a space is generated there. That is, 1. A line in the source with an M-dash at the end---% like that one; with no space before it in the source. 2. A line in the source with an M-dash at the beginning% ---like this one; also with no spaces around it. See tex.stackexchange.com/questions/7453/… Commented Dec 16, 2016 at 20:49
  • That's a bit of a nuisance but I could perhaps live with it. But it also strikes me as dangerous. If I happen to re-flow my source at some point or make edits that change the location of the dash, I have to remember to get rid of each affected % or else risk silently losing the whole rest of the line it is on.... Commented Dec 16, 2016 at 20:57
  • 1
    but the space around a dash is exactly the same as a space around a word, you can enter it as a newline or space, any issues about wrapping apply equally to all spaces not just those near a dash don't they? Commented Dec 16, 2016 at 21:01
  • depending on your editing preferences you could, instead of using --- ligature just type an emdash directly as then it is easy to define the emdash - to ignore any space before or after. Commented Dec 16, 2016 at 21:07
  • @DavidCarlisle I think I understand what you are saying, though I'm not sure I know how to make that happen. I am wondering, though: even though that would tell TeX that it could ignore spaces before or after the dash, would it still know that it could break a line in the typeset output either before or after the dash? Commented Dec 16, 2016 at 21:10

1 Answer 1

3

An end of line in the source is exactly the same as a space (it generates a space token with character code 32 exactly the same as a space character generates)

However if you enter the dashes as — then it is easy to define that to ignore white space before and after,

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{2014}{\leavevmode\unskip---\ignorespaces}


\begin{document}
1. A line in the source with an M-dash at the end—
like that one; with no space before it in the source.

2. A line in the source with an M-dash at the beginning
—like this one; also with no spaces around it.

3. A line—this one, I mean—with M-dashes in the middle,
and no spaces around them.

4. This line has an M-dash at the end of the line —
like that; but with a space before it.

5. This one has the M-dash at the beginning of a line
— like it? But there is a space after it.

6. This line — the last line — has M-dashes in the
middle, with spaces around them.
\end{document}
6
  • I'm not sure, but it seems not to be willing to break a line before or after the dash. No line in the following breaks at the dash: \documentclass{article} \usepackage[utf8]{inputenc} \DeclareUnicodeCharacter{2014}{\leavevmode\unskip---\ignorespaces} \begin{document} a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa— a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa— a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa— a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa \end{document} Commented Dec 16, 2016 at 21:30
  • but I don't know how to construct a proper test.... Commented Dec 16, 2016 at 21:33
  • Actually maybe seems to show the issue:\documentclass{article} \usepackage[utf8]{inputenc} \DeclareUnicodeCharacter{2014}{\leavevmode\unskip\penalty0---\ignorespaces} \begin{document} a—aaa a—a aa—a aaaaaaaaaaaaaaaaaaaaaaaaaaa—a a—aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa— a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa— a—aa aaa—a a—aa a—aaa a—a aa—a aaa—a a—aa a—aaa a—a aa—a aaa \end{document} Commented Dec 16, 2016 at 21:38
  • @EvansWinner from your test above I get ! Package inputenc Error: Unicode char ​ (U+200B) as you have invisible spaces Commented Dec 16, 2016 at 23:03
  • oh perhaps that is just in the site's rendering of --- OK Commented Dec 16, 2016 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .