Difference between revisions of "Command/definecounter"

From Wiki
Jump to navigation Jump to search
m
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
Creates a new numeric counter.
 
Creates a new numeric counter.
  
== Example ==
+
== Examples ==
 +
 
 +
=== Picture ===
  
 
The following partial example adds a picture at the end of each chapter:
 
The following partial example adds a picture at the end of each chapter:
  
<pre>
+
<texcode>
\definecounter[EventCount][
+
\definecounter[EventCount]
  way=bytext,
+
  [
  prefix=no
+
    way=bytext,
]
+
    prefix=no,
 +
  ]
  
 
\startTEXpage
 
\startTEXpage
 
   \incrementcounter[EventCount]
 
   \incrementcounter[EventCount]
   \externalfigure[{\rawcountervalue[EventCount]}][
+
   \externalfigure[{\rawcountervalue[EventCount]}]
    height=\paperheight,
+
                [
    orientation=90,
+
                  height=\paperheight,
  ]
+
                  orientation=90,
 +
                ]
 
\stopTEXpage
 
\stopTEXpage
</pre>
+
</texcode>
  
 
The pictures are numbered sequentially, starting at 1.
 
The pictures are numbered sequentially, starting at 1.
 +
 +
=== Show Section Number ===
 +
 +
The following example writes a counter in a layer, starting with the value of 1:
 +
 +
<texcode>
 +
\definecounter[MyCounter][
 +
  way=bytext,
 +
  prefix=no
 +
]
 +
 +
\setnumber[MyCounter][-1]
 +
 +
\setuphead[section][
 +
  page=left,
 +
  before={\incrementcounter[MyCounter]},
 +
]
 +
 +
\definelayer[MyLayer][
 +
  width=\paperwidth,
 +
  height=\paperheight,
 +
  position=no,
 +
  repeat=no,
 +
]
 +
 +
\setupbackgrounds[page][
 +
  setups=MySetup,
 +
  background=MyLayer,
 +
]
 +
 +
\startsetups[MySetup]
 +
\ifnum\rawcountervalue[MyCounter]>0{%
 +
  MyCounter = \rawcountervalue[MyCounter]
 +
}\fi
 +
\stopsetups
 +
 +
\starttext
 +
  \startsection[title=S1]
 +
  \stopsection
 +
 +
  \startsection[title=S2]
 +
  \stopsection
 +
\stoptext
 +
</texcode>
 +
 +
 +
The initial value for the counter is set to -1 so that its value is 0 on the first page, then 1 on the second page.
  
 
== See Also ==
 
== See Also ==
  
 +
* [[Counters]]
 
* {{cmd|incrementcounter}} - Increase the counter value
 
* {{cmd|incrementcounter}} - Increase the counter value
 
* {{cmd|decrementcounter}} - Decrease the counter value
 
* {{cmd|decrementcounter}} - Decrease the counter value
Line 34: Line 86:
 
View the source for more details:
 
View the source for more details:
  
http://source.contextgarden.net/tex/context/base/strc-num.mkiv
+
https://source.contextgarden.net/tex/context/base/mkiv/strc-num.mkiv

Latest revision as of 20:22, 5 April 2020

Creates a new numeric counter.

Examples

Picture

The following partial example adds a picture at the end of each chapter:

\definecounter[EventCount]
  [
    way=bytext,
    prefix=no,
  ]

\startTEXpage
  \incrementcounter[EventCount]
  \externalfigure[{\rawcountervalue[EventCount]}]
                 [
                   height=\paperheight,
                   orientation=90,
                 ]
\stopTEXpage

The pictures are numbered sequentially, starting at 1.

Show Section Number

The following example writes a counter in a layer, starting with the value of 1:

\definecounter[MyCounter][
  way=bytext,
  prefix=no
]

\setnumber[MyCounter][-1]

\setuphead[section][
  page=left,
  before={\incrementcounter[MyCounter]},
]

\definelayer[MyLayer][
  width=\paperwidth,
  height=\paperheight,
  position=no,
  repeat=no,
]

\setupbackgrounds[page][
  setups=MySetup,
  background=MyLayer,
]

\startsetups[MySetup]
\ifnum\rawcountervalue[MyCounter]>0{%
  MyCounter = \rawcountervalue[MyCounter]
}\fi
\stopsetups

\starttext
  \startsection[title=S1]
  \stopsection

  \startsection[title=S2]
  \stopsection
\stoptext


The initial value for the counter is set to -1 so that its value is 0 on the first page, then 1 on the second page.

See Also

Source Code

View the source for more details:

https://source.contextgarden.net/tex/context/base/mkiv/strc-num.mkiv