Difference between revisions of "Indentation"

From Wiki
Jump to navigation Jump to search
Line 128: Line 128:
{{note|type=attention|1=Indentation inside itemize works differently in MkIV: <code>indenting={40pt,yes}</code> also indents the first line! To get the visual output shown above in MkIV, use <code>indenting={40pt,'''next'''}</code>.}}
= Manual indentation =
= Manual indentation =

Revision as of 17:50, 16 April 2011

< Visuals

In plain TeX, controlling indentation is simple: The user sets a value for \parindent, and each new paragraph is indented by that value, unless explicitly begun with \noindent. Environments can provide a \noindent at the end of their definitions, and if the user wants to overrule that, he can add an explicit \indent at the beginning of the next paragraph. For the most part, LaTeX follows the same convention.

So, understanding indentation in plain TeX and LaTeX boils down to this: set a value for \parindent, and start a new paragraph (i.e., leave an empty line) whenever you want indentation. For example, LaTeX usually does not indent the first line after a sectioning command. If you want to indent the first line after a sectioning command you use the indentfirst package (which is part of the required LaTeX bundle). If you want to indent the paragraph after an environment, you leave a blank line after the end of the environment; if you do not want to indent after the end of an environment, you do not leave a blank line. It takes a while to get used to, but the rules are easy to remember and eventually you do not need to even think about indentation; it becomes a matter of habit.

Indentations in ConTeXt are a bit different; and sometimes difficult to understand. In this article I hope to explain how ConTeXt does indentations. First, let's understand why ConTeXt does indentations differently; why does it not simply follow the time-tested approach of plain TeX and LaTeX? The way I understand it, the reason is that Hans Hagen, the author of ConTeXt, prefers spaced out markup — surrounding each environment by empty lines — which makes it easy to see where an environment starts and ends while reading the source file. However, this style means that the 'indentation after empty lines' paradigm of plain TeX and LaTeX cannot be used for indentations. So, ConTeXt provides an alternative. As with other things in ConTeXt, this alternative is consistent and easy to configure; but if you are used to other TeX formats it takes some time to get comfortable with it.

The basics

Setting up indentation for the whole document

Indentation involves two things: when to indent, and how much to indent. In ConTeXt, these can be specified using \setupindenting[...]. There are two types of keys for this command:

  • To specify when to indent: never or always, (equivalently, no or yes), odd or even, and first or next.
  • To specify how much to indent: none, small, medium, big, or a specific dimension. small corresponds to 1em, medium to 1.5em, and big to 2em.

Suppose we want to indent all paragraphs by 20pt: we can use

\setupindenting[20pt, yes]

This is what one typically uses in a document. The other keys are needed only for special cases (like typesetting quotations and verses). In particular:

  • odd indents every odd paragraph
  • even indents every even paragraph
  • first indents the first paragraph
  • next does not indent the first paragraph, but indents every subsequent paragrah

Setting up indentation after an environment

\setupindenting does not take care of indenting after environments, such as ConTeXt's itemizes, enumerations, definitions, formulas and floats. It also does not take care of indenting after heads such as chapters, sections, and subsections.

The setup command of these environments provides an indentnext key to configure the indentation behaviour after the environment. The indentnext key can take one of three values: yes, no, and auto. If indentnext=yes then the paragraph after the end of the environment is always indented; if indentnext=no then the next paragraph is never indented; if indentnext=auto then the next paragraph is indented only if there is a blank space after the environment. Setting indentnext=auto is equivalent to the default plain TeX and LaTeX behaviour.

Let us provide a couple of examples. Suppose we do not want paragraphs after itemize to be indented; then we can say


If we want paragraphs after section heads to be indented, we can say


If we want the paragraphs after all sectioning heads to be indented, we can say


If we want paragraphs after formulas to be indented only if we leave a blank space after them, we can say


Setting up indentation inside environments

There is one case that is not taken care of by \setupindenting and the indentnext key: indentation of paragraphs inside multi-paragraph environments such as itemizes, descriptions, and enumerations. By default ConTeXt does not indent such paragraphs. The setup commands of these environments provides an indenting key to configure the indentation behaviour of paragraphs inside these environments. This key takes the same values as the arguments of \setupindenting command. For example, if we set


then the following :

\item This is an example of a multi|-|paragraph 
      item inside an itemize environment.

      This second paragraph is indented by 40pt
      (double the normal indentation).


NOTE: Indentation inside itemize works differently in MkIV: indenting={40pt,yes} also indents the first line! To get the visual output shown above in MkIV, use indenting={40pt,next}.

Manual indentation

No matter how careful we are with all the settings, there are some cases which cannot be taken care of by automatic indentation, and we have to tell ConTeXt how to indent. Plain TeX (and LaTeX) provide the \indent and \noindent commands for explicitly indenting and preventing indenting of a paragraph. These commands are defined in ConTeXt but are not hooked into the ConTeXt indentation mechanism. Instead, ConTeXt provides \indentation and \noindentation which achieve the same effect.

Suppose the default setup for an article is

\setupitemgroup [itemize] [indentnext=no]

Now, if we want to indent after an itemize, starting the next paragraph with \indent does not work; to get indentation we have to say \indentation. For example,

\setupindenting [big,yes]
\setupitemgroup [itemize] [indentnext=no]
\item A dummy list
\item To check \type{\indent}

\indent This paragraph is not indented. The 
\type{\indent} command does not work here.

\item Another dummy list
\item To check \type{\indentation}

\indentation This paragraph will be indented
because we used \type{\indentation} instead.


Beware of typos

ConTeXt defines two more commands not commonly used: \indenting and \noindenting. \indenting is similar to \setupindenting and is provided for backward compatibility; \noindenting is equivalent to \setupindenting[no]. Unfortunately, these commands sound very similar to \indentation and \noindentation, thus can be easily used by mistake. If you happen to write \noindenting instead of \noindentation in a document, it can take a while to debug.