I need to automatically include a build number in PDF which increases automatically when it is complied again.
E.g.
Version 1.0.1 for the first build.
Then after the second build, it should be
1.0.2
Do you have any idea to do this?
I need to automatically include a build number in PDF which increases automatically when it is complied again.
E.g.
Version 1.0.1 for the first build.
Then after the second build, it should be
1.0.2
Do you have any idea to do this?
This should do:
\documentclass[twoside]{article}
\usepackage{kantlipsum}
\AtBeginDocument{
\ifdefined\buildcount\else\gdef\buildcount{0}\fi
\xdef\buildcount{\the\numexpr\buildcount+1\relax}
\pagestyle{myheadings}
\markboth{}{Build No. 1.0.\buildcount}
}
\makeatletter
\AtEndDocument{
\write\@mainaux{
\string\gdef\string\buildcount{\buildcount}
}
}
\makeatother
\begin{document}
\kant[1-20]
\end{document}
The *.aux file may never be deleted. Otherwise the information gets lost.
Here's another possibility:
\documentclass{minimal}
\makeatletter
\def\set@docident{%
\begingroup
% yes, a big \ifcase would be more straightforward;
% no, that wouldn't be any fun at all
% (also it ends up looking messy and even tricksier).
\def\@step##1##2\@nil{\advance\@tempcnta##1 \def\@tempa{##2}}
\def\@tempa{{31}{28}{31}{30}{31}{30}{31}{31}{30}{31}{30}{31}}%
\@tempcnta=\day % day of month
\@tempcntb=\month % month of year (unit-offset)
\loop
\advance\@tempcntb-1
\ifnum \@tempcntb>0
\expandafter\@step\@tempa\@nil
\repeat
\@tempcntb=\year % yes, do calculate leap years
\divide\@tempcntb 4 \multiply\@tempcntb 4
\ifnum\@tempcntb=\year
\ifnum\month>2 % but let's not worry about century years (slack...)
\advance\@tempcnta 1
\fi
\fi
\xdef\docident{%
\the\@tempcnta % day-of-year
-\the\time} % minutes since midnight
\endgroup
}
\set@docident
\makeatother
\begin{document}
The docident is \docident.
\end{document}
This sets a \docident macro which produces a string which increases monotonically, and which doesn't depend on any stored state.
I use this to reassure me that a document – in my case a printed exam paper – is the same version, when it's handed out to students, as it was when I printed off the canonical version at the end of proofing. It's not bulletproof, but since it's sensitive to the time at which the LaTeX run was done, it provides a little more assurance than a VCS revision number alone.
It's actually an obfuscated date-time, with the same good and bad properties.
And yes, this is rather self-indulgently more complicated than it absolutely needs to be; but yes, even so, it will indeed give the wrong day-of-year in March–December 2400.
A simpler version, but equivalent, would be
\def\set@docident{%
\@tempcnta=\month
\multiply\@tempcnta 12
\advance\@tempcnta\day
\multiply\@tempcnta 1440
\advance\@tempcnta\time
\xdef\docident{\the\@tempcnta}}
CTRL+S... – Tobias Kienzler Dec 11 '15 at 14:26gitcommit reference. For example, it is unrelated to the developmental state of the document, and cannot be used to repeat that state. Would you care to add some clarification to the question? – Brent.Longborough Dec 15 '15 at 10:43