0

In my thesis, I'm using a hack in a sty file that adds margin notes with entries in the Index, like so:

\newcommand{\thenota}{\thechapter.{\it \alph{notas}}.}
\newcommand{\nota}[1]{\stepcounter{notas}\marginpar{%
    \scriptsize \thenota\ #1%
    \index{%
        Nota de margem!{\thenota}%
        }%
    }%
}

This one works fine when I add \newcounter{notas}[chapter] after \begin{document}: Entries appear in the Index as "Nota de margem 4.a." as expected.

After a while, I decided to add another class of sidenotes, with the following definition:

\newcommand{\themudanca}{\thechapter.{\it \alph{mudanca}}.}
\newcommand{\mudanca}[1]{\stepcounter{mudanca}\marginpar{%
    \scriptsize \themudanca\ #1%
    \index{%
        Alteração no texto!{\themudanca}%
        }%
    }%
}

But when I add \newcounter{mudanca}[chapter], the output I get is "Alteração no texto 1" and I get multiple page entries, one for each first \mudanca{} in each chapter.

A MWE would be something like

\documentclass{book}
\usepackage[utf8x]{inputenc}

\newcommand{\thenota}{\thechapter.{\it \alph{notas}}.}
\newcommand{\nota}[1]{\stepcounter{notas}\marginpar{%
    \scriptsize \thenota\ #1%
    \index{%
        Nota de margem!{\thenota}%
        }%
    }%
}
\newcommand{\themudanca}{\thechapter.{\it \alph{mudanca}}.}
\newcommand{\mudanca}[1]{\stepcounter{mudanca}\marginpar{%
    \scriptsize \themudanca\ #1%
    \index{%
        Alteração no texto!{\themudanca}%
        }%
    }%
}

\begin{document}
\newcounter{notas}[chapter]
\newcounter{mudanca}[chapter]


\chapter{First}
\nota{aaa}
\mudanca{bbb}
\nota{aaa}
\mudanca{bbb}
\chapter{Second}
\nota{aaa}
\mudanca{bbb}
\end{document}

Why do they behave differently if they are coded exactly the same? Clearing aux files didn't solve.

Thanks in advance.

  • Can you please make a minimal working example (MWE)? It will be easier to understand the issue. – egreg Sep 19 '13 at 7:44
  • Sorry, egreg, I forgot about doing that, but Red's answer below provides one, so I'll implement his example in my question. – Elton Carvalho Sep 19 '13 at 17:44
3

You have first to define the counters and then use \renewcommand{\the<countername>} instead of \newcommand{\the<countername>} to redefine the way in which the counter print its value:

\documentclass{report}

\newcounter{nota}[chapter]
\newcounter{mudanca}[chapter]

\renewcommand{\thenota}{\thechapter.{\it \alph{nota}}.}
\newcommand{\nota}[1]{\stepcounter{nota}\marginpar{%
    \scriptsize \thenota\ #1%
    \index{%
        Nota de margem!{\thenota}%
        }%
    }%
}

\renewcommand{\themudanca}{\thechapter.{\it \alph{mudanca}}.}
\newcommand{\mudanca}[1]{\stepcounter{mudanca}\marginpar{%
    \scriptsize \themudanca\ #1%
    \index{%
        Alteração no texto!{\themudanca}%
        }%
    }%
}

\begin{document}
\chapter{First}
\nota{aaa}
\mudanca{bbb}
\nota{aaa}
\mudanca{bbb}
\chapter{Second}
\nota{aaa}
\mudanca{bbb}
\end{document}

The problem in your code is that you define the command \themudanca and then you define the counter mudanca that overwrites the command \themudanca giving it the default value of printing the counter number as an arabic number.

In the first case this does not happen because you call the counter notas while the command you define at the beginning is \thenota and not thenotas.

I hope it's clear...

  • Thanks. So the command \themudanca is created automatically when I add the counter mudanca? Didn't know that. I Also didn't know that you could set new counters before \begin{document} even though now it makes perfect sense since all other coutners are defined by cls and sty files. Thanks again. – Elton Carvalho Sep 19 '13 at 17:51
  • 1
    @EltonCarvalho exactly – Red Sep 19 '13 at 17:52

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.