Since I don't have any access to good documentation, I'm trying to learn how to write a LaTeX class by googling for class and style files. However, I can't seem to produce automatic numbers using any combination of \newcounter \setcounter or \stepcounter.
So could somebody provide me with the shortest code fragment that I could paste in my class file (which patches the article class via LoadClass) to produce the following output:
Let's count 1 and 2 and 3!
(with the numbers 1, 2 and 3 being produced via the repeated invocation of a counter command called \foo).
The best I output I could come up with is:
Let's count 1 and 1 and 1!
(with the number 1 being produced by \setcounter or \stepcounter).
Thanks!
Document Classes ⇒ Creating custom counters by example
Creating custom counters by example
First, you have to define a new counter, say, bar. Then, define a new command \foo which i) adds one to the counter, via \stepcounter, ii) prints the counter. To print the counter, you have to remember that each counter has an associated \thecounter which prints the value.
Here's a simple code doing that:
Here's a simple code doing that:
Code: Select all
\documentclass{article}
\newcounter{bar}
\newcommand{\foo}{%
\stepcounter{bar}%
\thebar}
\begin{document}
Let's count \foo\ and \foo\ and \foo\
\end{document}
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Creating custom counters by example
For the present you can start with lshort as a general beginners guide and the clsguide as a manual for writing classes.untexnixal wrote:Since I don't have any access to good documentation, I'm trying to learn how to write a LaTeX class by googling for class and style files. […]
Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
-
- Posts: 3
- Joined: Sun Feb 01, 2009 2:12 am
Re: Creating custom counters by example
@keta Thanks. I was a bit confused about the "the"(foo) commands.
@localhost Thanks. The references as you said seem quite basic, though they clarify a lot of general points such as the meaning of all those @'s. I had been hoping to find something that would walk me thru such details as changing character mapping.
@localhost Thanks. The references as you said seem quite basic, though they clarify a lot of general points such as the meaning of all those @'s. I had been hoping to find something that would walk me thru such details as changing character mapping.