注意:这个问题不是关于在pdf中获得所需的视觉效果,而是与LaTeX / TeX内部算法有关。
在下面的代码中,\\
当在用户段落中间遇到时,有时会产生一个新的内部 tex 段落,有时则不会。在正常文本模式下,似乎唯一不会产生新段落的情况是在完全对齐(默认)对齐模式下。
那么问题是为什么 LaTeX 团队要对这种差异进行编码?是为了避免更改部分 tex 段落的段落缩进吗?这是否比在完全对齐模式下开始一个没有缩进的新段落更好(例如\par\vspace{1cm}\noindent
而不是\\[1cm]
)?
代码(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}
安慰:
% 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
输出:
答案1
这早于“LaTex 团队”的参与,可以追溯到 Leslie Lamport 的原始 LaTeX 版本,所以我无法真正说出“为什么”,只是确认你的观察是正确的。
记录的行为\\
是它永远不会结束段落,它只是强制换行,但是在\centering
和类似的设置中\\
被重新定义,并且正如你所说,内部使用,\par
这是一种遗憾,因为有时实现细节变得可观察到,例如当\parskip
非零时(尽管 latex 试图通过在引入的段落分隔符后添加负 \parskip 空格来隐藏它\\
)
\documentclass{article}
\parskip=1in
\begin{document}
\begin{center}
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
zzz\linebreak zzz aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
\end{center}
\begin{center}
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
zzz\\ zzz aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
\end{center}
\begin{center}
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
zzz\par zzz aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa
\end{center}
\end{document}