4

How I make the numbering in the following file start at 1.0 instead of 1.1? setcounter{dfnv}{-1} doesn't do anything.

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}

\makeatletter
\@addtoreset{dfnv}{dfnq}
\let\thedfnvsaved\thedfnv
\renewcommand{\thedfnv}{\thedfnq.\thedfnvsaved}
\makeatother

%% \makeatletter
%% \@namedef{thedfnv}{\@nameuse{thedfnq}.\arabic{dfnv}}
%% \makeatother

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

Full disclosure: this is a continuation of my previous question.

2

All you need is to subtract 1 to the value of your counter when you use it (in \thedfnv). Here it is done using a temporary counter.

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}[dfnq]
\newcounter{tmpcnt}

\renewcommand{\thedfnv}{
\setcounter{tmpcnt}{\value{dfnv}}\addtocounter{tmpcnt}{-1}\thedfnq.\thetmpcnt}


\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

EDIT: a way to get labels to work correctly

  • decouple dfnv form dfnq (not strictly necessary but we'll handle the dependency manually)
  • initialize dfnv to -1
  • define a command \nextdef that you will call instead of \stepcounter{dfnq} :

    \newcommand{\nextdef}{\stepcounter{dfnq}\setcounter{dfnv}{-1}}

  • redefine \thedfnv the good old way:

    \renewcommand{\thedfnv}{\thedfnq.\arabic{dfnv}}

And voilà, should work correctly.

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}
\setcounter{dfnv}{-1}

\renewcommand{\thedfnv}{\thedfnq.\arabic{dfnv}}

\def\nextdef{\stepcounter{dfnq}\setcounter{dfnv}{-1}}

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}\label{defa}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}\label{defb}
  Version 1 of the definition of foo.
\end{dfn}
\nextdef

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}\label{defc}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}\label{defd}
  Version 1 of the definition of bar.
\end{dfn}
\nextdef

\ref{defa}

\ref{defb}

\ref{defc}

\ref{defd}

\end{document}
  • Thanks! How do I get \label to work? Right now it still gives the old numbers 1.1, 1.2, etc. – Joshua Meyers May 26 '17 at 7:53
  • OK, TeX black magic going on here, I don't know how \label works precisely but things get messed up on the way. I'm adding a workaround. – Christoph Frings May 26 '17 at 10:12
  • OK my proposition is basically MadyYuvi's answer with a lot more text all around... – Christoph Frings May 26 '17 at 10:20
0

Put \setcounter{dfnv}{\numexpr\value{dfnv}-1\relax} after every occurence of \stepcounter{dfnq}.

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}

\makeatletter
\@addtoreset{dfnv}{dfnq}
\let\thedfnvsaved\thedfnv
\renewcommand{\thedfnv}{\thedfnq.\thedfnvsaved}
\makeatother

%% \makeatletter
%% \@namedef{thedfnv}{\@nameuse{thedfnq}.\arabic{dfnv}}
%% \makeatother

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
\setcounter{dfnv}{\numexpr\value{dfnv}-1\relax}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}
\setcounter{dfnv}{\numexpr\value{dfnv}-1\relax}
% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

enter image description here

-1

\setcounter{dfnq}{-1} and follows...

  • This doesn't do the job, the dfnq counter has the appropriate values, it is the way the dfnv counter increments is reset when the dfnq counter increments that is the problem as detailed in existing answers. – Dai Bowen May 26 '17 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.