Difference between revisions of "Paragraph Enumeration"

From Wiki
Jump to navigation Jump to search
m (Added some examples of the typeset output.)
(A rearrangement, putting the built-in method first. Also improved examples.)
Line 1: Line 1:
This code was proposed by Taco to the list:
+
== Standard Paragraph Numbering ==
 +
 
 +
ConTeXt has a built-in mechanism for paragraph numbering, which places numbers in the margin.  This is accessed with <cmd>setupparagraphnumbering</cmd>, as in this example, which also sets the number style to italic rather than the default roman.
 +
 
 +
<texcode>
 +
\starttext
 +
Some text in an unnumbered paragraph before the paragraph numbering starts.
 +
 
 +
\setupparagraphnumbering[state=start,style=italic,distance=0pt]
 +
This is the first numbered paragraph; it's short.
 +
 
 +
This is another numbered paragraph. it's rather a bit longer.  Specifically,
 +
it's long enough to wrap around onto more than one line, so as to show that
 +
these are paragraph numbers and not line numbers.
 +
 
 +
A third numbered paragraph.
 +
\setupparagraphnumbering[state=stop]
 +
 
 +
And, finally, an unnumbered paragraph after the paragraph numbering.
 +
\stoptext
 +
</texcode>
 +
 
 +
<context>
 +
\starttext
 +
Some text in an unnumbered paragraph before the paragraph numbering starts.
 +
 
 +
\setupparagraphnumbering[state=start,style=italic,distance=0pt]
 +
This is the first numbered paragraph; it's short.
 +
 
 +
This is another numbered paragraph. it's rather a bit longer.  Specifically,
 +
it's long enough to wrap around onto more than one line, so as to show that
 +
these are paragraph numbers and not line numbers.
 +
 
 +
A third numbered paragraph.
 +
\setupparagraphnumbering[state=stop]
 +
 
 +
And, finally, an unnumbered paragraph after the paragraph numbering.
 +
\stoptext
 +
</context>
 +
 
 +
 
 +
== Paragraph Numbering in the Text ==
 +
 
 +
An alternate way of numbering paragraphs is to place the numbers in the running text, rather than in the margin.  ConTeXt doesn't have a built-in way to do this, but it's not difficult to add a method using the <cmd>everypar</cmd> macro.  The following code was proposed by Taco on the mailing list.
  
 
<texcode>
 
<texcode>
 
\newcounter\Paracount
 
\newcounter\Paracount
 
\setcounter\Paracount1
 
\setcounter\Paracount1
 
 
\def\Paragraphnumber%
 
\def\Paragraphnumber%
 
   {\increment\Paracount  
 
   {\increment\Paracount  
 
     \Paracount.~}
 
     \Paracount.~}
\def\startParagraphs%
+
\def\startParagraphNumbers%
 
   {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
 
   {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
\def\stopParagraphs%
+
\def\stopParagraphNumbers%
 
   {\par \endgroup}
 
   {\par \endgroup}
  
 
\starttext
 
\starttext
Unnumbered text before.
+
Some text in an unnumbered paragraph before the paragraph numbering starts.
  
\startParagraphs
+
\startParagraphNumbers
This is the first numbered paragraph.
+
This is the first numbered paragraph; it's short.
  
This is another paragraph. This is another
+
This is another numbered paragraph. it's rather a bit longer.  Specifically,
paragraph. This is another paragraph.
+
it's long enough to wrap around onto more than one line, so as to show that
\stopParagraphs
+
these are paragraph numbers and not line numbers.
  
Unnambered text after.
+
A third numbered paragraph.
 +
\stopParagraphNumbers
 +
 
 +
And, finally, an unnumbered paragraph after the paragraph numbering.
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
  
This produces the following result:
+
This produces the following result/
  
 
<context>
 
<context>
 
\newcounter\Paracount
 
\newcounter\Paracount
 
\setcounter\Paracount1
 
\setcounter\Paracount1
 
 
\def\Paragraphnumber%
 
\def\Paragraphnumber%
 
   {\increment\Paracount  
 
   {\increment\Paracount  
 
     \Paracount.~}
 
     \Paracount.~}
\def\startParagraphs%
+
\def\startParagraphNumbers%
 
   {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
 
   {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
\def\stopParagraphs%
+
\def\stopParagraphNumbers%
 
   {\par \endgroup}
 
   {\par \endgroup}
  
 
\starttext
 
\starttext
Unnumbered text before.
+
Some text in an unnumbered paragraph before the paragraph numbering starts.
 
 
\startParagraphs
 
This is the first numbered paragraph.
 
  
This is another paragraph. This is another
+
\startParagraphNumbers
paragraph. This is another paragraph.
+
This is the first numbered paragraph; it's short.
\stopParagraphs
 
 
 
Unnambered text after.
 
\stoptext
 
</context>
 
  
If you're happy with numbers in the margin, this is in-built ConTeXt way, with <cmd>setupparagraphnumbering</cmd>:
+
This is another numbered paragraph. it's rather a bit longer.  Specifically,
 +
it's long enough to wrap around onto more than one line, so as to show that
 +
these are paragraph numbers and not line numbers.
  
<texcode>
+
A third numbered paragraph.
\starttext
+
\stopParagraphNumbers
\showframe
 
\setupcolors[state=start]
 
\setupparagraphnumbering[state=start,style=italic,distance=0pt]
 
\section{bloo}
 
\input knuth
 
\section{blah}
 
\input knuth \par
 
\setupparagraphnumbering[state=stop]
 
\input tufte \par
 
\setupparagraphnumbering[state=start,color=red]
 
\dorecurse{4}{\input tufte \par}
 
\stoptext
 
</texcode>
 
 
 
<context>
 
\setupcolors[state=start]
 
\starttext
 
Unnumbered text before.
 
 
 
\setupparagraphnumbering[state=start,style=italic,distance=0pt]
 
This is the first numbered paragraph.
 
 
 
This is another paragraph. This is another
 
paragraph. This is another paragraph.
 
\setupparagraphnumbering[state=stop]
 
  
Unnambered text after.
+
And, finally, an unnumbered paragraph after the paragraph numbering.
 
\stoptext
 
\stoptext
 
</context>
 
</context>

Revision as of 07:35, 4 September 2005

Standard Paragraph Numbering

ConTeXt has a built-in mechanism for paragraph numbering, which places numbers in the margin. This is accessed with \setupparagraphnumbering, as in this example, which also sets the number style to italic rather than the default roman.

\starttext
Some text in an unnumbered paragraph before the paragraph numbering starts.

\setupparagraphnumbering[state=start,style=italic,distance=0pt]
This is the first numbered paragraph; it's short.

This is another numbered paragraph. it's rather a bit longer.  Specifically,
it's long enough to wrap around onto more than one line, so as to show that
these are paragraph numbers and not line numbers.

A third numbered paragraph.
\setupparagraphnumbering[state=stop]

And, finally, an unnumbered paragraph after the paragraph numbering.
\stoptext


Paragraph Numbering in the Text

An alternate way of numbering paragraphs is to place the numbers in the running text, rather than in the margin. ConTeXt doesn't have a built-in way to do this, but it's not difficult to add a method using the \everypar macro. The following code was proposed by Taco on the mailing list.

\newcounter\Paracount
\setcounter\Paracount1
\def\Paragraphnumber%
   {\increment\Paracount 
    \Paracount.~}
\def\startParagraphNumbers%
   {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
\def\stopParagraphNumbers%
   {\par \endgroup}

\starttext
Some text in an unnumbered paragraph before the paragraph numbering starts.

\startParagraphNumbers
This is the first numbered paragraph; it's short.

This is another numbered paragraph. it's rather a bit longer.  Specifically,
it's long enough to wrap around onto more than one line, so as to show that
these are paragraph numbers and not line numbers.

A third numbered paragraph.
\stopParagraphNumbers

And, finally, an unnumbered paragraph after the paragraph numbering.
\stoptext

This produces the following result/