With the help of some methods presented here and by using grabbox
we can at least introduce this manually on a per paragraph basis (grabbox
so that the paragraph can still contain verbatim material).
I don't think this is possible in LaTeX to be automatically applied to every normal text paragraph.
It works by first collecting the paragraph into box register 0 as a \vbox
. This is done with \parfillskip=\parindent plus 1fil
so that TeX tries to have at least one \parindent
space in the last line. Next step is to store into a box register again (and again as a \vbox
), this is done so that we can do some alterations. First put the original contents back, then remove the last box (being the horizontal box of the last line) and store it in a box register. Next output that box register again but with a \hskip\parindent
before it, so that it'll be correctly indented.
We can do all this with a single box register 0 as the assignments are done locally and scoped within each nested use of a box.
Also we use some code from https://tex.stackexchange.com/a/463739/117050 to fix the space between consecutive \indentlastlinepar
s (which unfortunately needs another box register, the code would be way more confusing if it had only used register 0).
Beware: The current implementation creates paragraphs that are not page breakable.
\documentclass[]{article}
\usepackage{grabbox}
\newcount\myprevgraf
\newcommand\indentlastlinepar
{%
\par
\begingroup
\parfillskip\parindent plus 1fil\relax
% save the number of lines of the paragraph typeset in the box
\grabbox0\vbox[\par\global\myprevgraf\prevgraf]
{%
% measurement as in https://tex.stackexchange.com/a/463739/117050
\setbox0\vtop{\unvcopy0}%
\setbox2\vbox{\unvcopy0}%
\dimen0\dimexpr\dp0-\dp2\relax
% only make changes if the paragraph had more than one line
\ifnum\myprevgraf>1
% changing the last line as in
% https://tex.stackexchange.com/a/280035/117050
\setbox0\vtop
{%
\unvbox0
\setbox0\lastbox
\hbox to \linewidth{\hskip\parindent\unhbox0\uskip\unskip\hfill}%
}%
\fi
% introducing additional space and setting the correct depth as in
% https://tex.stackexchange.com/a/463739/117050
\dp0=\dp2
\box0
\vskip\dimen0
\endgroup
}%
}
\usepackage{duckuments}
\begin{document}
\indentlastlinepar{\blindduck[1]}
\indentlastlinepar{\blindduck[2]}
\indentlastlinepar{\blindduck[3]}
\indentlastlinepar{\blindduck[4]}
\indentlastlinepar{\blindduck[5]}
\indentlastlinepar{This is a paragraph containing \verb|\verbatim| material.}
\end{document}
An alternative that works if multiple consecutive \indentlastlinepar
are used and that is page breakable. You can suppress the additional space added above the paragraph by using the starred variant \indentlastlinepar*
.
\documentclass[]{article}
\usepackage{grabbox}
\newcount\myprevgraf
\NewDocumentCommand\indentlastlinepar{s}
{%
\par
\begingroup
\parfillskip\parindent plus 1fil\relax
% save the number of lines of the paragraph typeset in the box
\grabbox0\vtop[\par\global\myprevgraf\prevgraf]
{%
% only make changes if the paragraph had more than one line
\ifnum\myprevgraf>1
% changing the last line as in
% https://tex.stackexchange.com/a/280035/117050
\setbox0\vtop
{%
\unvbox0
\setbox0\lastbox
\hbox to \linewidth{\hskip\parindent\unhbox0\unskip\unskip\hfill}%
}%
\fi
% introducing additional space dependent on the current vtops height
\IfBooleanF{#1}
{%
\ifdim\ht0<\baselineskip
\vskip\dimexpr\baselineskip-\ht0\relax
\fi
}%
% unbox the contents
\unvbox0
\endgroup
}%
}
\usepackage{duckuments}
\begin{document}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{This is a paragraph containing \verb|\verbatim| material.}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{\blindduck[-]}
\indentlastlinepar{\blindduck[-]}
\end{document}

\linewidth - 1em
.