Note: This question is not about getting a desired visual effect in pdf, it is concerned with LaTeX/TeX internal algorithm.
In the following code, presence of \\
sometimes produces a new internal tex-paragraph when encountered in the middle of a user-paragraph, and sometimes does not. In normal text mode, the only time it seems to not produce a new paragraph is when in fully-justified (default) alignment mode.
So the question is why did LaTeX team code this discrepancy? Was it to avoid changing the paragraph indentation for partial tex-paragraphs? Is it any better than starting a new paragraph with no indent in fully justified mode (like \par\vspace{1cm}\noindent
instead of \\[1cm]
)?
Code (lualatex):
% >> lualatex par_vs_backslashes.tex
\documentclass{article}
\directlua{
nodetree = require"nodetree"
function filterprint(h)
nodetree.print(h)
return h
end
luatexbase.add_to_callback("pre_linebreak_filter",filterprint,"filterprint")
}
\begin{document}
% This produces 2 tex-internal paragraphs
Hello\\[1cm] foo\par\vspace{1cm} world
\raggedright
% This produces 3 tex-internal paragraphs
Hello\\[1cm] foo\par\vspace{1cm} world
\end{document}
Console:
% Output for fully-justified mode:
├─LOCAL_PAR
├─HLIST subtype: indent, width: 15pt
├─GLYPH subtype: 256, char: H, width: 7.5pt, height: 6.83pt
├─GLYPH subtype: 256, char: e, width: 4.44pt, height: 4.48pt, depth: 0.11pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
├─ADJUST
│ ╚═head:
│ └─GLUE width: 28.45pt
├─PENALTY penalty: 10000
├─GLUE stretch: +1fil
├─PENALTY penalty: -10000
├─GLUE subtype: spaceskip, width: 3.33pt, stretch: 1.66pt, shrink: 1.11pt
├─GLYPH subtype: 256, char: f, width: 3.06pt, height: 7.05pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
├─KERN kern: 0.28pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
│ ╚═ properties: {['injections'] = {['leftkern'] = 18350.08}}
├─PENALTY subtype: linepenalty, penalty: 10000
└─GLUE subtype: parfillskip, stretch: +1fil
├─LOCAL_PAR
├─HLIST subtype: indent, width: 15pt
├─GLYPH subtype: 256, char: w, width: 7.22pt, height: 4.31pt, depth: 0.11pt
├─KERN kern: -0.28pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
│ ╚═ properties: {['injections'] = {['leftkern'] = -18350.08}}
├─GLYPH subtype: 256, char: r, width: 3.92pt, height: 4.42pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: d, width: 5.56pt, height: 6.94pt, depth: 0.11pt
├─PENALTY subtype: linepenalty, penalty: 10000
└─GLUE subtype: parfillskip, stretch: +1fil
% Output for rest of the modes (\raggedright, etc):
├─LOCAL_PAR
├─HLIST subtype: indent
├─GLYPH subtype: 256, char: H, width: 7.5pt, height: 6.83pt
├─GLYPH subtype: 256, char: e, width: 4.44pt, height: 4.48pt, depth: 0.11pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
├─PENALTY subtype: linepenalty, penalty: 10000
└─GLUE subtype: parfillskip, stretch: +1fil
├─LOCAL_PAR
├─HLIST subtype: indent
├─GLYPH subtype: 256, char: f, width: 3.06pt, height: 7.05pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
├─KERN kern: 0.28pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
│ ╚═ properties: {['injections'] = {['leftkern'] = 18350.08}}
├─PENALTY subtype: linepenalty, penalty: 10000
└─GLUE subtype: parfillskip, stretch: +1fil
├─LOCAL_PAR
├─HLIST subtype: indent
├─GLYPH subtype: 256, char: w, width: 7.22pt, height: 4.31pt, depth: 0.11pt
├─KERN kern: -0.28pt
├─GLYPH subtype: 256, char: o, width: 5pt, height: 4.48pt, depth: 0.11pt
│ ╚═ properties: {['injections'] = {['leftkern'] = -18350.08}}
├─GLYPH subtype: 256, char: r, width: 3.92pt, height: 4.42pt
├─GLYPH subtype: 256, char: l, width: 2.78pt, height: 6.94pt
├─GLYPH subtype: 256, char: d, width: 5.56pt, height: 6.94pt, depth: 0.11pt
├─PENALTY subtype: linepenalty, penalty: 10000
└─GLUE subtype: parfillskip, stretch: +1fil
Output: