Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am looking for a way to tell TeX:

Please break that line if and only if you are not on new line already.

I need this for a new environment which should always start in a new line. But I don't (how could I?) know, whether the author has typed a linebreak in front of that manually. I tried \linebreak, \\, and \newline, all of them caused the

LaTeX Error: There's no line here to end.

error, which I expected to show up, when trying

\newenvironment{mynewenvironment}{\\ \emph{Header:} }{}
[...]
random text \\
\begin{mynewenvironment}
text again
\end{mynewenvironment}

One can observe the same behavior with predefined environments, for instance

random text 
\begin{itemize}
\\ \item text
\end{itemize}

is causing the error but not

random text

\begin{itemize}
\item text
\end{itemize}

random text\begin{itemize}
\item text
\end{itemize}

Both are doing exactly how I want my environment to react, therefore I expect my problem to be solvable fairly easy, but I don't know how.

share|improve this question
    
Welcome to TeX.SE! There should be no reason to use a manual line break at all. Maybe if you put \par or an empty line there? –  tohecz Mar 4 '13 at 17:03
add comment

1 Answer

up vote 10 down vote accepted

You should almost never use \\ in a document other than ending tabular rows. Just use \par with an appropriate setting of \parskip and \parindent. Or for more general display environments copy the definition of the latex environments such as center or quote which are all defined in terms of list or trivlist which enables them to detect whether the following text needs to start a new paragraph or not. quote for example is simply defined as:

\newenvironment{quote}
               {\list{}{\rightmargin\leftmargin}%
                \item\relax}
               {\endlist}
share|improve this answer
    
Thank you very much! \par does the trick I was looking for, and with the hints from the quote environment I am very happy now =) –  Dominikus K. Mar 4 '13 at 17:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.