2

This question led to a new package:
datestamp

I am making a workbook, and I want it to show the last a certain page was modified.

How can I make a date stamp at the bottom of each page (f.x. "Last modified 20. August 2021"). And make it so that the datestamp shows the date for last change for that certain page.

4
  • 1
    The stamp itself aside, if you generate a stamp using something automatic like \today, the whole document gets the date stamp at compilation time (I use stamps in this manner quite frequently). If you want each page to have a unique stamp, you will have to manually enter the date at the point of each change. That may be more trouble than you are looking for. Can you give us more context on what the content is that you are hoping to datestamp (e.g., general document text or particular tables or data blocks)? Aug 23, 2021 at 12:23
  • The only way to do this automatically would be to make each entry a separate file \input to the main document then you could access the last modified file date for each section. Aug 23, 2021 at 13:21
  • Since, strictly speaking, you are not modifying the .pdf output file, but the .tex input file, questions arise: What kinds of modifications to the .tex-input file should affect date-stamps on the pages of the output file? Only changes to the text? Or also changes to the type area or font size that do not affect the wording but do affect pagination? Similar to the color stack, one would have to implement a date-stamp-stack and use it to manually record each (new) change date within the .tex input file. Then ... Aug 23, 2021 at 15:06
  • ... Then you would need some kind of label-ref mechanism synchronized with the output routine to assign page numbers to change dates and find the most recent change date for each page. Aug 23, 2021 at 15:07

2 Answers 2

2

TeX has no internal way to remember when individual pieces of a tex file were edited. David, in comments, suggested placing different pages in different files and using file-date stamps for each page as it is \input.

Here, I take a different approach. I assume (I could be wrong) that your desire is to date-stamp certain important blocks of the document, for example, each tabular is date-stamped. To that end, I create an environment stamptabular that takes as its first argument the date stamp, before absorbing the regular tabular arguments. This stamp gets displayed in the page footer (and header, if desired). After each page is shipped out, the page stamp is reset to the default text. Extending this approach to other environments is trivial...tabular was merely chosen as an example with which to work.

In addition to creating special environments that require stamping, I also provide \DateStampAdd{} to arbitrarily insert a date stamp at that point in the document. Because more than one stamp may appear per page, the stamps are accumulated for any given page (before being reset after shipout).

In the MWE:

  1. an unstamped page

  2. this page has two pagestamped entries

  3. an unstamped page

  4. Eliminate page stamps at top of page with \BottomPageStamp. Also, add one stamped environment on page.

  5. Page Stamps discontinued altogether with \StopPageStamp.

Here is the MWE. Of course, with such an approach, the burden remains on the user to edit the DateStamps as he/she edits the document.

\documentclass{article}
\usepackage{xcolor,everypage}
\AddEverypageHook{\StopPageStamp}
\newcommand\DefaultPageStamp{Date Stamps:}
\makeatletter
\def\thePageStamp{}
\def\thePageStampTOP{\thePageStamp}
\def\EmptyStyle{empty}
\def\PlainStyle{plain}
\def\PageStampColor{red}

\newcommand{\ps@pagestamp}{
  \renewcommand{\@oddhead}{\sffamily\color{\PageStampColor}%
                           \hfil\textbf{\Large\thePageStampTOP}\hfil}
  \renewcommand{\@evenhead}{\@oddhead}
  \renewcommand{\@evenfoot}{\sffamily\hfil
                            \begin{tabular}{c}
                            \textrm{\thepage}\\
                            \color{\PageStampColor}
                            \textbf{\Large\thePageStamp}
                            \end{tabular}
                            \hfil\gdef\thePageStamp{\DefaultPageStamp}}
  \renewcommand{\@oddfoot}{\@evenfoot}
}

\newcommand{\ps@emptypagestamp}{
  \renewcommand{\@oddhead}{\sffamily\color{\PageStampColor}%
                             \hfil\textbf{\Large\thePageStampTOP}\hfil}
  \renewcommand{\@evenhead}{\@oddhead}
  \renewcommand{\@evenfoot}{\sffamily\hfil
                            \begin{tabular}{c}
                            ~\\
                            \color{\PageStampColor}
                            \textbf{\Large\thePageStamp}
                            \end{tabular}
                            \hfil}
  \renewcommand{\@oddfoot}{\@evenfoot}
}
\makeatother
\newcommand\BottomPageStamp[1][\DefaultPageStamp]{%
  \PageStamp[#1]%
  \def\thePageStampTOP{}%
}

\newcommand\PageStamp[1][\DefaultPageStamp]{
  \gdef\thePageStamp{#1}
  \gdef\PlainStyle{pagestamp}
  \gdef\EmptyStyle{emptypagestamp}
  \pagestyle{\PlainStyle}
}

\newcommand\StopPageStamp[0]{
  \def\PlainStyle{plain}
  \def\EmptyStyle{empty}
  \pagestyle{\PlainStyle}
}

\newcommand\DateStampAdd[1]{%
  \expandafter\PageStamp\expandafter[\thePageStamp{}/#1/]%
}

\newenvironment{stamptabular}[1]
{\DateStampAdd{#1}\begin{tabular}}{\end{tabular}}

\PageStamp[\DefaultPageStamp]

\textheight=1in % FOR THIS MWE ONLY
\begin{document}

Page 1
\clearpage

Page 2

\begin{stamptabular}{2021-08-19}{cc}
\hline
This & is\\
my  stamped & tabular\\
\hline
\end{stamptabular}

Here I manually add an additional datestamp\DateStampAdd{2021-08-23}

\clearpage

Page 3
\clearpage

Page 4

\BottomPageStamp% IF YOU ONLY WANT STAMP AT PAGE  BOTTOM

\begin{stamptabular}{2020-05-01}{cc}
\hline
This & is\\
another  stamped & tabular\\
\hline
\end{stamptabular}

\clearpage

\StopPageStamp

Page 5

\end{document}

enter image description here


enter image description here


enter image description here


enter image description here


enter image description here

1

I wrote a LuaLaTeX-only package named datestamp for this :)

It's pretty new, so might take 2-3 days to come in the distributions. If you are impatient you can clone the git repostiory; run l3build install in the datestamp/datestamp directory. This will install the package in your local texmf.

A short example

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{datestamp}

\begin{document}
The date I write with \verb|\adddatestamp| doesn't change.

\adddatestamp{firstds}
\end{document}

Let's say your filename is random.tex. Running the above code will generate a random.ds file. Assuming you run it today; the .ds file will have the following text.

firstds = "October 22, 2021"

This is then interpreted as a lua-code which makes firstds a variable and then the value of this variable (which is the date) is printed in TeX. As long as you preserve the .ds file; your dates won't change, but let's say you lose your .ds file by mistake; there is still no need to worry. You can fool the program by writing your own .ds file and using exactly same keys in your document as argument of \adddatestamp command.

An automated example

\documentclass{article}
\usepackage{kantlipsum}
\usepackage{datestamp}
\NewDocumentCommand{\dsfoot}{ }{%
  \adddatestamp{pn\thepage}%
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\cfoot{}
\rfoot{Last modified: \dsfoot}

\begin{document}
\kant
\kant
\kant
\end{document}

If you add two more \kants on some other day, those pages will show that particular date. Your .ds file will look like the following:

pn1 = "October 22, 2021"
pn2 = "October 22, 2021"
pn3 = "October 22, 2021"
pn4 = "October 22, 2021"
pn5 = "October 22, 2021"
pn6 = "October 22, 2021"
pn7 = "October 22, 2021"

As explained earlier; if you want to have a different date on let's say page number 4, you can edit the .ds file; change the value of pn4 to, say, "December 22, 2021". From the next compile; output will show December 22, 2021 only on page 4.


Note: Please be careful while using the names of the variables. It seems like Lua doesn't like only numeric variables. I haven't dug deep; but using \thepage instead of pn\thepage throws a weird Lua error. So better have alphanumeric variables like ds1, pn1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .