
文件(許多文件中的典型)都有一個標題,該標題以文字字串的形式顯示時間戳記(「2013 年 12 月 25 日」)。時間戳字串源自於"update"
載入了\input
.
我嘗試建立一個最小的工作範例,但該範例(三個文件)無法按照我的預期工作。
% this is a listing of example.cls
\ProvidesPackage{example}
\LoadClassWithOptions{book}
\newcommand{\timestamp}[1]{#1}
\newcommand{\revision}{ \timestamp}
% this is a listing of example.tex
\documentclass[letterpaper]{example}
\begin{document}
This line represents the document header: \revision
\input{update} % update data from external file
Now the header should reflect the update: \revision
\end{document}
% this is a listing of "update"
% the date string should update the document header:
\timestamp{25 December 2013}
This line represents update text, which typically consists of dozens of lines.
經過大量搜尋和閱讀,我仍然不明白哪種 LaTeX 機制(例如\savebox
or \renewcommand
)適合這項任務。另外,我對\timestamp
和的定義的正確位置感到困惑\revision
- 它們應該在類文件 ( example.cls
)、主文檔文件 ( ) 中定義,還是在定期更新主文檔文件的example.tex
文件 ( ) 中定義?update
我傾向於在類文件中定義盡可能多的內容,因為有超過一千個文件文件。
答案1
我想這就是你想要的。您不需要新.cls
文件。
\documentclass{book}
\newcommand{\revision}{dummy value}
\newcommand{\timestamp}[1]{%
\renewcommand{\revision}{#1}
}
\begin{document}
This line represents the document header: \revision
\input{update} % update data from external file, type .tex
Now the header should reflect the update: \revision
\end{document}
如果輸入文字之前出現在文件標題中的修訂行需要時間戳記的新值,您將不得不更加努力 - 請參閱如何將文字複製到文件的另一部分?