7

A document (typical of many) has a header which displays a timestamp in the form of a text string (“25 December 2013”). The timestamp string originates in a file "update" which is loaded with \input.

I attempted to construct a minimal working example, but the example (three files) does not work as I expected it to work.

% 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.

After much searching and reading, I still do not understand which LaTeX mechanism – such as \savebox or \renewcommand – is appropriate for this task. Also, I am confused regarding the proper location for the definitions of \timestamp and \revision – should they be defined in the class file (example.cls), in the main document file (example.tex), or in the file (update) which periodically updates the main document file? My inclination is to define as much as possible in the class file, because there are over a thousand document files.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Do us a favour and change your username to something more telling than "user1234". – Tobi Jan 3 '14 at 14:34
5

I think this does what you want. You don't need a new .cls file.

\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}

enter image description here

If the revision line that appears in the document header before the input text needs the new value of the timestamp you'll have to work a little harder - see how to make text be copied to another part of a document?

  • I thank you, kind sir. The solution you gave appears to serve my need perfectly. And I do have need for a customized .cls file, because the document is fairly complex, with several sections, a complex first-page header, and header and footer on all pages. The class defines over a thousand similar but unique documents, and each document is likely to be updated a dozen or more times. Needless to say, the alternative of manually modifying the header via cut-and-paste is daunting. – rlh Dec 26 '13 at 20:55
  • @user43157: If this solves your problem please consider marking the answer as ‘Accepted’ by clicking on the tickmark below the vote count (see How do you accept an answer?). This assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – Tobi Jan 3 '14 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.