Created
November 12, 2020 19:13
-
-
Save Kumquatum/7c0cfad2017f288d04d2a2d44edc8e6f to your computer and use it in GitHub Desktop.
Function to create notes with different counters and refer to it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage[utf8]{inputenc} | |
\newcommand\note[2]{\getid{#1}\label{note:#1:#2}\textsuperscript{\ref{note:#1:#2}}} | |
\makeatletter | |
\newcommand{\getid}[1]{% | |
\@ifundefined{c@#1} | |
{% the counter doesn't exist | |
\newcounter{#1}\setcounter{#1}{1}% | |
} | |
{% the counter exists | |
\stepcounter{#1}% | |
}% | |
\def\@currentlabel{\arabic{#1}} | |
} | |
\makeatother | |
\begin{document} | |
\section{Personal notes with multiple counters} | |
Hey there ! Here is a quick gist to create a note inside a texte with one or multiple counter | |
Here is a first bit of text I want to refer to with a counter (mycounter) \note{mycounter}{test1}. | |
And here's is a second one I want to refer with it (mycounter2) \note{mycounter}{test2} | |
Now imagine I want to use another counter (because I'm in another part of my doc for example) and refer to it \note{mycounter2}{tut1} | |
And again use this counter in this bit of text \note{mycounter2}{tut2} | |
--- | |
\ref{note:mycounter:test1}. Here is a reference to explain the ref test1 of mycounter | |
\ref{note:mycounter:test2}. Here is a reference to explain the ref test2 of mycounter | |
\ref{note:mycounter2:tut1}. Here is a reference to explain the ref tut1 of mycounter2 | |
\ref{note:mycounter2:tut2}. Here is a reference to explain the ref tut2 of mycounter2 | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment