I want each chapter to have a closed set of labels, meaning that different chapters can contain the same label, and if I use \eqref in that chapter, only look for the label in that same chapter, otherwise say "not defined label". In summary, I want each chapter to have independent label. Can I do that?

  • 3
    Welcome to TeX.SX! You're going to shoot at your own feet with this.
    – egreg
    Sep 25 '16 at 19:57
  • Are you using hyperref?
    – Werner
    Sep 25 '16 at 19:58
  • @Werner Yes I am using hyperref. But if I could, I would use it only for headers, and not for equations. At the moment, hyperref is referring to the closest label it finds, I think. Sep 25 '16 at 20:07
  • @egreg Why do you think that? Sep 25 '16 at 20:07

You can create a macro to automatically add chap<chapternumber>: before each label, and change \ref so that it searches for references with chap<chapternumber>:prefix.



% Poor man's version of ConTeXt's \expanded macro




% AMSMath changes the behavior of label.


\chapter{First chapter}
  a = b + c

It is shown in \eqref{eq:first} (\ref{eq:first}) that \ldots

\chapter{Second chapter}
  a = b + c

It is shown in \eqref{eq:first} (\ref{eq:first}) that \ldots

If you open filename.aux file, you'll see:

\@writefile{toc}{\contentsline {chapter}{\numberline {1}First chapter}{1}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\@writefile{toc}{\contentsline {chapter}{\numberline {2}Second chapter}{3}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}

Thus, the labels are written as {chap1:eq:first}, {chap2:eq:first}, etc. So, they are unique per chapter.

  • 1
    The way the ams packages typeset tags and labels are... tricky. See the answers to tex.stackexchange.com/questions/319158/… for example. Sep 25 '16 at 20:32
  • @WillieWong: Thanks for the explanation! I have updated the answer.
    – Aditya
    Sep 25 '16 at 20:38
  • @Aditya Thank you very much! I changed your answer a little, but everything is working fine! Sep 25 '16 at 21:03
  • Question: would you consider using this yourself? You don't mention any of the downsides of doing thing or the potential pitfalls.
    – cfr
    Sep 26 '16 at 2:59
  • @BrunoMurino Did you try \usepackage{hyperref}?
    – cfr
    Sep 26 '16 at 3:08

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.