I was just wondering if there was a LaTeX tool for making paragraphs of text into perfect rectangles. The effect is shown below in a schematic

I was just wondering if there was a LaTeX tool for making paragraphs of text into perfect rectangles. The effect is shown below in a schematic

The parameter is \parfillskip; it's better to increase \emergencystretch not to confine all badness in one line. Paragraphs should be sufficiently long.
\documentclass{article}
\usepackage{microtype}
\usepackage{kantlipsum}
\setlength{\parindent}{0pt}
\setlength{\parskip}{.5\baselineskip}
\setlength{\parfillskip}{0pt} % don't fill the last line
\setlength{\emergencystretch}{.5\textwidth} % not to get preposterously bad lines
\begin{document}
\kant[1-3]
\end{document}

You can get the same behavior on a single paragraph if you end it with the combination
... here ends the paragraph.%
{\parfillskip=0pt \emergencystretch=.5\textwidth \par}
Notice the braces: the setting will be undone just after the paragraph has ended.
At the end of a paragraph, when \par is sensed (it's usually inserted automatically by TeX seeing an empty line), TeX removes horizontal glue (space) that might be present, then issues
\penalty10000 % no break here or the next glue would be removed
\hskip\parfillskip
\penalty-10000 % force a break
The usual value of \parfillskip is 0pt plus 1fill, so normally this will push the last line to be ragged right. If we set it to 0pt, the last line will be filled up. Of course, TeX must be able to find a suitable sequence of line breaks, or it will set a paragraph with underfull lines. In general it will prefer to concentrate all badness in one line; by setting \emergencystretch to a positive value, TeX will possibly reconsider the line breaks and distribute badness over all lines. See p. 100 of the TeXbook and exercise 14.15 (about modernistic novelist).
stretch=30 or stretch=40 for microtype in addition to the \emergencystretch setting (20 is the default).
– Stephan Lehmke
Nov 24 '13 at 12:41
microtype settings be slightly liberalized if we are pursuing the rectangular appearance?
– Simon Kuang
Feb 05 '16 at 23:03
\newcommand{\rectify}{{\parfillskip=0pt \emergencystretch=0.5\textwidth \par}}
– alan
Dec 15 '17 at 00:04
There are likely much better solutions, but using \linebreak at the end of a paragraph as a quickie seems to work:

\documentclass{article}
\begin{document}
\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget ante
pretium leo aliquet ultricies. Aenean ultrices facilisis sem nec
tempus. Aenean pretium odio eget diam congue feugiat. Sed faucibus
erat vel risus lobortis sit amet tincidunt justo mollis. Mauris id
volutpat sem. Praesent bibendum, dui vel tempus dictum, nisi risus
hendrerit eros, sed faucibus orci felis in neque. Vivamus ut nibh
lectus. Sed sit amet dolor eget diam tempus tempus vitae eget
leo. Cras imperdiet risus id ante molestie tincidunt. Mauris nec nunc
orci, vitae auctor velit. Proin gravida quam sit amet nulla tempor
condimentum auctor tellus facilisis.\par\bigskip
\noindent
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget ante
pretium leo aliquet ultricies. Aenean ultrices facilisis sem nec
tempus. Aenean pretium odio eget diam congue feugiat. Sed faucibus
erat vel risus lobortis sit amet tincidunt justo mollis. Mauris id
volutpat sem. Praesent bibendum, dui vel tempus dictum, nisi risus
hendrerit eros, sed faucibus orci felis in neque. Vivamus ut nibh
lectus. Sed sit amet dolor eget diam tempus tempus vitae eget
leo. Cras imperdiet risus id ante molestie tincidunt. Mauris nec nunc
orci, vitae auctor velit. Proin gravida quam sit amet nulla tempor
condimentum auctor tellus facilisis.\linebreak
\end{document}