This question led to a new package:
nowidow
I'm trying to define a dynamic \begingroup
command to get rid of widows:
\usepackage{pgffor}
\newcommand{\nowidow}[1][2]{%
\begingroup\widowpenalties #1 \foreach \n in {2,...,#1}{10000 } 0
\par\endgroup
}
This fails complaining that \begingroup
requires a number and I'm guessing this has to do with expansion.
Here is a MWE:
\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{pgffor}
\newcommand{\nowidow}[1][2]{%
\begingroup\widowpenalties #1 \foreach \n in {2,...,#1}{10000 } 0
\par\endgroup
}
\begin{document}
\lipsum
\nowidow
\end{document}
How can I get this to work? Would it be easier (although less portable) to do it in Lua?