Difference between revisions of "Paragraph Enumeration"

From Wiki
Jump to navigation Jump to search
(A rearrangement, putting the built-in method first. Also improved examples.)
m
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
== Standard Paragraph Numbering ==
 
== 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.
+
ConTeXt has a built-in mechanism for paragraph numbering, which places numbers in the margin.  This is accessed with {{cmd|setupparagraphnumbering}}.  
  
<texcode>
+
The mechanism numbers ‘TeX paragraphs’, so a formula or an itemization item will get its own number. For ‘block of thought’ paragraphs that can contain multiple TeX paragraphs, see the {{module|pararef}} module described at [[Paragraph Referencing]].
 +
 
 +
<context source="yes">
 +
\setuppapersize[A5]
 
\starttext
 
\starttext
 
Some text in an unnumbered paragraph before the paragraph numbering starts.
 
Some text in an unnumbered paragraph before the paragraph numbering starts.
Line 10: Line 13:
 
This is the first numbered paragraph; it's short.
 
This is the first numbered paragraph; it's short.
  
This is another numbered paragraph. it's rather a bit longerSpecifically,
+
This is another numbered paragraph.  It's long enough to wrap around onto
it's long enough to wrap around onto more than one line, so as to show that
+
more than one line, so as to show that these are paragraph numbers and not
these are paragraph numbers and not line numbers.
+
line numbers.
  
A third numbered paragraph.
+
\startitemize[packed]
\setupparagraphnumbering[state=stop]
+
    \item an
 
+
    \item itemization
And, finally, an unnumbered paragraph after the paragraph numbering.
+
\stopitemize
\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.
 
A third numbered paragraph.
Line 42: Line 32:
 
== Paragraph Numbering in the Text ==
 
== 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.
+
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}} macro.  The following code was proposed by Taco on the mailing list.
  
<texcode>
+
<context source="yes" text="This produces the following result:">
 +
\setuppapersize[A6]
 
\newcounter\Paracount
 
\newcounter\Paracount
 
\setcounter\Paracount1
 
\setcounter\Paracount1
Line 61: Line 52:
 
This is the first numbered paragraph; it's short.
 
This is the first numbered paragraph; it's short.
  
This is another numbered paragraph. it's rather a bit longerSpecifically,
+
This is another numbered paragraph.  It's long enough to wrap around onto
it's long enough to wrap around onto more than one line, so as to show that
+
more than one line, so as to show that these are paragraph numbers and not
these are paragraph numbers and not line numbers.
+
line numbers.
  
 
A third numbered paragraph.
 
A third numbered paragraph.
Line 70: Line 61:
 
And, finally, an unnumbered paragraph after the paragraph numbering.
 
And, finally, an unnumbered paragraph after the paragraph numbering.
 
\stoptext
 
\stoptext
</texcode>
+
</context>
 +
 
 +
== Combining Section Numbering with Paragraph Numbering and Titles ==
  
This produces the following result/
+
Idris provided [https://mailman.ntg.nl/pipermail/ntg-context/2017/089454.html a modified version] of an enumerated-paragraphs sample provided by Wolfgang. In the modified version, section numbering is combined with paragraph enumeration, with titles optional:
  
<context>
+
<context source="yes" text="The output from the previous code is:">
\newcounter\Paracount
+
\defineseparatorset [ParagraphNumber][.,] % no second decimal for susubparagraphs
\setcounter\Paracount1
+
% \defineseparatorset [ParagraphNumber][.,.] % second decimal for susubparagraphs
\def\Paragraphnumber%
+
   {\increment\Paracount
+
\definecounter[ParagraphNumber][numberseparatorset=ParagraphNumber,criterium=all]
    \Paracount.~}
+
\def\startParagraphNumbers%
+
\define\ParagraphNumber
  {\par \begingroup \appendtoks \Paragraphnumber \to \everypar}
+
  {{\bf \incrementcounter[ParagraphNumber]%
\def\stopParagraphNumbers%
+
   \convertedcounter[ParagraphNumber][numbersegments=1]}\quad}
   {\par \endgroup}
+
 +
\define\subParagraphNumber
 +
  {{\bf \incrementcounter[ParagraphNumber][2]%
 +
  \convertedcounter[ParagraphNumber][numbersegments=1:2]}\quad}
 +
 +
\define\subsubParagraphNumber
 +
  {{\bf \incrementcounter[ParagraphNumber][3]%
 +
  \convertedcounter[ParagraphNumber][numbersegments=1:3]}\quad}
 +
 
 +
\setuphead[section]
 +
  [style=\bf,
 +
    alternative=text,
 +
    criterium=all,
 +
    number=no,
 +
    textcommand=\ParagraphNumber,
 +
    insidesection=\hskip-0.49em] % adjust space after title
 +
   
 +
\setuphead[subsection]
 +
   [style=\bf,
 +
    alternative=text,
 +
    criterium=all,
 +
    number=no,
 +
    textcommand=\subParagraphNumber,
 +
    insidesection=\hskip-0.49em] % adjust space after title
  
 +
\setuphead[subsubsection]
 +
  [style=\bf,
 +
    alternative=text,
 +
    criterium=all,
 +
    number=no,
 +
    textcommand=\subsubParagraphNumber,
 +
    insidesection=\hskip-0.49em] % adjust space after title
 +
 +
\setupwhitespace[line]
 +
 
\starttext
 
\starttext
Some text in an unnumbered paragraph before the paragraph numbering starts.
+
\startsection[title={Text.}]
 +
\input ward
 +
\startsubsection
 +
\input ward
 +
\startsubsubsection[title={Text.}]
 +
\input ward
 +
\stopsubsubsection
 +
\stopsubsection
 +
\stopsection
  
\startParagraphNumbers
+
\startsection
This is the first numbered paragraph; it's short.
+
\input ward
 
+
\startsubsubsection
This is another numbered paragraph. it's rather a bit longer.  Specifically,
+
\input ward
it's long enough to wrap around onto more than one line, so as to show that
+
\stopsubsubsection
these are paragraph numbers and not line numbers.
+
\stopsection
 
 
A third numbered paragraph.
 
\stopParagraphNumbers
 
 
 
And, finally, an unnumbered paragraph after the paragraph numbering.
 
 
\stoptext
 
\stoptext
 
</context>
 
</context>
 +
 +
[[Category:Basics]]

Revision as of 15:10, 8 June 2020

Standard Paragraph Numbering

ConTeXt has a built-in mechanism for paragraph numbering, which places numbers in the margin. This is accessed with \setupparagraphnumbering.

The mechanism numbers ‘TeX paragraphs’, so a formula or an itemization item will get its own number. For ‘block of thought’ paragraphs that can contain multiple TeX paragraphs, see the t-pararef module described at Paragraph Referencing.

\setuppapersize[A5]
\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 long enough to wrap around onto
more than one line, so as to show that these are paragraph numbers and not
line numbers.

\startitemize[packed]
    \item an
    \item itemization
\stopitemize

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.

\setuppapersize[A6]
\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 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:

Combining Section Numbering with Paragraph Numbering and Titles

Idris provided a modified version of an enumerated-paragraphs sample provided by Wolfgang. In the modified version, section numbering is combined with paragraph enumeration, with titles optional:

\defineseparatorset [ParagraphNumber][.,] % no second decimal for susubparagraphs
% \defineseparatorset [ParagraphNumber][.,.] % second decimal for susubparagraphs
 
\definecounter[ParagraphNumber][numberseparatorset=ParagraphNumber,criterium=all]
 
\define\ParagraphNumber
  {{\bf \incrementcounter[ParagraphNumber]%
   \convertedcounter[ParagraphNumber][numbersegments=1]}\quad}
 
\define\subParagraphNumber
  {{\bf \incrementcounter[ParagraphNumber][2]%
   \convertedcounter[ParagraphNumber][numbersegments=1:2]}\quad}
 
\define\subsubParagraphNumber
  {{\bf \incrementcounter[ParagraphNumber][3]%
   \convertedcounter[ParagraphNumber][numbersegments=1:3]}\quad}
   
\setuphead[section]
   [style=\bf,
    alternative=text,
    criterium=all,
    number=no,
    textcommand=\ParagraphNumber,
    insidesection=\hskip-0.49em] % adjust space after title
    
\setuphead[subsection]
   [style=\bf,
    alternative=text,
    criterium=all,
    number=no,
    textcommand=\subParagraphNumber,
    insidesection=\hskip-0.49em] % adjust space after title

\setuphead[subsubsection]
   [style=\bf,
    alternative=text,
    criterium=all,
    number=no,
    textcommand=\subsubParagraphNumber,
    insidesection=\hskip-0.49em] % adjust space after title 
 
\setupwhitespace[line]
 
\starttext
\startsection[title={Text.}]
\input ward
\startsubsection
\input ward
\startsubsubsection[title={Text.}]
\input ward
\stopsubsubsection
\stopsubsection
\stopsection

\startsection
\input ward
\startsubsubsection
\input ward
\stopsubsubsection
\stopsection
\stoptext

The output from the previous code is: