11

(No, I'm not looking for a solution. I'm really looking for a problem.)

I remember that, a long time ago, I encountered a situation where the \\ (newline) command would insert a blank line if the line preceding the newline was already full. That is,

abc\\xyz

resulted in

abc
xyz

as desired, but

this is a really long line reaching the right margin\\xyz

resulted in

this is a really long line reaching the right margin

xyz

instead of the desired

this is a really long line reaching the right margin
xyz

At that time, I could fix the problem by using \par\noindent instead of \\ (which has of course other problems, in particular if parskip or parsep are non-zero). But I don't remember under which circumstances this happened, which document class and which macro packages were used, and in fact it may have even been old LaTeX instead of LaTeX2e. The strange thing is: The problem has disappeared. I cannot reproduce it anymore.

Does that ring a bell with anybody? Are there any parameter settings that could give rise to such a behavior? Have there been any changes in the definition of \\ in the standard LaTeX packages (in particular, from old LaTeX to LaTeX2e) that could explain it?

Uwe
  • 213
  • 7
    Well, just don't use \\ for breaking lines. ;-) – egreg Dec 07 '16 at 14:23
  • maybe you were in a table context ? – percusse Dec 07 '16 at 14:26
  • 2
    @egreg I have avoided \\ for ten years or so. But I wonder whether the reason why I started to avoid it has disappeared completely, or whether there is still some exceptional case where the lengthy \par\noindent may be more robust. – Uwe Dec 07 '16 at 14:27
  • @percusse No, definitely not in a table. Perhaps in some list environment, but probably not even that. – Uwe Dec 07 '16 at 14:28
  • I'm not able to reproduce the behavior you claim to have seen. Most probably there was a space before \\. – egreg Dec 07 '16 at 14:49
  • @egreg I can't reproduce it either (today), not even with spaces before or after \\. But I'm rather sure that I saw it ten or twenty years ago. That's why I'm asking. – Uwe Dec 07 '16 at 15:13
  • This isn't the reason you should avoid using \\ to break lines, even if it is the reason you have avoided it. – cfr Dec 07 '16 at 18:03
  • @cfr Do you object to (1) breaking lines at all, or to (2) using \ to do it? If (1): I'm talking about things like lecture slides, where enforcing certain line breaks really improves readability, or about some kinds of data listings, like \begin{itemize}\item a\\b\item c\\d\end{itemize}. Not about ordinary aligned text in an article. If (2): What else do you suggest? – Uwe Dec 07 '16 at 18:16
  • You shouldn't use \\ to break lines. I assumed that was @egreg's point. – cfr Dec 07 '16 at 22:52
  • Ulrike Fischer’s answer is brilliant; but of course, you can reproduce the desired behavior only by means of spaces, as @egreg suggests, provided that you put at least two of them in a row in the horizontal list being formed, so that one of them survives the \unskip performed by \@gnewline. For example, word1 \ \\word2 will do. See also: (1) ltspace.dtx, definition of \@normalcr; (2) The TeXbook, p. 97, fifth paragraph, end of first sentence, and (3) p. 114, last paragraph. – GuM Dec 08 '16 at 01:21
  • @GustavoMezzetti Thanks a lot. I didn't think about two (protected) spaces. – Uwe Dec 08 '16 at 01:37
  • @cfr So, what else should I use to break lines? (Or do you mean that I shouldn't put a space after \ ?) – Uwe Dec 08 '16 at 01:42
  • Maybe tomorrow I’ll turn my comment into an answer, if I feel so inclined… (I’m very lazy! But the references I gave do contain the full explanation… :-) – GuM Dec 08 '16 at 01:52
  • No the space is just because SE gobbles the code without it. – cfr Dec 08 '16 at 02:18
  • http://tex.stackexchange.com/questions/82664/when-to-use-par-and-when-or-blank-lines http://tex.stackexchange.com/questions/138/what-are-underfull-hboxes-and-vboxes-and-how-can-i-get-rid-of-them http://tex.stackexchange.com/questions/27028/what-is-the-difference-between-newline-and etc. – cfr Dec 08 '16 at 02:29
  • \par\noindent is completely different to \\ in both action and meaning so there is never really a choice between them. The author should know whether or not a paragraph is ending at that point. – David Carlisle Dec 08 '16 at 07:55
  • @cfr I am familiar with the articles you refer to. They say that one should use \ to enforce a linebreak. (For the sake of discussion, you may assume that I don't use \ to end paragraphs, that I don't use \ as a replacement for \linebreak[n], that I don't use \ in the middle of ordinary running text in an article, and that I know when visual formatting is appropriate and when it's not.) – Uwe Dec 08 '16 at 09:45
  • @Uwe can we also assume you've been using latex since about 1985? :-) – David Carlisle Dec 08 '16 at 13:44
  • @DavidCarlisle I think that the first thing I wrote in LaTeX was my diploma thesis, so it must have been 1988. – Uwe Dec 08 '16 at 14:39
  • @Uwe ooh only one year before \\ was fixed for this issue then:-) – David Carlisle Dec 08 '16 at 14:41
  • @DavidCarlisle Given the maintenance of the LaTeX installation, I may still have encountered the problem in 1993 or so. – Uwe Dec 08 '16 at 14:43
  • Well, Beamer is non-standard anyway as you are already typesetting non-justified text regardless. – cfr Dec 08 '16 at 16:27

2 Answers2

16

You have good memory, the change predates LaTeX2e but in the latex sources you find...

  \begin{macro}{\@gnewline}
 \changes{v1.2u}{1996/10/29}{Added macro}
 The |\nobreak| added to prevent null lines when |\\|
 ends an overfull line.  Change made 24 May 89 as suggested by
 Frank Mittelbach and Rainer Sch\"opf

Similarly in the final sources of latex2.09 (latex.tex)

% \nobreak added to \newline to prevent null lines when \newline
% ends an overfull line.  Change made 24 May 89 as suggested by
% Frank Mittelbach and Rainer Sch\"opf
%
\def\newline{\ifvmode \@nolnerr \else \unskip\nobreak\hfil
  \penalty -\@M\fi}
David Carlisle
  • 757,742
10

You can get this if the word ends with a hyphen:

\documentclass[]{article}
\textwidth=1mm
\begin{document}
margin-\\xyz
\end{document}

enter image description here

Ulrike Fischer
  • 327,261