0

I am aware that this is a hyper specific question but I have been playing around with making all paragraphs perfect rectangles just like in this StackExchange question. And as in these older threads I am experiencing the same problems. But I am still trying to make them less bad.

  1. The first problem is probably easier to fix: The changes to parfillskip and the other parameters do not take affect in any environments like enumerate and itemize in the example below. But I also want to have rectangular paragraphs there.
  2. This is probably much harder to fix and just an idea of mine. Is it possible to make the changes to the lengths only apply when the paragraph exceeds a certain length? Maybe there is some way to get the length of a paragraph to then only use the \setlength in the preamble when the length is greater than some given length.

I am also aware that this is not exactly what is intended with LaTeX as the looks should be the less important part but I still want to experiment a bit with it.

Here is a minimal working example which shows the problems

\documentclass[a4paper]{article}

\usepackage{blindtext}
\usepackage{lmodern}

\usepackage[stretch=30]{microtype} \usepackage{etoolbox}

% Enbale rectangular paragraphs \setlength{\parindent}{0pt} \setlength{\parskip}{.5\baselineskip} \setlength{\parfillskip}{0pt} \setlength{\emergencystretch}{.5\textwidth} \makeatletter \patchcmd{@sect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{} \patchcmd{@ssect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{} \makeatother

\begin{document} Too short paragraph that gets ruined and where the changed lengths should not apply \section{Lorem ipsum} \blindtext \begin{itemize} % No affect here \item \blindtext \end{itemize} \begin{enumerate} % No affect here \item \blindtext \end{enumerate} \end{document}

1 Answers1

0

Unfortunately I was not able to completely fix all the problems but I have now created an environment which only changes things like parfillskip if there are enough lines that the whitespaces will not be too large. The environment still has problem number 1 and enumeration of sections etc. also get messed up:

\documentclass[a4paper]{article}

\usepackage{blindtext}
\usepackage{microtype}

\usepackage{calc} \usepackage{etoolbox} \usepackage{pgf}

% Standard changes to paragraphs \setlength{\parindent}{0pt} \setlength{\parskip}{.5\baselineskip}

\makeatletter \patchcmd{@sect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{} \patchcmd{@ssect}{\begingroup}{\begingroup\parfillskip=0pt plus 1fil\relax}{}{} \makeatother

% Get lengths to count lines \newlength{\parline} \newlength{\paroutindent} \newlength{\lineheight} \setlength{\lineheight}{\heightof{abcdefghijklmnoprstuvwxyzüäöß}}

\newcommand{\txtblck}[1]{ \setlength{\paroutindent}{\expandafter\parindent} \setlength{\parline}{\heightof{\noindent\begin{minipage}{\linewidth} \setlength{\parindent}{\paroutindent}#1\end{minipage}}} \pgfmathparse{round(\parline / (0.9*\lineheight))}

\ifdim\pgfmathresult pt > 3.0pt % Text is long enough -> Rectangular
\setlength{\emergencystretch}{.5\textwidth} \setlength{\parfillskip}{0pt} #1

% Reset values
\setlength{\emergencystretch}{11.8 pt}
\setlength{\parfillskip}{0pt plus 1fil}

\else % Text is too short for perfect rectangle #1 \fi }

\begin{document} \section{Test} \txtblck{\section{Lorem ipsum} \blinddocument} But this is unaffected \txtblck{As well as this} \end{document}

One could try to fix this by changing how the lines are counted because I think this is the reason that the section numbering is increasing too much