4

Is it possible somehow to highlight/mark lines with the following properties?

  1. It is a last line of a paragraph
  2. AND:
    • either it ends within 1 em of the right end of the text width;
    • or it contains less than 7 characters.

An overfull warning will mark the overfulled lines in draft mode. I am looking for something similar to be able to automatically mark lines which are not according to certain typographic guidelines. And then for example the "almost full" last lines of paragraphs could be corrected according to this TexExchange answer

Update: I suspect, that there is a (high?) correlation with this recent question.

1 Answer 1

1

This is not exactly what is asked, but in a pinch it may help. First, let's discuss what is bad about this approach:

  1. It requires an environment ProcessPars to set off the text to be examined.

  2. It can't count 7 characters from the left margin; rather, it looks for the final line being less than 7ex in width.

  3. If the last paragraph line is squeezed at all, the highlight mark shows up on the next line all by itself.

The MWE, in which paragraphs that meet the requirement are set off with a red bullet in the left margin.

\documentclass{article}
\usepackage{tabto,xcolor,environ}
\newcommand\checkloc{%
  \tabto*{-20pt}%
  \ifdim\TabPrevPos<7ex\relax\makemark\else%
    \ifdim\TabPrevPos>\dimexpr\linewidth-1em\relax\relax\makemark\fi%
  \fi
  \tabto{\TabPrevPos}%
}
\newcommand\makemark{\textcolor{red}{$\bullet$}}
\long\def\processparsaux#1\par#2\relax{%
  #1\checkloc\par\ifx\relax#2\relax\else\processparsaux#2\relax\fi%
}
\NewEnviron{ProcessPars}{\expandafter\processparsaux\BODY\par\relax}
\newcommand\showrules{%
  \noindent\hspace{7ex}\smash{\rule[-\textheight]{.4pt}{\textheight}}\hfill%
  \smash{\rule[-\textheight]{.4pt}{\textheight}}\hspace{1em}\mbox{}\par
}
\begin{document}
\showrules
\begin{ProcessPars}
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. 

This is a test. This is a test. This is a test. This is a test. This is big/fat.

This is a test. This is a test. This is a test. This is a test. This is a big test.

This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.

This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test.

This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
\end{ProcessPars}
\end{document} 

enter image description here

1
  • I like the basic solution, but sadly it has some interference with microtype ("! error: (file cmr10:kernfactor=0.010;) (type 3): font cmr10:kernfactor=0.010; at 600 not found"). For some paragraphs it works, for some compilation fails with this error... any ideas on this one?
    – D. Kovács
    Commented Nov 4, 2017 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .