Skip to content

Commit

Permalink
Don't repeat labels
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Jan 18, 2024
1 parent 5019457 commit 90faecc
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 311 deletions.
Binary file modified docs/images/pandoc-numbering-sample.epub
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/images/pandoc-numbering-sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class="pandoc-numbering-entry theorem">Theorem 2.2</span></a></li>
</ul>
<h1 id="this-is-the-first-section">This is the first section</h1>
<p><span id="exercise:1"></span><span id="exercise:1"
<p><span></span><span id="exercise:1"
class="pandoc-numbering-text exercise"><strong>Exercise
1</strong></span></p>
<p>This is the first exercise. Have also a look at the <a
Expand Down
Binary file modified docs/images/pandoc-numbering-sample.pdf
Binary file not shown.
43 changes: 20 additions & 23 deletions docs/images/pandoc-numbering-sample.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,72 @@
\listofexercise
\listoftheorem}

\hypertarget{this-is-the-first-section}{%
\section{This is the first section}\label{this-is-the-first-section}}
\section{This is the first section}\label{this-is-the-first-section}

\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {1}{\ignorespaces {}}}\protect\hypertarget{exercise:1}{}{}\protect\hypertarget{exercise:1}{}{\label{exercise:1}\label{exercise:1}\textbf{Exercise
\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {1}{\ignorespaces {}}}{}\phantomsection\label{exercise:1}{\textbf{Exercise
1}}

This is the first exercise. Have also a look at the
\protect\hyperlink{theorem:first}{{Theorem 1.1 (Needed for the
\protect\hyperlink{exercise:second}{second exercise})}}, the
\protect\hyperlink{exercise:second}{{exercise 2}} and the
\protect\hyperlink{exercise:last}{{exercise 3}}.
\hyperref[theorem:first]{{Theorem 1.1 (Needed for the
\hyperref[exercise:second]{second exercise})}}, the
\hyperref[exercise:second]{{exercise 2}} and the
\hyperref[exercise:last]{{exercise 3}}.

\begin{quote}
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {1.1}{\ignorespaces {Needed for the \protect\hyperlink{exercise:second}{second exercise}}}}\protect\hypertarget{theorem:this-is-the-first-section.needed-for-the-second-exercise}{}{}\protect\hypertarget{theorem:first}{}{\label{theorem:first}\label{theorem:this-is-the-first-section.needed-for-the-second-exercise}\emph{Theorem
1.1: Needed for the \protect\hyperlink{exercise:second}{second
exercise}}}
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {1.1}{\ignorespaces {Needed for the \hyperref[exercise:second]{second exercise}}}}\phantomsection\label{theorem:this-is-the-first-section.needed-for-the-second-exercise}{}\phantomsection\label{theorem:first}{\emph{Theorem
1.1: Needed for the \hyperref[exercise:second]{second exercise}}}

This is a the first theorem. Look at the
\protect\hyperlink{exercise:second}{exercise}.
\hyperref[exercise:second]{exercise}.
\end{quote}

\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {2}{\ignorespaces {}}}\protect\hypertarget{exercise:this-is-the-second-exercise}{}{}\protect\hypertarget{exercise:second}{}{\label{exercise:second}\label{exercise:this-is-the-second-exercise}\textbf{Exercise
\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {2}{\ignorespaces {}}}\phantomsection\label{exercise:this-is-the-second-exercise}{}\phantomsection\label{exercise:second}{\textbf{Exercise
2} \emph{(This is the second exercise)}}

Use \protect\hyperlink{theorem:first}{\emph{theorem 1.1} page
Use \hyperref[theorem:first]{\emph{theorem 1.1} page
\pageref{theorem:first}}

\begin{description}
\tightlist
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {1.1}{\ignorespaces {Example}}}\protect\hypertarget{example:this-is-the-first-section.1}{}{}\protect\hypertarget{example:1.1}{}{\label{example:1.1}\label{example:this-is-the-first-section.1}\textbf{Example
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {1.1}{\ignorespaces {Example}}}\phantomsection\label{example:this-is-the-first-section.1}{}\phantomsection\label{example:1.1}{\textbf{Example
1}}]
This is the first example of the first section
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {1.2}{\ignorespaces {Example}}}\protect\hypertarget{example:this-is-the-first-section.2}{}{}\protect\hypertarget{example:1.2}{}{\label{example:1.2}\label{example:this-is-the-first-section.2}\textbf{Example
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {1.2}{\ignorespaces {Example}}}\phantomsection\label{example:this-is-the-first-section.2}{}\phantomsection\label{example:1.2}{\textbf{Example
2}}]
This is the second example of the first section
\end{description}

\hypertarget{this-is-the-second-section}{%
\section{This is the second section}\label{this-is-the-second-section}}
\section{This is the second section}\label{this-is-the-second-section}

\begin{description}
\tightlist
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {2.1}{\ignorespaces {Example}}}\protect\hypertarget{example:this-is-the-second-section.1}{}{}\protect\hypertarget{example:2.1}{}{\label{example:2.1}\label{example:this-is-the-second-section.1}\textbf{Example
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {2.1}{\ignorespaces {Example}}}\phantomsection\label{example:this-is-the-second-section.1}{}\phantomsection\label{example:2.1}{\textbf{Example
1}}]
This is the first example of the second section
\end{description}

\begin{quote}
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {2.1}{\ignorespaces {\(a=b\)}}}\protect\hypertarget{theorem:this-is-the-second-section.a-b}{}{}\protect\hypertarget{theorem:2.1}{}{\label{theorem:2.1}\label{theorem:this-is-the-second-section.a-b}\emph{Theorem
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {2.1}{\ignorespaces {\(a=b\)}}}\phantomsection\label{theorem:this-is-the-second-section.a-b}{}\phantomsection\label{theorem:2.1}{\emph{Theorem
2.1: \(a=b\)}}

Another theorem. Can be useful in \protect\hyperlink{exercise:1}{}
Another theorem. Can be useful in \hyperref[exercise:1]{}
\end{quote}

\begin{quote}
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {2.2}{\ignorespaces {Theorem}}}\protect\hypertarget{theorem:this-is-the-second-section.2}{}{}\protect\hypertarget{theorem:2.2}{}{\label{theorem:2.2}\label{theorem:this-is-the-second-section.2}\emph{Theorem
\phantomsection\addcontentsline{theorem}{theorem}{\protect\numberline {2.2}{\ignorespaces {Theorem}}}\phantomsection\label{theorem:this-is-the-second-section.2}{}\phantomsection\label{theorem:2.2}{\emph{Theorem
2.2}}

A last theorem.
\end{quote}

\begin{description}
\tightlist
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {2.2}{\ignorespaces {Example}}}\protect\hypertarget{example:this-is-the-second-section.2}{}{}\protect\hypertarget{example:2.2}{}{\label{example:2.2}\label{example:this-is-the-second-section.2}\textbf{Example
\item[\phantomsection\addcontentsline{example}{example}{\protect\numberline {2.2}{\ignorespaces {Example}}}\phantomsection\label{example:this-is-the-second-section.2}{}\phantomsection\label{example:2.2}{\textbf{Example
2}}]
This is the second example of the second section
\end{description}

\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {3}{\ignorespaces {}}}\protect\hypertarget{exercise:3}{}{}\protect\hypertarget{exercise:last}{}{\label{exercise:last}\label{exercise:3}\textbf{Exercise
\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {3}{\ignorespaces {}}}\phantomsection\label{exercise:3}{}\phantomsection\label{exercise:last}{\textbf{Exercise
3}}

This is the third exercise.
Expand Down
33 changes: 20 additions & 13 deletions pandoc_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,26 @@ def _compute_global_number(self):
def _compute_data(self):
# pylint: disable=too-many-statements,no-member
classes = self._doc.defined[self._basic_category]["classes"]
self._set_content(
[
Span(identifier=self._alias),
Span(identifier=self._tag, classes=["pandoc-numbering-text"] + classes),
]
)
if self._alias == self._tag:
self._set_content(
[
Span(),
Span(
identifier=self._tag,
classes=["pandoc-numbering-text"] + classes,
),
]
)
else:
self._set_content(
[
Span(identifier=self._alias),
Span(
identifier=self._tag,
classes=["pandoc-numbering-text"] + classes,
),
]
)
self._link.classes = self._link.classes + classes
self._entry.classes = self._entry.classes + classes

Expand Down Expand Up @@ -532,13 +546,6 @@ def _compute_data(self):

# Finalize the content
if self._doc.format in {"tex", "latex"}:
self._get_content()[1].content.insert(
0, RawInline("\\label{" + self._alias + "}", "tex")
)
self._get_content()[1].content.insert(
0, RawInline("\\label{" + self._tag + "}", "tex")
)

latex_category = re.sub("[^a-z]+", "", self._basic_category)
latex = (
"\\phantomsection"
Expand Down
Loading

0 comments on commit 90faecc

Please sign in to comment.