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'm using TeXLive (pdftex) with TexShop on my Mac and usually, I don't format my .tex files. Now that I have to write some bigger ones, the code soon gets too messy to read and I tried to insert some newlines/returns to divide my code blocks. So why does my TeX package (or my TexShop) turn this into additional newlines and on top of that, indents?

For example, consider this minimum example:

\documentclass[10pt,a4paper,fleqn]{article}
\begin{document}
\section{Test}
\subsection{Sub1}
A line\\\\

newline
\end{document}

Why does this turn into (something like) this:

A Line



___newline

Is this some feature of TeX? I really want to format my code, can I turn this off somewhere?

edit (solved):

ok, as egreg said, I'm now using an empty line to end a paragraph. With this, my code gets a bit cleaner. But now, something like this:

\documentclass[10pt,a4paper,fleqn]{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{defi}{Definition}[section]
\begin{document}
\begin{defi}
....
\end{defi}

\begin{defi}
....
\end{defi}
\end{document}

(just as an example) compiled, these two theorems get (visually) really close to each other (less line spacing than between two \items of an itemize, even though I inserted a blank line there), which I think, does not look good. Why is this? Basically I am asking when to use \\, \\\\ and a blank line, now that you all shattered my beliefs ;D

edit 2: solved it myself, just removed \usepackage{parskip} and now it looks really nice. thank you all!

share|improve this question
    
The indent in the output is standard in the article (or other) document class. The indentation length is governed by \parindent. If you want to remove that in the output, use \setlength{\parindent}{0pt} at the start of your document. However, other environments that may use \parindent could not work as expected anymore. –  Werner Oct 22 '11 at 21:58
    
We could probably give you better answers or suggestions if you told us what exactly are you trying to achieve. How do you want to format you tex file, and what output do you expect it to produce. –  Jan Hlavacek Oct 22 '11 at 22:55

3 Answers 3

up vote 1 down vote accepted

if you want a paragraph skip instead of the indentation then set:

\setlength\parindent{0pt}
\setlength\parskip{\medskipamount}
share|improve this answer
    
I thought parskip should only be set using the parskip package? –  Martin Scharrer Oct 23 '11 at 9:51
    
if you like the skips for lists, yes. But I do not like it ... –  Herbert Oct 23 '11 at 12:06

You shouldn't use \\ to end a paragraph, but an empty line. This will also polish your LaTeX code.

The indent in front of a paragraph is correct. If you really need to "leave a blank line", then write something like

... here the end of a paragraph.

\medskip

Here a new paragraph starts ...

However a "blank line" is seldom necessary.

share|improve this answer
    
if i use an empty line instead of \\\\, those two blocks of theorems: \begin{example}...\end{example} \begin{example}...\end{example} are really close, is that really how it should be? –  Eike Cochu Oct 22 '11 at 22:58
    
How do you define the example environment? Please, edit your question to show it. –  egreg Oct 22 '11 at 23:01

You already have some good answers, but let me try to explain what is going on:

1) TeX uses empty lines (to be more precise, blocks of empty lines) as paragraph separators. So writing

...blah blah blah.

Blah blah blah...

will end the first paragraph after blah. and start a new paragraph with Blah. In TeX, first line of each paragraphs is indented by default. The exceptions are first paragraphs in each sectioning unit. That's why in your example, the paragraph immediately after the \subsection does not get indented.

So the above code will produce something like:

...blah blah blah.
    Blah blah blah...

2) In LaTeX, double backslash \\ is used for new line. So \\\\ will insert two new lines.

So TeX is doing exactly what you told it to do: insert two new lines and end the paragraph, then start the new paragraph with an indent. As others noted, that is really isn't how LaTeX is supposed to be used. LaTeX is supposed to be mostly logical markup. To insert a configurable vertical space after a paragraph, I would recommend using the \vspace command. If you want to have a single paragraph without indentation, you can start it with \noindent. Herbert already explained how to make LaTeX remove indentation from all paragraphs, and replace it by a vertical space.

share|improve this answer
    
Of course, \\\\ will always produce an Underfull \hbox warning. –  egreg Oct 22 '11 at 23:02

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.