0

An MWE is follows.

\documentclass{book}
\usepackage{lipsum}
\usepackage{hyperref}

\usepackage{marginnote}%
\newcounter{original}
\newcommand{\bmark}{\ensuremath{|}}
%produce a breaking mark and a source page number-------------------
\newcommand{\original}{\refstepcounter{original}%increment page counter
    \marginnote{\small\theoriginal}%print source page number in marginpar
    \label{O\theoriginal}%add a label
    \bmark{} %print breaking mark
}

\begin{document}
\frontmatter
\renewcommand{\thepage}{\Roman{page}}

\renewcommand{\theoriginal}{\Roman{original}}
\setcounter{original}{0}

\lipsum[1]
\original

\clearpage
\lipsum[2]
\original

\clearpage
\lipsum[3]
\original

\mainmatter
\renewcommand{\theoriginal}{\arabic{original}}
\setcounter{original}{0}

\chapter{Example}
\lipsum[4]
\original

\clearpage
\lipsum[5]
\original

\clearpage
\lipsum[6]
\original

\chapter{Reference tests}

Number \ref{O2}

\end{document}

As you see, I define a \original command above. I use \original to produce a mark and a source page for the original texts in the original book which is retyped now.

When I use \ref{O2} (see the codes at the bottom) to refer to the number 2 which is not greater than the largest number in the front matter produced by \original, it refers to II while not 2 although it prints 2 in the right way. Why? Is there any way to fix it?

0

1 Answer 1

2

It's really unclear what you're trying to achieve.

A solution for getting correct anchors is to link the counter to another one.

\documentclass{book}

\usepackage{lipsum}
\usepackage{marginnote}

\usepackage{hyperref}

\newcounter{parentoriginal}
\newcounter{original}[parentoriginal]
\newcommand{\resetoriginal}{\stepcounter{parentoriginal}}
\renewcommand{\theHoriginal}{\theparentoriginal.\arabic{original}}

\newcommand{\bmark}{\ensuremath{|}}
%produce a breaking mark and a source page number-------------------
\newcommand{\original}{%
  \refstepcounter{original}%
  \marginnote{\small\theoriginal}%print source page number in marginpar
  \label{O\theoriginal}%add a label
  \bmark{}%print breaking mark
}

\begin{document}
\frontmatter
\renewcommand{\thepage}{\Roman{page}}
\renewcommand{\theoriginal}{\Roman{original}}

\resetoriginal

\lipsum[1]
\original

\clearpage
\lipsum*[2]\original

\clearpage
\lipsum*[3]\original

\mainmatter
\renewcommand{\theoriginal}{\arabic{original}}
\resetoriginal

\chapter{Example}
\lipsum*[4]\original

\clearpage
\lipsum*[5]\original

\clearpage
\lipsum*[6]\original

\chapter{Reference tests}

Number \ref{O2}

\end{document}

A different solution is to modify also \theHoriginal.

\documentclass{book}

\usepackage{lipsum}
\usepackage{marginnote}

\usepackage{hyperref}

\newcounter{original}
\newcommand{\resetoriginal}{\setcounter{original}{0}}

\newcommand{\bmark}{\ensuremath{|}}
%produce a breaking mark and a source page number-------------------
\newcommand{\original}{%
  \refstepcounter{original}%
  \marginnote{\small\theoriginal}%print source page number in marginpar
  \label{O\theoriginal}%add a label
  \bmark{}%print breaking mark
}

\begin{document}

\frontmatter
\renewcommand{\thepage}{\Roman{page}}
\renewcommand{\theoriginal}{\Roman{original}}
\renewcommand{\theHoriginal}{F\arabic{original}}

\resetoriginal

\lipsum[1]
\original

\clearpage
\lipsum*[2]\original

\clearpage
\lipsum*[3]\original

\mainmatter
\renewcommand{\theoriginal}{\arabic{original}}
\renewcommand{\theHoriginal}{M\arabic{original}}
\resetoriginal

\chapter{Example}
\lipsum*[4]\original

\clearpage
\lipsum*[5]\original

\clearpage
\lipsum*[6]\original

\chapter{Reference tests}

Number \ref{O2}

\end{document}
1
  • The first one is better.
    – M. Logic
    Sep 1, 2022 at 1:46

Not the answer you're looking for? Browse other questions tagged .