I've searched quite a bit but haven't found a solution quite yet. I am working on a LaTeX labbook, and in addition the "project" sorting of the experiments, I would like to add a chapter called "log" where I have a chronological list of what I did and a reference to the page in which the experiment is done.
To do so I created 2 new commands. The first is \logg{}{} in which I add the date in the first argument, and a short description of what I did in that day for a specific project in the second argument. The second command is called \showlogg and should sort all the logg entries by the date, and display them using "date" "description" and the page that was referencing.
Here is an example:
\documentclass[a4paper]{report}
\usepackage{hyperref}
\usepackage{datatool} %pour créer des databases, surtout nécessaire pour les macros
\usepackage{ifthen}
\DTLnewdb{list} %important pour la commande \logg
\newcounter{logglabel}
\setcounter{logglabel}{0}
\newcommand\logg[2]{% fait une entree dans le labbook de type \logg{date}{résumé de ce qui a été fait}
{\vspace{0.5cm}\large{#1}}%
\stepcounter{logglabel}
\label{\thelogglabel}
\DTLnewrow{list}
\DTLnewdbentry{list}{Date}{#1}
\DTLnewdbentry{list}{Description}{#2}
\DTLnewdbentry{list}{Page}{\pageref{\thelogglabel}}
}
\newcommand\showlogg{% fait un index avec toutes les entrées de \logg triées par date, avec pour infos date, résumé, et page de l'experience.
\DTLsort{Date}{list}
\DTLforeach*{list}{\date=Date,\desc=Description,\pa=Page}{\textbf{\date} \hspace{0.25cm} \desc \dotfill \pa \\}
}
\begin{document}
\chapter{My labbook}
\section{My first experiment}
Here is an experiment that I did on \logg{20171006}{I tried banana and coco}\\
I tried to grow banana but bananas wouldn't grow, I tried to grow coco but coco wouldn't grow.
\newpage %just to show what happens when both \logg are on different pages
\section{My second experiment}
Here is something I did on \logg{20171002}{I tried to grow apples and oranges}\\
Actually before bananas and coco I also tried apples and oranges.
\newpage
\section{The log of my experiments}
\showlogg
\end{document}
My current issue is that when I put several \logg entries in my file, the command \showlogg shows the correct dates, the correct descriptions but always the page of the last \logg entry. Is there a way to make sure that the page is referring to the right place?
Or more generally formulated: is it possible to create a command, that automatically creates a label, where the tag within the label (\label{tag}) is of incrementing numbers, and the \pageref used right afterwards is with the exact same number?


