我正在創建一個會議紀要類,因為我有一些非常具體的要求 -minutes.sty
似乎並不能滿足我的所有要求。
取得了一些不錯的進展,但我完全陷入了以下困境:我希望能夠在會議中遇到行動項目時定義它們,並讓它們自動按人排序。
如果我能寫出這樣的東西那就太好了:
\action{Peter}{next week}{Take out the garbage}
\action{Mike}{tomorrow}{Prepare a presentation for the thing}
\action{Peter}{2015-02-28}{Clean the kitchen}
\action{Peter}{tomorrow}{Water the plants}
\action{Mike}{yesterday}{Cleanse the bathroom}
並將其全部顯示在description
這樣的環境中:
\begin{description}
\item[Peter] \hfill \\
Water the plants \hfill \textbf{tomorrow} \\
Take out the garbage \hfill \textbf{next week} \\
Clean the kitchen \hfill \textbf{2015-02-28} \\
\item[Mike] \hfill \\
Prepare a presentation for the thing \hfill \textbf{tomorrow} \\
Cleanse the bathroom \hfill \textbf{yesterday} \\
\end{description}
這些任務不必按照每個人的截止日期進行排序,儘管我也希望得到這方面的指導。按人分組更為關鍵。
我顯然需要一個資料結構,但我不知道從哪裡開始或它們如何運作。有沒有像數組、列表、哈希圖或任何可以輕鬆排序的東西?
我也不受任何特定編譯器的束縛。如果有一些功能,比如說luatex
可以讓這種方式變得更容易,那麼這就不成問題了。
有人能指出我正確的方向嗎?有可能嗎?
答案1
這是一個起點:
\documentclass{article}
\usepackage{multido}
\newcounter{personcntr}% Keep track of number of persons
\makeatletter
\newcommand{\action}[3]{% \action{<name>}{<time>}{<duty>}
\@ifundefined{person@#1}{% If person doesn't exist
\stepcounter{personcntr}% Next person
\expandafter\xdef\csname person@#1\endcsname{1}% One time/duty
\expandafter\xdef\csname person@bynumber@\thepersoncntr\endcsname{#1}% Number person
}{% Person already exists
\expandafter\xdef\csname person@#1\endcsname{%
\number\numexpr\csname person@#1\endcsname+1}% Step number of time/duty
}%
\expandafter\xdef\csname person@#1@\csname person@#1\endcsname @time\endcsname{#2}% Store time
\expandafter\xdef\csname person@#1@\csname person@#1\endcsname @duty\endcsname{#3}% Store duty
\ignorespaces
}
\gdef\newpar{\par}% \multido doesn't enjoy \par
\newcommand\printactions{% Print actions
\def\descriptionBODY{}% Empty descriptionBODY
{\let\item\relax% Prevent expansion of \item
\let\newpar\relax% Prevent expansion of \newpar
\multido{\iPerson=1+1}{\value{personcntr}}{% Step through all persons
% Extract person name
\expandafter\xdef\expandafter\thisperson\expandafter{\csname person@bynumber@\iPerson\endcsname}%
\protected@xdef\descriptionBODY{%
\descriptionBODY%
\item[\thisperson] \leavevmode\newpar}% Add person name to descriptionBODY
% Extract person number
\expandafter\xdef\expandafter\thispersonnum\expandafter{\csname person@\thisperson\endcsname}%
\multido{\iDuty=1+1}{\thispersonnum}{%
\protected@xdef\descriptionBODY{%
\descriptionBODY%
\csname person@\thisperson @\iDuty @duty\endcsname% Add person duty to descriptionBODY
\hfill
{\bfseries\csname person@\thisperson @\iDuty @time\endcsname}% Add person time to descriptionBODY
\newpar
}%
}%
}%
}%
% Print person time/duty
\begin{description}
\descriptionBODY
\end{description}
}
\makeatother
\begin{document}
\action{Peter}{next week}{Take out the garbage}
\action{Mike}{tomorrow}{Prepare a presentation for the thing}
\action{Peter}{2015-02-28}{Clean the kitchen}
\action{Peter}{tomorrow}{Water the plants}
\action{Mike}{yesterday}{Cleanse the bathroom}
\printactions
\end{document}