Difference between revisions of "Description"

From Wiki
Jump to navigation Jump to search
(Added improved explanation (after looking this up in the LaTeX manual), example.)
(A bit more explanation, improvement of examples.)
Line 22: Line 22:
 
=== ConTeXt ===
 
=== ConTeXt ===
  
<tt>\setupdescription</tt> with some special parameters
+
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.
(<tt>location=hanging</tt>, <tt>width=broad</tt>,
 
<tt>margin=</tt><i>indentation</i>)
 
  
 
<texcode>
 
<texcode>
\definedescription[notation][
+
\definedescription[latexdesc][
 
   headstyle=bold,style=normal,align=left,location=hanging,
 
   headstyle=bold,style=normal,align=left,location=hanging,
 
   width=broad,margin=1cm]
 
   width=broad,margin=1cm]
  
 
\starttext
 
\starttext
\notation{A very very very very long item}
+
\latexdesc{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{i}
+
\latexdesc{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
 
</texcode>
 
</texcode>
  
The empty lines (or <tt>\par</tt>) after each description
+
The empty lines (or <cmd>par</cmd>) after each description (here, <tt>\latexdesc</tt>) line are required.
(here notation) are necessary.
 
  
The result looks like this:
+
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>
\definedescription[notation][
+
\definedescription[latexdesc][
 
   headstyle=bold,style=normal,align=left,location=hanging,
 
   headstyle=bold,style=normal,align=left,location=hanging,
 
   width=broad,margin=1cm]
 
   width=broad,margin=1cm]
  
 
\starttext
 
\starttext
\notation{A very very very very long item}
+
\latexdesc{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{i}
+
\latexdesc{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>
 
<b>Hint:</b> This solution uses the <tt>distance=</tt><i>dimension</i>
 
distance for separation of label and text.
 
 
  
 
== Description with minimal label width: ==
 
== Description with minimal label width: ==

Revision as of 19:24, 4 September 2005

< From LaTeX to ConTeXt >

A Basic Description Environment

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.

Description with minimal label width:

LaTeX

\documentclass{article}
\usepackage{mdwlist}
\begin{document}
\begin{basedescript}{\desclabelstyle{\pushlabel}\desclabelwidth{6em}}
\item[Label] bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\item[Very long label] bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{basedescript}
\end{document}

ConTeXt

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