[Tex/LaTex] Defining rules for line breaks in \newcommand

amsthmline-breakingmacrosrules

Thanks to the help of this answer, I've defined a command for creating a blank line:

\newcommand{\blank}[1]{\rule{#1}{0.4pt}}

However, because this is a user-defined command, LaTeX doesn't seem to factor it in to its calculations of when to start a new line. For example, if I write:

This is a long line and the blank line at the end is going to run off the page \blank{6cm}

then the blank line at the end runs off the page. How can I prevent this from happening?

EDIT: This actually only happens in a specific case: when I'm in the amsthm package's proof environment, and I have at least one line of writing followed by an enumeration.

\documentclass{article}
\usepackage{amsthm}
\newcommand{\blank}[1]{\rule[-3pt]{#1}{0.4pt}}  % nice blank underscores
\begin{document}
\begin{proof}
Here is my proof:
\begin{enumerate}
\item This is a long line and the blank line is going to run off \blank{8cm}
\item This is the second line.
\end{enumerate}
\end{proof}
\end{document}

Even when the blank line doesn't run off the page, I still get an overfull hbox warning for each instance of \blank I have within an enumerate in a proof.

Best Answer

If you want that the rule goes automatically on the next line if it can't be placed in the current one, just say

\newcommand{\blank}[2][100]{\hfil\penalty#1\hfilneg\rule[-3pt]{#2}{0.4pt}}

This is modeled on the \filbreak macro in the TeXbook.

The default penalty is 100, which discourages a line break. In cases of emergency you can insert a different one as optional argument:

 \blank[0]{3cm}

enter image description here

Related Question