![補助ファイル内の文字列を使用してヘッダーを更新するにはどうすればよいですか?](https://rvso.com/image/281466/%E8%A3%9C%E5%8A%A9%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%86%85%E3%81%AE%E6%96%87%E5%AD%97%E5%88%97%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%83%98%E3%83%83%E3%83%80%E3%83%BC%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
ドキュメント (多くの場合に共通) には、テキスト文字列の形式でタイムスタンプを表示するヘッダーがあります (「2013 年 12 月 25 日」)。タイムスタンプ文字列は、"update"
で読み込まれたファイルに由来します\input
。
最小限の動作例を作成しようとしましたが、例 (3 つのファイル) は期待どおりに動作しません。
% 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
この\renewcommand
タスクに適しているのかわかりません。また、\timestamp
およびの定義の適切な場所についても混乱しています。これらは、\revision
クラス ファイル ( example.cls
)、メイン ドキュメント ファイル ( example.tex
)、またはメイン ドキュメント ファイルを定期的に更新するファイル ( update
) のどれで定義すればよいのでしょうか。ドキュメント ファイルが 1,000 個以上あるため、できるだけクラス ファイルで定義する方がよいでしょう。
答え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}
入力テキストの前の文書ヘッダーに表示されるリビジョン行にタイムスタンプの新しい値が必要な場合は、もう少し作業が必要になります。テキストをドキュメントの別の部分にコピーするにはどうすればよいですか?