TransWikia.com

Line-Breaking Around clearpage

TeX - LaTeX Asked on December 8, 2020

AFAIK, line-breaking around begin{document}, end{document}, or begin{section} doesn’t change the results as follows.

documentclass{article}
                        % INSERTING OR DELETING THIS LINE DOESN'T AFFECT THE OUTCOME
begin{document}
                        % INSERTING OR DELETING THIS LINE DOESN'T AFFECT THE OUTCOME
Hello, world!
                        % INSERTING OR DELETING THIS LINE DOESN'T AFFECT THE OUTCOME
end{document}

I wonder if this is the same for clearpage. I think there are seven possible spots for clearpage that seemingly produce the same output. Do they have no logical difference from one another?

Spot 1: The spot right after the first paragraph.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.clearpage

This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 2: The spot right below the first paragraph.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
clearpage

This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 3: Two lines away from both the first and second paragraphs.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.

clearpage

This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 4: The spot right above the second paragraph.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.

clearpage
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 5: The spot right before the second paragraph.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.

clearpage This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 6: In the middle of the two paragraphs with no additional line break.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
clearpage
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

Spot 7: Just at the beginning of the second paragraph with no line break.

documentclass{article}
begin{document}
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
clearpage This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
end{document}

I think either Spot 1 or Spot 3 is more readable than others, and Spot 7 is the shortest code among all the candidates with the same outcome. I wonder if pursuing easy-reading (or space-saving sometimes) coding practice unexpectedly influences the results.

One Answer

Unlike pagebreak, clearpage (via newpage) inserts a par before processing, and after processing is consequently already in vertical mode. this means that putting a blank line (par) before or after makes no difference. However a blank line is the standard document markup for paragraph breaks so I would always add a blank line between paragraphs (doesn't really matter whether that is before or after the clearpage) rather than rely on the technical detail that clearpage ends the current paragraph.

If you try your examples with pagebreak instead of clearpage you will see a big difference between the cases with the versions with no blank line being set as a single paragraph, not two.

Correct answer by David Carlisle on December 8, 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