我正在使用下面的代码来获取文档中所有评论的待办事项列表。问题是列表显示文档的最后一部分,但没有任何评论。只应显示带有评论的部分。有什么想法如何解决这个问题吗?
\documentclass{article}
\usepackage{todonotes,tocloft,xpatch,hyperref}
% This is based on classicthesis chapter definition
\let\oldsec=\section
\renewcommand*{\section}{\secdef{\Sec}{\SecS}}
\newcommand\SecS[1]{\oldsec*{#1}}%
\newcommand\Sec[2][]{\oldsec[\texorpdfstring{#1}{#1}]{#2}}%
% http://tex.stackexchange.com/a/61267/11984
\makeatletter
\xapptocmd{\Sec}{\addtocontents{tdo}{\protect\todoline{\thesection}{#1}{}}}{}{}
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[3]{%
\@ifnextchar\todoline
{}
{\contentsline{section}{\numberline{#1}#2}{#3}{}{}}%
}
\let\l@todo\l@subsection
\newcommand{\Endoftdo}{}
\AtEndDocument{\addtocontents{tdo}{\string\Endoftdo}}
\makeatother
\begin{document}
\listoftodos
\tableofcontents
\section{My first Section}\todo{Section 1 note}
\subsection{A first Subsection}
\subsubsection{A first subsubsection}\todo{Section 1, section 1, subsection note}
\subsection{Another subsection}\todo{Section 1, section 1, subsection note 2}
\section{My second Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\section{My third Section}
\section{My fourth Section}
\end{document}
答案1
\xapptocmd{\Sec}{\addtocontents{...}}{}{}
每次使用时都会添加一个 Toc 条目,\section
无论是否存在待办事项注释。
我认为它应该被删除!
如果我有时间,我会为这个\todoline
问题提供另一种解决方案。
\documentclass{article}
\usepackage{todonotes,tocloft,xpatch,hyperref}
% This is based on classicthesis chapter definition
\let\oldsec=\section
\renewcommand*{\section}{\secdef{\Sec}{\SecS}}
\newcommand\SecS[1]{\oldsec*{#1}}%
\newcommand\Sec[2][]{\oldsec[\texorpdfstring{#1}{#1}]{#2}}%
\newcounter{istodo}[section]
% http://tex.stackexchange.com/a/61267/11984
\makeatletter
%\xapptocmd{\Sec}{\addtocontents{tdo}{\protect\todoline{\thesection}{#1}{}}}{}{}
\newcommand{\todoline}[1]{\@ifnextchar\Endoftdo{}{\@todoline{#1}}}
\newcommand{\@todoline}[3]{%
\@ifnextchar\todoline{}
{\contentsline{section}{\numberline{#1}#2}{#3}{}{}}%
}
\let\l@todo\l@subsection
\newcommand{\Endoftdo}{}
\AtEndDocument{\addtocontents{tdo}{\string\Endoftdo}}
\makeatother
\begin{document}
\listoftodos
\tableofcontents
\section{My first Section}\todo{Section 1 note}
\subsection{A first Subsection}
\subsubsection{A first subsubsection}\todo{Section 1, section 1, subsection note}
\subsection{Another subsection}\todo{Section 1, section 1, subsection note 2}
\section{My second Section}
\subsection{Another subsection}\todo{Section 2, subsection 1 note}
\subsection{Another subsection}\todo{Section 2, subsection 2 note}
\section{My third Section}
\section{My fourth Section}
\end{document}