0

Hello the latex team

I have detected that the use of hyperref is incompatible with the custom of the todolist \mylistoftodos at the end of the document.

Will you have an explanation and a solution to my problem?

If I comment the package hyperref the bug disappear but obviously not link here are the sources of my inspiration:

[How to add todo notes?

and

[Replacing page number with other counter in listoftodos

the MWE code

\documentclass{book}
%% todonote_custom.tex  fonctionnement ok sur les liens
\usepackage[english,french]{babel}%pour un document en français
%mini sommaire à chaque chapitre
\usepackage[french]{minitoc}
\setcounter{mtc}{5}
\usepackage{xspace}
%Permet à  babel d'utiliser la macro xspace partout où c'est nécessaire. (Voir la doc de babel pour de plus amples explications.)
\usepackage[cyr]{aeguill}
\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{lipsum}                     % Dummytext
%---------------------------------------------------------------------------------
% divers codes pour todonote
\usepackage{ifthen}
% variable pour édition papier ou online
\newboolean{vsersion-pdf}
%VARIABLE À POSITIONNER À true POUR UNE VERSION PDF POUR SITE INTERNET
\setboolean{vsersion-pdf}{true}
%VARIABLE À POSITIONNER À false POUR EDITION PAPIER
%\setboolean{vsersion-pdf}{false}
%---------------------------------------------------------------------------------
\usepackage{hyperref}%rend actif les liens, références croisée, toc, ...
\ifthenelse{ \boolean{vsersion-pdf} }
{% pdf en ligne
    \hypersetup{colorlinks,%
        citecolor=blue,%
        filecolor=blue,%
        linkcolor=orange,%ou bien blue
        urlcolor=blue}
}
{%version papier
    \hypersetup{colorlinks,%
        citecolor=black,%
        filecolor=black,%
        linkcolor=blue,%
        urlcolor=black}
}
\usepackage{xargs}                      % Use more than one optional parameter in a new commands
\usepackage[pdftex,dvipsnames]{xcolor}  % Coloured text etc.
% paramétrage de base
% cette commande est indispensable pour que les lien fonction dans la liste de récap de la FAQ

\usepackage[colorinlistoftodos,french,prependcaption,textsize=tiny]{todonotes}
%liste de nouvelles commandes customisée
\newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}
\newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}
\newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}


\newcounter{faqcounter}
\newcommandx{\faq}[2][1=]{
    \refstepcounter{faqcounter}%
    \ifthenelse{ \boolean{vsersion-pdf} }
    { \todo[fancyline,linecolor=red,backgroundcolor=blue!25,bordercolor=blue,color={red!100!green!33},size=\small]{%
            \textbf{FAQ [\uppercase{#1}N°\thefaqcounter]:}~#2}}
    { \todo[linecolor=red,backgroundcolor=blue!25,bordercolor=blue,color={red!100!green!33},size=\small]{%
            \textbf{FAQ [\uppercase{#1}N°\thefaqcounter]:}~#2}}}
%---------------------------------------------------------------------------------
%The  idea  is  to  define  a  newcommand\mycomment which  adds  a  counter  and  optionally  the  initials  of  theauthor to the inserted todonote.
\newcounter{mycomment}
\newcommand{\mycomment}[2][]{%
    % initials of the author (optional) + note in the margin
    \refstepcounter{mycomment}%
    {%
        %\setstretch{0.7}% spacing cette ligne perturbe
        \todo[color={red!100!green!33},size=\small]{%
            \textbf{Commentaire [\uppercase{#1}-N°\themycomment]:}~#2}%
}}  



%---------------------------------------------------------------------------------
% gestion de notes avec un mot encadré et placé au fil de l'eau dans le texte avec option livre ou online
% commande \margintip {mot}{commentaire}
\newcommand{\tipword}[1]{\colorlet{currentcolor}{.}{\color{red}\fbox{\color{currentcolor}#1}}} 
\newcommand{\tipitself}[1]{
    \ifthenelse{ \boolean{vsersion-pdf} }
    { \todo[backgroundcolor=OliveGreen!25,bordercolor=red,fancyline]{#1}}
    { \todo[backgroundcolor=OliveGreen!25,bordercolor=red]{#1}}
} 
\newcommand{\margintip}[2]{\tipword{#1}\tipitself{#2}} 
%---------------------------------------------------------------------------------
% commentaire à la word pour les auteurs

%---------------------------------------------------------------------------------
% part of custom is not compatible with hyperref
\makeatletter
\def\myaddcontentsline#1#2#3{%
    \addtocontents{#1}{\protect\contentsline{#2}{#3}{voir \thesection\  page. \thepage}}}
\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \myaddcontentsline{tdo}{todo}{{%
            \colorbox{\@todonotes@currentbackgroundcolor}%
            {\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption}}%
    \else%
    \myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}%
    \fi}%
\newcommand*\mylistoftodos[1][nom par défaut]{%
    \begingroup
    \setbox\@tempboxa\hbox{see 9.9 at p. 99}%
    \renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
    \renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
    \listoftodos[#1]%
    \endgroup
}
\makeatother

%---------------------------------------------------------------------------------
% --------------------- FIN des commandes pour tonotes----------------------------

%---------------------------------------------------------------------------------
\begin{document}
\dominitoc
\pagestyle{empty}
\chapter{démo de todonotes}
\minitoc
\textbf{Ce code fonctionne correctement les hyperliens de la liste récap pointent sur les bonnes pages.}
\section{section todo en ligne}
\todo[inline]{The original todo note withouth changed colours.\newline Here's another line.}
\section{section test de todo dans la marge}
\lipsum[150]\unsure{Is this correct?}\unsure{I'm unsure about also!}
\lipsum[120]\change{Change this!}
\lipsum[110]\info{This can help me in chapter seven!}
\lipsum[110]\improvement{This really needs to be improved!\newline\newline What was I thinking?!}
\lipsum[5]

\section{section zone cachée à revoir}
\thiswillnotshow{This is hidden since option `disable' is chosen!}
\improvement[inline]{The following section needs to be rewritten!}

\section{Commentaires à la Word}
Toujours plus fort il peut être nécessaire de travailler à plusieurs et d'apporter des annotations diverses par auteur
The  idea  is  to  define  a  newcommand \verb+\mycomment +  which adds  a  counter  and  optionally  the  initials  of  the author to the inserted todonote.\mycomment[FD]{Ceci est mon commentaire auteur FD}

\lipsum[1]\faq{il faut bien en faire une}
\lipsum[1]\faq{il faut bien en faire deux}
\lipsum[1]\faq{il faut bien en faire trois}
\lipsum[1]\margintip{mot louche}{il faut bien en faire quatre}
Now this is where the tip word comes in, it's \margintip{form}{this is the tip (\textbf{form})} can be shaped with the todo package \margintip{pas le bon texte}{il faut bien en faire cinq}

\lipsum[1] \faq{il faut bien en faire trois}


Now this is where the tip word comes in, it's \margintip{form}{this is the tip} can be shaped with the todo package 

\lipsum[3-4] 

\begin{enumerate}
    \setlength\itemsep{0.05em} %semble ok 
    \item trop de todonotes devient impossible à bien gérer.
    \item énumérer juste avant tous les points à traiter pour la rédaction du livre. A la fin cette liste est vide. \todo[fancyline]{du coup le texte est à enlever.}
    \item Etablir une FAQ liée au livre .\faq[FD]{Et là le travail est à faire au fil de l'eau.}
    \item Etablir une FAQ liée au livre \faq{aussi du coup le texte est à enlever.}
\end{enumerate}
\todo[inline]{vérifier que les liens de la faq pointe bien sur la bonne page actuellement il y a un bug.}

\lipsum[1]voila ici commentaire à la word.\mycomment[FD]{Ceci est mon commentaire} notez que marginpar is moved!!
\mylistoftodos[Liste des points a traiter...]

\end{document}

Editing to add fixing incomplete for hyperref with 4 parameter with this new step I have bad link but I have link :-)

\documentclass{book}
%% todonote_custom_next.tex  fonctionnement ok sur les liens
\usepackage[english,french]{babel}%pour un document en français
%mini sommaire à chaque chapitre
\usepackage[french]{minitoc}
\setcounter{mtc}{5}
\usepackage{xspace}
%Permet à  babel d'utiliser la macro xspace partout où c'est nécessaire. (Voir la doc de babel pour de plus amples explications.)
\usepackage[cyr]{aeguill}
\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{lipsum}                     % Dummytext
%---------------------------------------------------------------------------------
% divers codes pour todonote
\usepackage{ifthen}
% variable pour édition papier ou online
\newboolean{vsersion-pdf}
%VARIABLE À POSITIONNER À true POUR UNE VERSION PDF POUR SITE INTERNET
\setboolean{vsersion-pdf}{true}
%VARIABLE À POSITIONNER À false POUR EDITION PAPIER
%\setboolean{vsersion-pdf}{false}
%---------------------------------------------------------------------------------
\usepackage{hyperref}%rend actif les liens, références croisée, toc, ...
\ifthenelse{ \boolean{vsersion-pdf} }
{% pdf en ligne
    \hypersetup{colorlinks,%
        citecolor=blue,%
        filecolor=blue,%
        linkcolor=orange,%ou bien blue
        urlcolor=blue}
}
{%version papier
    \hypersetup{colorlinks,%
        citecolor=black,%
        filecolor=black,%
        linkcolor=blue,%
        urlcolor=black}
}
\usepackage{xargs}                      % Use more than one optional parameter in a new commands
\usepackage[pdftex,dvipsnames]{xcolor}  % Coloured text etc.
% paramétrage de base
% cette commande est indispensable pour que les lien fonction dans la liste de récap de la FAQ

\usepackage[colorinlistoftodos,french,prependcaption,textsize=tiny]{todonotes}
%liste de nouvelles commandes customisée
\newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}
\newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}
\newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}


\newcounter{faqcounter}
\newcommandx{\faq}[2][1=]{
    \refstepcounter{faqcounter}%
    \ifthenelse{ \boolean{vsersion-pdf} }
    { \todo[fancyline,linecolor=red,backgroundcolor=blue!25,bordercolor=blue,color={red!100!green!33},size=\small]{%
            \textbf{FAQ [\uppercase{#1}N°\thefaqcounter]:}~#2}}
    { \todo[linecolor=red,backgroundcolor=blue!25,bordercolor=blue,color={red!100!green!33},size=\small]{%
            \textbf{FAQ [\uppercase{#1}N°\thefaqcounter]:}~#2}}}
%---------------------------------------------------------------------------------
%The  idea  is  to  define  a  newcommand\mycomment which  adds  a  counter  and  optionally  the  initials  of  theauthor to the inserted todonote.
\newcounter{mycomment}
\newcommand{\mycomment}[2][]{%
    % initials of the author (optional) + note in the margin
    \refstepcounter{mycomment}%
    {%
        %\setstretch{0.7}% spacing cette ligne perturbe
        \todo[color={red!100!green!33},size=\small]{%
            \textbf{Commentaire [\uppercase{#1}-N°\themycomment]:}~#2}%
}}  



%---------------------------------------------------------------------------------
% gestion de notes avec un mot encadré et placé au fil de l'eau dans le texte avec option livre ou online
% commande \margintip {mot}{commentaire}
\newcommand{\tipword}[1]{\colorlet{currentcolor}{.}{\color{red}\fbox{\color{currentcolor}#1}}} 
\newcommand{\tipitself}[1]{
    \ifthenelse{ \boolean{vsersion-pdf} }
    { \todo[backgroundcolor=OliveGreen!25,bordercolor=red,fancyline]{#1}}
    { \todo[backgroundcolor=OliveGreen!25,bordercolor=red]{#1}}
} 
\newcommand{\margintip}[2]{\tipword{#1}\tipitself{#2}} 
%---------------------------------------------------------------------------------
% commentaire à la word pour les auteurs

%---------------------------------------------------------------------------------
% part of custom is not compatible with hyperref
\makeatletter
\def\myaddcontentsline#1#2#3#4{%
    % first solution without hyperref using
    %\addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at page. \thepage}}}
    % new solution to be compatible with hyperrref 4 parameter for \addtocontents
     \addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at page \thepage}{#4}}}%
\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \myaddcontentsline{tdo}{todo}{{%
            \colorbox{\@todonotes@currentbackgroundcolor}%
            {\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption}}{fourth parameter}%
    \else%
    \myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}{fourth parameter}%
    \fi}%
\newcommand*\mylistoftodos[1][nom par défaut]{%
    \begingroup
    \setbox\@tempboxa\hbox{see 9.9 at p. 99}%
    \renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
    \renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
    \listoftodos[#1]%
    \endgroup
}
\makeatother

%---------------------------------------------------------------------------------
% --------------------- FIN des commandes pour tonotes----------------------------

%---------------------------------------------------------------------------------
\begin{document}
\dominitoc
\pagestyle{empty}
\chapter{démo de todonotes}
\minitoc
\textbf{Ce code fonctionne correctement les hyperliens de la liste récap pointent sur les bonnes pages.}
\section{section todo en ligne}
\todo[inline]{The original todo note withouth changed colours.\newline Here's another line.}
\section{section test de todo dans la marge}
\lipsum[150]\unsure{Is this correct?}\unsure{I'm unsure about also!}
\lipsum[120]\change{Change this!}
\lipsum[110]\info{This can help me in chapter seven!}
\lipsum[110]\improvement{This really needs to be improved!\newline\newline What was I thinking?!}
\lipsum[5]

\section{section zone cachée à revoir}
\thiswillnotshow{This is hidden since option `disable' is chosen!}
\improvement[inline]{The following section needs to be rewritten!}

\section{Commentaires à la Word}
Toujours plus fort il peut être nécessaire de travailler à plusieurs et d'apporter des annotations diverses par auteur
The  idea  is  to  define  a  newcommand \verb+\mycomment +  which adds  a  counter  and  optionally  the  initials  of  the author to the inserted todonote.\mycomment[FD]{Ceci est mon commentaire auteur FD}

\lipsum[1]\faq{il faut bien en faire une}
\lipsum[1]\faq{il faut bien en faire deux}
\lipsum[1]\faq{il faut bien en faire trois}
\lipsum[1]\margintip{mot louche}{il faut bien en faire quatre}
Now this is where the tip word comes in, it's \margintip{form}{this is the tip (\textbf{form})} can be shaped with the todo package \margintip{pas le bon texte}{il faut bien en faire cinq}

\lipsum[1] \faq{il faut bien en faire trois}


Now this is where the tip word comes in, it's \margintip{form}{this is the tip} can be shaped with the todo package 

\lipsum[3-4] 

\begin{enumerate}
    \setlength\itemsep{0.05em} %semble ok 
    \item trop de todonotes devient impossible à bien gérer.
    \item énumérer juste avant tous les points à traiter pour la rédaction du livre. A la fin cette liste est vide. \todo[fancyline]{du coup le texte est à enlever.}
    \item Etablir une FAQ liée au livre .\faq[FD]{Et là le travail est à faire au fil de l'eau.}
    \item Etablir une FAQ liée au livre \faq{aussi du coup le texte est à enlever.}
\end{enumerate}
\todo[inline]{vérifier que les liens de la faq pointe bien sur la bonne page actuellement il y a un bug.}

\lipsum[1]voila ici commentaire à la word.\mycomment[FD]{Ceci est mon commentaire} notez que marginpar is moved!!
\mylistoftodos[Liste des points a traiter...]
%\listoftodos
\end{document}

I understand a basic MWE is neccessary to the next

see follow code please

\documentclass{book}
%% todonote_custom_MWE.tex  fonctionnement ok sur les liens
\usepackage[english,french]{babel}%pour un document en français

\usepackage[cyr]{aeguill}
\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{lipsum}                     % Dummytext
%---------------------------------------------------------------------------------
\usepackage{hyperref}%rend actif les liens, références croisée, toc, ...


\hypersetup{colorlinks,%
    citecolor=blue,%
    filecolor=blue,%
    linkcolor=orange,%ou bien blue
    urlcolor=blue}
\usepackage{xargs}                      % Use more than one optional parameter in a new commands
\usepackage[pdftex,dvipsnames]{xcolor}  % Coloured text etc.

\usepackage[colorinlistoftodos,french,prependcaption,textsize=tiny]{todonotes}
%liste de nouvelles commandes customisée
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}




%---------------------------------------------------------------------------------
% part of custom is not compatible with hyperref
\makeatletter
\def\myaddcontentsline#1#2#3#4{%
    % first solution without hyperref using
    %\addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at page. \thepage}}}
    % new solution to be compatible with hyperrref 4 parameter for \addtocontents
     \addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at page \thepage}{#4}}}{}%
\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \myaddcontentsline{tdo}{todo}{{%
            \colorbox{\@todonotes@currentbackgroundcolor}%
            {\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption}}{blalbla}%
    \else%
    \myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}{blabla}%
    \fi}%
\newcommand*\mylistoftodos[1][nom par défaut]{%
    \begingroup
    \setbox\@tempboxa\hbox{see 9.9 at p. 99}%
    \renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
    \renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
    \listoftodos[#1]%
    \endgroup
}
\makeatother
%---------------------------------------------------------------------------------
\begin{document}


\chapter{démo de todonotes}

\lipsum[1]\info{il faut bien en faire une}
\lipsum[1]\info{il faut bien en faire deux}
\lipsum[1]\info{il faut bien en faire trois}

\mylistoftodos[Liste des points a traiter...]
\end{document}

Do you think ist's now enough basic for your test (part in order to help Ulrike) ? Thanks by advance

Manmax
  • 11
  • when using hyperref, \contentsline should have four arguments. – Ulrike Fischer Apr 15 '20 at 12:02
  • Ok I found this : To make it compatible with hyperref it should be \addtocontents{#1}{\protect\contentsline{#2}{#3}{see \thesection\ at p. \thepage}{}}} (extra pair of curly braces at the end), @midtiby: you may want to update the example in the todonotes manual. – Jörg Jun 22 '12 at 10:54 Now it's better but link are not active in the todolist what is neccessary to add – Manmax Apr 16 '20 at 15:46
  • I found also : It's a redefined \contentsline by package hyperref, which needs to know the link target name for the entry in the table of contents. The target name is stored in the fourth argument. I don't know what data to add – Manmax Apr 16 '20 at 15:57
  • I think the fourth parameter is material to operate a link toward the target. The idea is a ref to the margin note. Any idea ? How to ref to the local todonote – Manmax Apr 17 '20 at 23:23
  • Yes the parameter is the destination name. But your example is too long and complicated. I don't have the time to debug this. – Ulrike Fischer Apr 18 '20 at 02:46
  • Some part was deleted by admin because of I didn't respect policy... And now I ping @ Ulrike Fischer again in order to study the small code added – Manmax Apr 27 '20 at 23:31

1 Answers1

1

You only need to add always \@currentHref as the fourth argument:

\documentclass{book}
%% todonote_custom_MWE.tex  fonctionnement ok sur les liens
\usepackage[english,french]{babel}%pour un document en français

%\usepackage[cyr]{aeguill} %outdated
%\usepackage[latin1]{inputenc} % I have utf8 by default
\usepackage[T1]{fontenc}
\usepackage{lipsum}                     % Dummytext

\usepackage{xargs}                      % Use more than one optional parameter in a new commands
\usepackage[pdftex,dvipsnames]{xcolor}  % Coloured text etc.

\usepackage[colorinlistoftodos,french,prependcaption,textsize=tiny]{todonotes}

%---------------------------------------------------------------------------------
\usepackage{hyperref}%rend actif les liens, références croisée, toc, ...


\hypersetup{colorlinks,%
    citecolor=blue,%
    filecolor=blue,%
    linkcolor=orange,%ou bien blue
    urlcolor=blue}
%liste de nouvelles commandes customisée
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}

\makeatletter
\def\myaddcontentsline#1#2#3{%
     \addtocontents{#1}{\protect\contentsline{#2}{#3}%
     {see \thesection\ at page \thepage}{\@currentHref}}}{}% %<-------------

\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \myaddcontentsline{tdo}{todo}{{%
            \colorbox{\@todonotes@currentbackgroundcolor}%
            {\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
            \ \@todonotes@caption}}%
    \else%
    \myaddcontentsline{tdo}{todo}{{\@todonotes@caption}}%
    \fi}%

\newcommand*\mylistoftodos[1][nom par défaut]{%
    \begingroup
    \setbox\@tempboxa\hbox{see 9.9 at p. 99}%
    \renewcommand*\@tocrmarg{\the\wd\@tempboxa}%
    \renewcommand*\@pnumwidth{\the\wd\@tempboxa}%
    \listoftodos[#1]%
    \endgroup
}
\makeatother
%---------------------------------------------------------------------------------
\begin{document}


\chapter{démo de todonotes}

\lipsum[1]\info{il faut bien en faire une}
\lipsum[1]\info{il faut bien en faire deux}
\lipsum[1]\info{il faut bien en faire trois}

\mylistoftodos[Liste des points a traiter...]
\end{document}
Ulrike Fischer
  • 327,261