如何建立一個計數命令(例如 TODO)以在清單中使用?

如何建立一個計數命令(例如 TODO)以在清單中使用?

藉口:我知道諸如todonotestodo、 和 之類的軟體包fixme,但這更多的是學習 LaTeX 程式設計的任務。因此,不鼓勵使用從 CTAN 下載的其他軟體包。還想避免使用額外的 *.sty 檔案。

如何在主 *.tex 中建立一個命令,以便稍後在清單中顯示計數項目?例如:

Text before\todo[optional caption]{my text here}. 
Some other text in the document\todo{another todo but without caption}.

待辦事項註解將在內嵌文字中著色、添加前綴或以其他方式標記。然後,呼叫將在文件中\listoftodos建立 s 列表,並產生一個與 類似但獨立的(超連結)列表,其中當且僅當存在時,其中的內容才會被替換為 in ,頁碼位於右側。該列表僅需要單一深度。\todo\tableofcontents{}[]

正在查看該todonotes包的源代碼,但無法理解它的意義。據我所知,此任務需要定義兩個新命令,將文字儲存在待辦事項清單中,處理可選參數,最後hyperref在(另一個)目錄中使用待辦事項的參考清單。該清單將寫入 *.aux 檔案。

獎金:

  • 在方程式或節標題中使用的安全性,在註釋中使用格式或方程式的安全性

  • 如何新增選項?內聯文字的簡單顯示或隱藏選項(同時仍顯示在 中\listoftodos)會很好。

  • 這個方法可以推廣到其他項目嗎?\myitem, \listofmyitems, \otheritems, \listofotheritems?

附錄:是否有任何 (La)TeX 程式設計的線上進階指南?這對於未來的任何創業都會有幫助。

答案1

初步版本,無選項鍵

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{etoolbox}%
\usepackage{blindtext}% Just as text filler
\usepackage{hyperref}
\makeatletter
\def\todolist{}

\newcounter{todolistcounter}

\newcommand{\ToDo}{%
  \@ifnextchar[{\todoopt}{\todonoopt}%
}%

\newcommand{\todonoopt}[1]{%
  \refstepcounter{todolistcounter}
  % \addcontentsline{todo}{section}{\thetodolistcounter~#1} % No contents line
  \listgadd{\todolist}{#1}%
   #1%
   %      \colorbox{green}{\thetodolistcounter~#1}
}

\newcommand{\todoopt}[2][]{%
  \refstepcounter{todolistcounter}
  \addcontentsline{todo}{section}{\thetodolistcounter~#1}
  \listgadd{\todolist}{#2}%
   #2%
   %      \colorbox{green}{\thetodolistcounter~#2}
}%



\newcommand{\listoftodos}{%
  \section{List of Todos}
  \@starttoc{todo}
  \clearpage
}%

% inline display (as a enumerate) list 
\newcommand{\InTextListOfToDos}{%
\begin{enumerate}%
  \renewcommand*{\do}[1]{%
  \item ##1%
  }
  \dolistloop{\todolist}%
\end{enumerate}%
}


\makeatother

\begin{document}
\listoftodos
\ToDo{first} \ToDo{We}

\blindtext[5] \ToDo[should not]{should} \blindtext[10]\ToDo{start from scratch}
\ToDo{\begin{equation}
    E = mc^2%
    \end{equation}%
}

\blindtext

\section{The ToDos}

\section{A heading with a ToDo \protect\ToDo{Something}}


\InTextListOfToDos


\end{document}

相關內容