Difference between revisions of "Description"

From ConTeXt wiki
(A bit more explanation, improvement of examples.)
(Some header-level changing (for consistency with other pages); added "multi-paragraph item" section (with Howto? in place of answer).)
Line 1: Line 1:
 
< [[From LaTeX to ConTeXt]] >
 
< [[From LaTeX to ConTeXt]] >
  
== A Basic Description Environment ==
+
= Basic Description Lists =
  
=== LaTeX ===
+
== LaTeX ==
  
 
LaTeX provides a <tt>description</tt> environment, which works just like an itemized or enumerated list except that the item labels are specified by an (optional) argument to the <tt>\item</tt> command, rather than being automatically generated.  This is useful for making lists of definitions and other sorts of descriptions that are headed by a keyword.
 
LaTeX provides a <tt>description</tt> environment, which works just like an itemized or enumerated list except that the item labels are specified by an (optional) argument to the <tt>\item</tt> command, rather than being automatically generated.  This is useful for making lists of definitions and other sorts of descriptions that are headed by a keyword.
Line 20: Line 20:
 
</texcode>
 
</texcode>
  
=== ConTeXt ===
+
== ConTeXt ==
  
 
ConTeXt provides a similar mechanism.  Unlike the LaTeX version, ConTeXt's description mechanism does not enclose the items in an environment, but instead formats them independently according to formats given in <cmd>setupdescription</cmd> or <cmd>definedescription</cmd>.  The <cmd>definedescription</cmd> latter command is used to define a named description class, which can later be called using its name.  This example defines a <tt>latexdesc</tt> description, with parameters that roughly approximate the LaTeX defaults.
 
ConTeXt provides a similar mechanism.  Unlike the LaTeX version, ConTeXt's description mechanism does not enclose the items in an environment, but instead formats them independently according to formats given in <cmd>setupdescription</cmd> or <cmd>definedescription</cmd>.  The <cmd>definedescription</cmd> latter command is used to define a named description class, which can later be called using its name.  This example defines a <tt>latexdesc</tt> description, with parameters that roughly approximate the LaTeX defaults.
Line 39: Line 39:
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
 
The empty lines (or <cmd>par</cmd>) after each description (here, <tt>\latexdesc</tt>) line are required.
 
 
The <tt>margin=<i>dimension</i></tt> key specifies the hanging indentation for lines after the first line.  In addition, the separation between the label and the text can be specified using a <tt>distance=<i>dimension</i></tt> key.
 
  
 
<context>
 
<context>
Line 60: Line 56:
 
</context>
 
</context>
  
== Description with minimal label width: ==
+
The empty lines (or <cmd>par</cmd>) after each description (here, <tt>\latexdesc</tt>) line are required.
 +
 
 +
The <tt>margin=<i>dimension</i></tt> key specifies the hanging indentation for lines after the first line.  In addition, the separation between the label and the text can be specified using a <tt>distance=<i>dimension</i></tt> key.
 +
 
 +
= Multi-Paragraph Descriptions =
 +
 
 +
== LaTeX ==
 +
 
 +
Because the LaTeX description mechanism is an environment, it is simple to include multiple paragraphs in a description environment, or even to embed sub-lists.  For instance, consider the following example:
 +
 
 +
<texcode>
 +
\documentclass{article}
 +
\begin{document}
 +
\begin{description}
 +
\item[Para] This is a shorter item label, and some text that talks about it.
 +
  The text is wrapped into a paragraph, with successive lines indented.
 +
 
 +
  This is another paragraph under the "Para" item.
 +
 
 +
  \begin{description}
 +
  \item[Sub-Item] This is a description of an item which is within the
 +
      "Para" item.
 +
 
 +
  \item[Sub-Item] Another sub-item.
 +
  \end{description}
 +
\item[Short] A short item that's not part of that really long "Para" item.
 +
\end{description}
 +
\end{document}
 +
</texcode>
 +
 
 +
In this example, the code indentation has been used to illustrate the alignment of the typeset output.  Everything between <code>\item[Para]</code> and <code>\item[Short]</code> is part of the "Para" item, and is indented by the same amount.  The embedded description then embeds any following lines on the "Sub-Item"s by an additional indentation, as one would expect.
 +
 
 +
== ConTeXt ==
 +
 
 +
{{Howto}}
 +
 
 +
 
 +
= Descriptions with Fixed Label Width =
 +
 
 +
== LaTeX ==
 +
 
 +
In LaTeX, the <tt>mdwlist</tt> package can be used to set a fixed label width.
  
=== LaTeX ===
 
 
<texcode>
 
<texcode>
 
\documentclass{article}
 
\documentclass{article}
Line 68: Line 104:
 
\begin{document}
 
\begin{document}
 
\begin{basedescript}{\desclabelstyle{\pushlabel}\desclabelwidth{6em}}
 
\begin{basedescript}{\desclabelstyle{\pushlabel}\desclabelwidth{6em}}
\item[Label] bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
\item[Short] This is a shorter item label, and some text that talks about it.
   bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
   The text is wrapped into a paragraph, with successive lines indented.
\item[Very long label] bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
\item[Rather longer label] This is a longer item label.  As you can see, the
   bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
   text is not started a specified distance in -- unlike with other lists -- but
 +
  is spaced a fixed distance from the end of the label.
 
\end{basedescript}
 
\end{basedescript}
 
\end{document}
 
\end{document}
 
</texcode>
 
</texcode>
  
=== ConTeXt ===
+
 
 +
== ConTeXt ==
  
 
Using an explicit dimension as argument for the 'width' parameter
 
Using an explicit dimension as argument for the 'width' parameter
sets the label to 6em:
+
sets the label to 5em:
 +
 
 +
<texcode>
 +
\definedescription[notation][
 +
  headstyle=bold,style=normal,align=left,location=hanging,
 +
  width=5em]
 +
</texcode>
  
 
<context>
 
<context>
 
\definedescription[notation][
 
\definedescription[notation][
 
   headstyle=bold,style=normal,align=left,location=hanging,
 
   headstyle=bold,style=normal,align=left,location=hanging,
   width=6em]
+
   width=5em]
  
 
\starttext
 
\starttext
\notation{Label}
+
\notation{Short} This is a shorter item label, and some text that talks about it.
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
The text is wrapped into a paragraph, with successive lines indented.
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 
  bla bla bla bla
 
  
\notation{Very long label}
+
\notation{Rather longer label} This is a longer item label.  As you can see, the
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
text is not started a specified distance in -- unlike with other lists -- but
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
+
is spaced a fixed distance from the end of the label.
  bla bla bla bla
 
  
 
\stoptext
 
\stoptext
 
</context>
 
</context>

Revision as of 19:39, 4 September 2005

< From LaTeX to ConTeXt >

Basic Description Lists

LaTeX

LaTeX provides a description environment, which works just like an itemized or enumerated list except that the item labels are specified by an (optional) argument to the \item command, rather than being automatically generated. This is useful for making lists of definitions and other sorts of descriptions that are headed by a keyword.

\documentclass{article}
\begin{document}
\begin{description}
\item[Short] This is a shorter item label, and some text that talks about it.
The text is wrapped into a paragraph, with successive lines indented.
\item[Rather longer label] This is a longer item label.  As you can see, the
text is not started a specified distance in -- unlike with other lists -- but
is spaced a fixed distance from the end of the label.
\end{description}
\end{document}

ConTeXt

ConTeXt provides a similar mechanism. Unlike the LaTeX version, ConTeXt's description mechanism does not enclose the items in an environment, but instead formats them independently according to formats given in \setupdescription or \definedescription. The \definedescription latter command is used to define a named description class, which can later be called using its name. This example defines a latexdesc description, with parameters that roughly approximate the LaTeX defaults.

\definedescription[latexdesc][
  headstyle=bold,style=normal,align=left,location=hanging,
  width=broad,margin=1cm]

\starttext
\latexdesc{Short} This is a shorter item label, and some text that talks about it.
The text is wrapped into a paragraph, with successive lines indented.

\latexdesc{Rather longer label} This is a longer item label.  As you can see, the
text is not started a specified distance in -- unlike with other lists -- but
is spaced a fixed distance from the end of the label.

\stoptext

The empty lines (or \par) after each description (here, \latexdesc) line are required.

The margin=dimension key specifies the hanging indentation for lines after the first line. In addition, the separation between the label and the text can be specified using a distance=dimension key.

Multi-Paragraph Descriptions

LaTeX

Because the LaTeX description mechanism is an environment, it is simple to include multiple paragraphs in a description environment, or even to embed sub-lists. For instance, consider the following example:

\documentclass{article}
\begin{document}
\begin{description}
\item[Para] This is a shorter item label, and some text that talks about it.
   The text is wrapped into a paragraph, with successive lines indented.

   This is another paragraph under the "Para" item.

   \begin{description}
   \item[Sub-Item] This is a description of an item which is within the
      "Para" item.

   \item[Sub-Item] Another sub-item.
   \end{description}
\item[Short] A short item that's not part of that really long "Para" item.
\end{description}
\end{document}

In this example, the code indentation has been used to illustrate the alignment of the typeset output. Everything between \item[Para] and \item[Short] is part of the "Para" item, and is indented by the same amount. The embedded description then embeds any following lines on the "Sub-Item"s by an additional indentation, as one would expect.

ConTeXt


The author of this entry is looking for a solution for the described problem. (See: How to?)


Descriptions with Fixed Label Width

LaTeX

In LaTeX, the mdwlist package can be used to set a fixed label width.

\documentclass{article}
\usepackage{mdwlist}
\begin{document}
\begin{basedescript}{\desclabelstyle{\pushlabel}\desclabelwidth{6em}}
\item[Short]  This is a shorter item label, and some text that talks about it.
  The text is wrapped into a paragraph, with successive lines indented.
\item[Rather longer label] This is a longer item label.  As you can see, the
  text is not started a specified distance in -- unlike with other lists -- but
  is spaced a fixed distance from the end of the label.
\end{basedescript}
\end{document}


ConTeXt

Using an explicit dimension as argument for the 'width' parameter sets the label to 5em:

\definedescription[notation][
  headstyle=bold,style=normal,align=left,location=hanging,
  width=5em]