TransWikia.com

TeX/LuaTeX: Will the typeset output of par, and indent ever differ? Why do they add separate glues?

TeX - LaTeX Asked on December 6, 2020

Visually speaking, ending one paragraph and beginning another is just a matter of inserting a linebreak and an (potential) indent. Two ways come to mind to achieve this: par (or empty line) and indent. In my testing below, they produce exact same result visually. Is there any case where the two will produce results that differ even slightly (like kern, hypehnation/linebreak, font expansion, etc)? Will tex.linebreak be called internally only once for all text if indent were used? (AFAIK tex.linebreak is called on each chunk of text separated by par (or empty lines)) Given tex’s linebreaking algorithm tries to optimize some metrics across linebreaks, and using indent means all linebreaks (even across visually different paragraphs) are considered together for optimization, will this result in slowdown when number of linebreaks increase a lot?

Here’s console output, code, and screenshot of output that compares par, and indent side-by-side:

Console:

indent adds:
......penalty 10000
......glue 0.0 plus 1.0fil
......penalty -10000

par adds:
......penalty 10000
......glue(parfillskip) 0.0 plus 1.0fil

Why does add some unnamed glue glue 0.0 plus 1.0fil vs glue(parfillskip) 0.0 plus 1.0fil added by par? Is there a separate named glue or way of controlling glue added by or will it always equal glue added by parfillskip (like it is in this case 0.0 plus 1.0fil)? If it is same by default, then why is there a hook to control one, and not another?

Code:

>>> lualatex par_or_linebreak.tex
documentclass{article}
usepackage[english]{babel}
usepackage{blindtext}
usepackage[paper=a2paper,lmargin=2in,tmargin=2in,rmargin=0.5in,bmargin=0.5in]{geometry}
usepackage[absolute]{textpos}
setlength{TPHorizModule}{1in}
setlength{TPVertModule}{1in}
textblockorigin{0in}{0in}

begin{document}
showoutput
sloppy
thispagestyle{empty}

newcommand{sampletext}{This an equation $x=a+b^2$  without any intrinsic meaning unless one sees some. textbf{And this is some bold text to add some variety to this piece of text.} And am typing here,  difference diffierence $b=c^3$. blindtext[1]}

newcommand{sampletextmore}{blindtext[2]}

newsavebox{vboxwithpar}
setboxvboxwithpar = vbox{{hsize=2inrelaxnoindentsampletextparsampletextparsampletextparsampletextmorepar}}

newsavebox{vboxwithlinebreak}
setboxvboxwithlinebreak = vbox{{hsize=2inrelaxnoindentsampletextindentsampletextindentsampletextindentsampletextmorepar}}

begin{textblock*}{2in}(1in,0.25in)
copyvboxwithpar
end{textblock*}

begin{textblock*}{2in}(3.5in,0.25in)
copyvboxwithlinebreak
end{textblock*}

end{document}

Output:

Screenshot of output

One Answer

enter image description here

par ends the paragraph but does not so using is noindent almost never the correct markup, although can accidentally give the same visual output.

see When to use par and when , newline, or blank lines

It is easy to see examples of different vertical space perhaps a less obvious one is to have different linebreaking. I used a high value of finalhyphendemerits here to make it a bit simpler to construct an example, but you could see the same effect even with the more moderate value of finalhyhendemerits in the standard class settings.

documentclass{article}

finalhyphendemerits=100000

begin{document}

deftxt{%
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours  forzzzz different markup.zz
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different markup.
Random words in example paragraph text,
showing different behaviours for different.
}

noindent
begin{minipage}[t]{6cm}
defzz{par}
txt 
end{minipage}quad
begin{minipage}[t]{6cm}
defzz{indent}
txt 
end{minipage}

end{document}

For the question in the title, on different glue, there is no reason to expect that the glue is the same. par is a tex primitive that causes the tex primitive parfillskip glue to be added, is a macro that in its standard latex definition ends up using

def@gnewline #1{%
  ifvmode
    @nolnerr
  else
    unskip reserved@e {reserved@f#1}nobreak hfil break
  fi}

so adds hfil glue.

Correct answer by David Carlisle on December 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP