我已经为要做的:
\documentclass{book}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools,etoolbox}
\usepackage{float}
\usepackage{amstext} % for \text macro
\usepackage{array}
\usepackage{tocloft}
\usepackage{xcolor}
\newcommand{\addchaptertotoctodos}{\relax}
\newcommand{\addsectiontotoctodos}{\relax}
\newcounter{TotTodos}
\newcommand{\listtodosname}{List of to do's (\arabic{TotTodos})}
\newlistof{todos}{todo}{\listtodosname}
\newcounter{todo}[chapter]
\newcommand\todo[1]{
\refstepcounter{todo}
\phantomsection
\label{todo:\thechapter.\thetodo}\stepcounter{TotTodos}
\textcolor{red}{To do \thetodo} \textcolor{gray}{#1}
\addchaptertotoctodos
\renewcommand{\addchaptertotoctodos}{\relax}
\addcontentsline{todo}{todos}
{\protect\numberline{\thechapter.\thetodo} #1}
}
% change the cmd chapter to add the chapterts to the list of todo's
\makeatletter
\let\ori@chapter\@chapter
\def\@chapter[#1]#2{\ori@chapter[#1]{#2}%
\if@mainmatter\renewcommand{\addchaptertotoctodos}{\addcontentsline{todo}{chapter}{\protect\numberline{\thechapter}{#1}}}%
\else\renewcommand{\addchaptertotoctodos}{\addcontentsline{todo}{chapter}{#1}}%
\fi}
\makeatother
\begin{document}
\chapter{First chapter}
\todo{a}
\section{Section 1.1}
\todo{b}
\section{Section 1.2}
\todo{c}
\section{Section 1.3}
\chapter{Middle chapter}
\chapter{Second chapter}
\section{Section 2.1}
\todo{d}
\section{Section 2.2}
\section{Section 2.3}
\todo{e}
\chapter{Last chapter}
\cleardoublepage % assure start with odd page number
\phantomsection
\addcontentsline{toc}{chapter}{List of to do's}
\listoftodos
\end{document}
此命令运行正常,生成一个列表要做的按章节组织。我尝试将其增强为列表此外部分,但改变chapter
还section
不够。
我想通过以下方式增强代码:
章节和部分列在索引中
如果章节和部分下没有“要执行的操作”,则不会打印这些章节和部分(将章节/部分行添加到目录中的命令完毕todos
应该保存在某处,并且只能在第一次出现时执行去做)
结果应该是
List of to dos (5)
1 First chapter
1.1 a
1.1 Section 1.1
1.2 b
1.2 Section 1.2
1.3 c
2 Second chapter
2.1 Section 2.1
2.1 d
2.3 Section 2.3
2.2 e
编辑1问题(2)已解决,问题中的代码已实现。开放只是增加了部分内容。