# What I want:

I would like to reference text lines: I wrote something at one part of my document and would like to reference these particular lines in other parts of the document.

During my experiment I have done this and that (See \evref{experiment:1}), and that was great.

....

First I took the xy and put the stuff into the tube.
Then I did some other stuff. \evid{experiment:1}
Also I did crazy things.


I would like to have all the actual line labels in the margin (already solved this) and I'd like them to be numbers.

# What I have already done:

I already got pretty far with the code (I display only the crucial part):

\newcounter{evidcount}
\newcommand{\evref}[1]{\hyperref[evidence:#1]{#1}}
\marginnote{\RaggedLeft\phantomsection\label{evidence:\theevidcount}\evidcirlce{\theevidcount}}


\RaggedLeft comes from the package ragged2e.

As one can see, the text which is used for reference is a running counter. In the body of the document I use these command like this:

During my experiment I have done this and that (See \evref{2}), and that was great.

....

First I took the xy and put the stuff into the tube. \evid
Then I did some other stuff. \evid
Also I did crazy things.


# Why it's not what I want, yet:

This should be the case in the future version, I'd like to have. However, the current version requires me to know the running counter for a particular line I'd like to reference - which is an issue if a new reference is added. Then I have to change all the references. Instead I'd like to have a label for the reference and the referee. Still, the text displayed should be the running counter - just as seen in my first grey box.

How do I do this?

# What I also don't want:

I don't want to have the number along all lines, only on those lines which are actually referenced. So I don't want all lines numbered consecutively, but only the referenced lines numbered consecutively.

Also I don't just want numbers, but fancy circles. This is not in the code above to preserve readability, but I am actually using the command

\newcommand{\evidcirlce}[1]{
\raisebox{1pt}{%
\begin{tikzpicture}[baseline=(C.base)]%%
\node[draw,circle,inner sep=0.5pt,fill=black](C){\color{white}\scriptsize\bfseries#1};%
\end{tikzpicture}}}


PS: Some people may say this is not pretty (I am writing this just in case), then I have to say this:

1. Its taste, we can't argue about taste.
2. "pretty" is off topic regarding the question.
3. I might change it anyway in the future, so no point arguing.
• If you use \refstepcounter{evidcount} followed by \label{name} then \ref{name} will return \theevidcount and hypperref will link to the location where \refstepcounter was used (not necessarily the \label location). – John Kormylo Sep 26 '15 at 16:42
• I'm not sure I get this. Could you write an answer, where you include it into my command from above. Maybe even make a minimal working example? – Make42 Sep 26 '15 at 17:03

BTW, I don't know what package \Raggedleft comes from. This is why a full MWE is better than snippets.

\documentclass{article}
\usepackage{marginnote}
\usepackage{tikz}
\usepackage{hyperref}

\newcommand{\evidcirlce}[1]{
\raisebox{1pt}{%
\begin{tikzpicture}[baseline=(C.base)]%%
\node[draw,circle,inner sep=0.5pt,fill=black](C){\color{white}\scriptsize\bfseries#1};%
\end{tikzpicture}}}

\newcounter{evidcount}
\newcommand{\evid}[1]{\marginnote{\refstepcounter{evidcount}\label{#1}%
\evidcirlce{\theevidcount}}}

\begin{document}
During my experiment I have done this and that (See \ref{experiment}), and that was great.
\vfil
First I took the xy and put the stuff into the tube.
Then I did some other stuff. \evid{experiment}
Also I did crazy things.

\end{document}


# EDIT: Final commands (used by OP)

\usepackage{ragged2e} % Providing \RaggedRight
\newcounter{evidcount}

\newcommand{\evref}[2][]{\ifthenelse{\equal{#1}{}}{{\footnotesize[\ref{#2}]}}{{\footnotesize[\ref{#1}\,-\,\ref{#2}]}}}

\newcommand{\evid}[1]{%
\marginnote{\RaggedLeft\refstepcounter{evidcount}\label{#1}%
{\footnotesize[\theevidcount]}}%
}