I'm need to annotate source code line by line using the listings package. Here's an example of what I'm looking for (made in MS Word):
These particular examples display price of executing each line (left column) and how many times it is being called (right column).
Here's what I got going on so far (nothing done on annotations, as I'm not sure where to even start):
\documentclass[fleqn]{article}
\usepackage{listings}
\usepackage{color}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{document}
\begin{lstlisting}[language=c++,caption=Insertion sort realizacija masyve]
std::vector<int> insertion_sort_array::sort(const std::vector<int> &in) {
std::vector<int> res(in);
for (std::vector<int>::size_type i = 1; i < res.size(); i++) {
for (std::size_t j = i; j > 0 && res[j - 1] > res[j]; j--) {
int tmp = res[j - 1];
res[j - 1] = res[j];
res[j] = tmp;
}
}
return res;
}
\end{lstlisting}
\end{document}
tikzmark
. See tex.stackexchange.com/q/86309/86 for how tikzmark and listings integrate.