Math & ScienceSimple Counter Customization

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
shoemoodoshaloo
Posts: 5
Joined: Tue May 31, 2011 1:01 am

Simple Counter Customization

Post by shoemoodoshaloo »

Hey guys, don't know why this is so damn hard to me but...

Basically, I have several .tex documents which will later be compiled into a larger document using the \include{file.tex} command. Each document is a stand-alone file, which has its header completely designed by a specified number variable. For example, if the number is 8, then all the headers will autoformat to incorporate this. This flexibility is crucial because I need to be able to shuffle these at a whim. I would like then to be able to number the equations accordingly. Therefore, if the number variable is 8, then I need all equations in the document automatically numbered as (8.0, 8.1, 8.2) etc...

I realize that Latex has the \setcounter command to start counting at 8, and it also has the \numberwithin command to increment by .1 instead of 1. Unfortunately, the \numberwithin command needs to refer to a built-in feature of the document, for example the section. Since my documents are stand-alone files, they don't have sections or chapters for the \numberwithin command to understand. Is there a way to have \numberwithin recognize the number variable (E.G. 8) and number all equations as 8.1, 8.2 etc... Alternatively, can one define a custom \setcounter, that simply increments by .1 rather than 1.

Can anyone help with this? It's really holding me up!

Thanks
Last edited by shoemoodoshaloo on Sun Aug 07, 2011 3:02 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Simple Counter Customization

Post by frabjous »

Perhaps you could use the \counterwithin command provided by the chngcntr package.

Here's an example:

Code: Select all

\documentclass{article}
\usepackage{chngcntr}
\newcounter{mycounter}
\counterwithin{equation}{mycounter}
\setcounter{mycounter}{8}
\begin{document}

\begin{equation}
8.1 = 8.1
\end{equation}

\begin{equation}
8.2 = 8.2
\end{equation}

Now let's move on to 9.
\refstepcounter{mycounter}

\begin{equation}
9.1 = 9.1
\end{equation}

\begin{equation}
9.2 = 9.2
\end{equation}

\end{document}

shoemoodoshaloo
Posts: 5
Joined: Tue May 31, 2011 1:01 am

Simple Counter Customization

Post by shoemoodoshaloo »

Thanks man. A professor of mine actually had a similar problem in the past and suggested this solution before I saw you had answered my post. Without requiring extra packages, the following command in my class file worked:

Code: Select all

\newcounter{EQCOUNTER}
{

\newcommand{\eqcounter}[1]{
\setcounter{EQCOUNTER}{#1} 
}
\numberwithin{equation}{EQCOUNTER}
In the document itself, I simply call this with

Code: Select all

\def \labnumber{8}
\eqcounter{\labnumber}
Post Reply