User:Bibiko/GlossCnt

From Glottopedia
Jump to: navigation, search

Extension GlossCnt – An auto-count function

Contents


Background

It is often the case that an editor of an article wants to number examples, figures, diagrams, etc. serially. This can be done by hand. By doing so a problem arises if you want to add for instance a further example between existing ones. After inserting it the editor has to renumber all example following the new one. Furthermore if within this article occurs a reference like see example (6) the editor has to renumber this reference as well.

To solve this problem the editor can use this extension GlossCnt to number them automatically by using the tags <glcnt /> and <glref />.


Short Description

What can you do with this extension in short terms:

  • define several independent counters by using different ns (<glcnt ns="ns" name="name" />)
  • refer to the a specific counter by using the name attribute (<glref name="name" />)
  • predefine the type of counting (numeric or alphabetic)
    • for sub-counter: specify whether only the sub-counter will be displayed ( 7b or only b )
  • predefine the format, like (1), or §a, or figure :, which will be bequeathed
  • define a sub-counter linked via name (<glsub of="name" />)
  • reset a global counter (<glreset ns="ns" />)

 

Usage

The tag <glcnt />

Syntax: <glcnt ns="ns" pre="prefix" suf="suffix" name="name" type="type" nocnt />
ns ns must be a valid identifier to be able to count different topics independently.
If not set the default identifier glcnt is taken
optional except for counting different topics
prefix prefix specifies what will be printed just before the following number.
If prefix is set within the first occurrence of that tag all succeeding tags of the same ns inherits it. Otherwise its default is "(".
optional
suffix suffix specifies what will be printed just after the preceding number.
If suffix is set within the first occurrence of that tag all succeeding tags of the same ns inherits it. Otherwise its default is "(".
optional
name name must be any unique and valid name to be able to refer to it by using the tag <glref />. optional except for referring to it
type It specifies the type for counting
  allowed types:
    A : counts A, B, ..., Z, AA, AB, ...
    a : counts a, b, ..., z, aa, ab, ...
If not set numerical counting is its default.
optional
nocnt This attribute suppresses the incrementing of the counter  


Further explanations:

  • prefix and suffix have to have set together. If you set only suffix this attribute will be ignored.
  • It is possible to add HTML tags to prefix and suffix.
    Example: <glcnt pre="[&lt;b&gt;" suf="&lt;/b&gt;]" /> to set the number in bold face enclosed by "[]" like [3].
    Please note that < , > , and & must be escaped: &lt; , &gt; , &amp;
  • name and ns may only contain the following characters: A to Z, a to z, numbers and an _
  • If you are editing only a section of an article please note that the numbering starts always at 1 (resp. A or a) in the Preview regardless the number of this tag within the entire article. After saving this section the numbering within the article is serially.
  • The type attribute must be specified within the first occurrence of <glcnt {ns="ns"} />!
  • If prefix and suffix are set within the first occurrence of that tag you can use it as a kind of caption for figures, diagrams, examples, etc. (e.g.: figure 1, figure 2)

The tag <glsub />

Syntax: <glsub of="of" pre="prefix" suf="suffix" name="name" type="type" sep="sep" nocnt />
of of must be a valid superior name specified within the tags <glcnt /> or <glsub />. must be set
prefix prefix specifies what will be printed just before the following number.
If no prefix is set its default is "".
optional
suffix suffix specifies what will be printed just after the preceding number.
If no suffix is set its default is "".
optional
name name must be any unique and valid name to be able to refer to it by using the tag <glref />. optional except for referring to it
type It specifies the type for counting
  allowed types:
      A : counts A, B, ..., Z, AA, AB, ...
    _A : counts A, B, ..., Z, AA, AB, ..., but it only displays the subcounter
      a : counts a, b, ..., z, aa, ab, ...
    _a : counts a, b, ..., z, aa, ab, ..., but it only displays the subcounter
    _1 : counts 1, 2, ..., but it only displays the subcounter
If not set numerical counting is its default.
optional
sep This string is used for separating the sub-counter.
If not set its default is "" or "." if the sub-types is equal to its superior type. Once sep is set the following sub-counter for of inherits it until it is set again.
optional
nocnt This attribute suppresses the incrementing of the counter  


Further explanations:

  • It is possible to nest <glsub /> via the attribute name to get e.g. (1.4d).
  • The type attribute must be specified within the first occurrence of <glsub of="of"} />!

The tag <glref />

Syntax: <glref pre="prefix" suf="suffix" name="name" />
prefix prefix specifies what will be printed just before the following number.
If not set it inherits it from the refered <glcnt name="name" />.
optional
suffix suffix specifies what will be printed just after the preceding number.
If not set it inherits it from the refered <glcnt name="name" />.
optional
name name specifies to which <glcnt name="name" /> it should refer to. must be set

The tag <glref name="myref1" /> will be replaced by the number according to <glcnt name="myref1" /> and this number is implemented as Hyperlink to <glcnt name="myref1" /> to make it possible to jump to it easily.

Further explanations:

  • prefix and suffix have to have set together. If you set only suffix this attribute will be ignored.
  • It is possible to add HTML tags to prefix and suffix.
    Example: <glref pre="[&lt;b&gt;" suf="&lt;/b&gt;]" /> to set the number in bold face enclosed by "[]" like [3].
    Please note that < , > , and & must be escaped: &lt; , &gt; , &amp;
  • name may only contain the following characters: A to Z, a to z, numbers and an _
  • If the name is unknown within this article an error will be printed out.
  • If you are editing only a section of an article and the name points outside of this section an error occurs. For editing such a case you have to edit the entire article to be sure that the reference is correct or dismiss the error and save the section if you know that the name is correct.
  • It is possible to use <glref name="ref_name" before <glcnt name="ref_name"> occurs in the article.

The tag <glreset />

Syntax: <glreset ns="ns" />
ns ns must be a valid identifier to a used counter.
If not set the default identifier glcnt is taken

This tag set the counter according to its ns to 1, or A, or a.

Further explanations:

  • You cannot reset a sub-counter.

Examples

Syntax Output
<glcnt />
some text

<glcnt />
(1)
some text

(2)
<glcnt pre="" suf="]" />
some text
further text
<glcnt />
additional text
-<glcnt pre="&lt;font color=red&gt;{" suf="}&lt;/font&gt;" />
1]
some text
further text
2]
additional text
-{3}
See example <glref name="r1" />

Example: <glcnt name="r1" /> Here my example.
See example (1)

Example: (1) Here my example.
See example <glref name="r2" />
Example: <glcnt name="first" /> Here my first example.
Example: <glcnt name="r2" /> Here my example.

See my first example <glref name="first" />
See example (2)
Example: (1) Here my first example.
Example: (2) Here my example.

See my first example (1)
See <glref name="fig1" />
<glcnt pre="figure " suf=":" />
<glcnt name="fig1" />
<glcnt pre="" suf="" />
<glcnt />
See figure 2:
figure 1:
figure 2:
3
figure 4
<glcnt name="e1" />

<glcnt pre="[" suf="]" name="e2" />
<glref name="e1" />
<glref name="e2" />
<glref pre="" suf="" name="e2" />
(1)

[2]
(1)
[2]
2
<glcnt />
<glcnt />
<glcnt ns="dia" />
<glcnt />
<glcnt ns="dia" />
<glcnt /><glreset />
<glcnt />
<glcnt type="a" ns="fig" />
<glcnt ns="dia" />
<glcnt ns="fig" />
(1)
(2)
(1)
(3)
(2)
(4)
(1)
(a)
(3)
(b)
<glcnt />
<glref name="ref" />
<glcnt />
<glcnt name="c1" />
<glsub of="c1" type="a" sep="-" />
<glsub of="c1" />
<glsub of="c1" />
<glcnt />
<glsub of="c1" name="sub1" />
<glsub of="sub1" sep="" name="ref" />
(1)
(3-d1)
(2)
(3)
(3-a)
(3-b)
(3-c)
(4)
(3-d)
(3-d1)
<glcnt name="s1" /> Examples:

<glsub of="s1" type="_a" /> only the subcounter wil be displayed

<glsub of="s1" name="s2" /> Here also!

See <glref name="s2" /> But the reference shows the complete counter.
(1) Exapmles:

(a) only the subcounter wil be displayed

(b) Here also!

See (1b) But the reference shows the complete counter.

 

Comments, Bugs, Wishes

Please don't hesitate to contact me via (bibiko[at]eva.mpg.de) if there are problems, errors, bugs, or wishes regarding to this extension.


March 20th, 2007