Changes

Jump to navigation Jump to search
164 bytes removed ,  12:03, 11 June 2012
m
Narrower examples, no more <cmd> tags
< [[Visuals]]
In plain TeX, controlling indentation is simple: The user sets a value for<cmdtt>parindent</cmdtt>, and each new paragraph is indented by that value, unlessexplicitly begun with <cmdtt>noindent</cmdtt>. Environments can provide a<cmdtt>noindent</cmdtt> at the end of their definitions, and if the user wants tooverrule that, he can add an explicit <cmdtt>indent</cmdtt> at the beginning of the nextparagraph. For the most part, LaTeX follows the same convention.
So, understanding indentation in plain TeX and LaTeX boils down to this: set avalue for <cmdtt>parindent</cmdtt>, and start a new paragraph (i.e., leave an emptyline) whenever you want indentation. For example, LaTeX usually does not indentthe first line after a sectioning command. If you want to indent the first lineafter a sectioning command you use the <code>indentfirst</code> package (whichis part of the required LaTeX bundle). If you want to indent the paragraph afteran environment, you leave a blank line after the end of the environment; if youdo not want to indent after the end of an environment, you do not leave a blankline. It takes a while to get used to, but the rules are easy to remember andeventually you do not need to even think about indentation; it becomes a matterof habit.
Indentations in ConTeXt are a bit different; and sometimes difficult tounderstand. In this article I hope to explain how ConTeXt does indentations.First, let's understand why ConTeXt does indentations differently; why does itnot simply follow the time-tested approach of plain TeX and LaTeX? The way Iunderstand it, the reason is that Hans Hagen, the author of ConTeXt, prefers''spaced out'' markup &mdash; surrounding each environment by empty lines&mdash; which makes it easy to see where an environment starts and ends whilereading the source file. However, this style means that the 'indentation afterempty lines' paradigm of plain TeX and LaTeX cannot be used for indentations.So, ConTeXt provides an alternative. As with other things in ConTeXt, thisalternative is consistent and easy to configure; but if you are used to otherTeX 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. InConTeXt, these can be specified using <tt>{{cmd>|setupindenting}}[...]</cmdtt>. Thereare three types of keys for this command:
* '''To enable indenting:''' <code>never</code> or <code>always</code>, (equivalently, <code>no</code> or <code>yes</code>), The default is '''<code>never</code>'''
<texcode>\setupindenting[20pt, yes, first]</texcode>
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, the most commonlyused keys are
* <code>yes</code> enable indenting
== Setting up indentation after an environment ==
<{{cmd>|setupindenting</cmd> }} does not take care of indenting after environments,such as ConTeXt's itemizes, enumerations, definitions, formulas and floats. Italso does not take care of indenting after heads such as chapters, sections, andsubsections.
The setup command of these environments provides an'''<code>indentnext</code>''' key to configure the indentation behaviour afterthe environment. The <code>indentnext</code> key can take one of three values:<code>yes</code>, <code>no</code>, and <code>auto</code>. If<code>indentnext=yes</code> then the paragraph after the end of the environmentis always indented; if <code>indentnext=no</code> then the next paragraph isnever indented; if <code>indentnext=auto</code> then the next paragraph isindented only if there is a blank space after the environment. Setting<code>indentnext=auto</code> is equivalent to the default plain TeX and LaTeXbehaviour.  Let us provide a couple of examples. Suppose we do not want paragraphs afteritemize to be indented; then we can say
Let us provide a couple of examples. Suppose we do not want paragraphs after itemize to be indented; then we can say
<texcode>
\setupitemgroup[itemize][indentnext=no]
</texcode>
If we want the paragraphs after all sectioning heads to beindented, we can say
<texcode>
</texcode>
If we want paragraphs after formulas to be indented only if weleave a blank space after them, we can say
<texcode>
== Setting up indentation inside environments ==
There is one case that is not taken care of by <{{cmd>|setupindenting</cmd> }} and the<code>indentnext</code> key: indentation of paragraphs inside multi-paragraphenvironments such as itemizes, descriptions, and enumerations. By defaultConTeXt does not indent such paragraphs. The setup commands of theseenvironments provides an '''<code>indenting</code>''' key to configure the indentationbehaviour of paragraphs inside these environments. This key takes the samevalues as the arguments of <{{cmd>|setupindenting</cmd> }} command. For example, if we set 
<texcode>
\setupitemgroup[itemize][indenting={40pt,next}]
then the following :
<context source="yes" text="gives" scale="0.8">\setuppapersize[A5] 
\setupindenting[medium,yes]
\setupitemgroup[itemize][indenting={40pt,next}]
\stopitemize
</context>
 
{{note|type=attention|1=Indentation inside itemize works differently in MkII: <code>indenting={40pt,yes}</code> does not indent the first line!}}
= Manual indentation =
No matter how careful we are with all the settings, there are some cases whichcannot be taken care of by automatic indentation, and we have to tell ConTeXthow to indent. Plain TeX (and LaTeX) provide the <{{cmd>|indent</cmd> }} and <{{cmd>|noindent</cmd>}} commands for explicitly indenting and preventing indenting of a paragraph. Thesecommands are defined in ConTeXt but are not hooked into the ConTeXtindentation mechanism. Instead, ConTeXt provides <{{cmd>|indentation</cmd> }} and<{{cmd>|noindentation</cmd> }} which achieve the same effect.
Suppose the default setup for an article is
</texcode>
Now, if we want to indent after an itemize, starting the next paragraphwith <{{cmd>|indent</cmd> }} does not work; to get indentation we have to say<{{cmd>|indentation</cmd>}}. For example, <context source="yes" text="gives">\setuppapersize[A5]
<context source="yes" text="gives" scale="0.8">
\setupindenting [big,yes]
\setupitemgroup [itemize] [indentnext=no]
 
\startitemize[n]
\item A dummy list \item To check \type{\indent}
\stopitemize
\indent This paragraph is not indented. The
\type{\indent} command does not work here.
\startitemize[n]
\item Another dummy list \item To check \type{\indentation}
\stopitemize
\indentation This paragraph will be indented
because we used \type{\indentation} instead.
</context>
= Beware of typos =
ConTeXt defines two more commands not commonly used:<{{cmd>|indenting</cmd> }} and <{{cmd>|noindenting</cmd>}}. <{{cmd>|indenting</cmd> }} is similar to<{{cmd>|setupindenting</cmd> }} and is provided for backward compatibility;<{{cmd>|noindenting</cmd> }} is equivalent to<{{cmd>|setupindenting[no]</cmd>}}. Unfortunately, these commands sound verysimilar to <{{cmd>|indentation</cmd> }} and <{{cmd>|noindentation</cmd>}}, thus can be easily used by mistake. If you happen to write <{{cmd>|noindenting</cmd> }} instead of<{{cmd>|noindentation</cmd> }} in a document, it can take a while to debug.

Navigation menu