Debian Codegraph @

texmf-dist/source/latex/mversion/mVersion.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2011 by Michael Schmeing <[email protected]>
4 % -------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.2
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.2 or later is part of all distributions of LaTeX
14 % version 1999/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{mVersion.dtx}
21 %</driver>
22 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
23 %<package>\ProvidesPackage{mVersion}
24 %<*package>
25 [2013/03/11 v1.0.1 easy versioning for LaTeX]
26 %</package>
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \usepackage{mVersion}[2011/10/18]
31 \EnableCrossrefs
32 \CodelineIndex
33 \RecordChanges
34 \begin{document}
35 \DocInput{mVersion.dtx}
36 \PrintChanges
37 \PrintIndex
38 \end{document}
39 %</driver>
40 % \fi
41 %
42 % \CheckSum{0}
43 %
44 % \CharacterTable
45 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
46 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
47 % Digits \0\1\2\3\4\5\6\7\8\9
48 % Exclamation \! Double quote \" Hash (number) \#
49 % Dollar \$ Percent \% Ampersand \&
50 % Acute accent \' Left paren \( Right paren \)
51 % Asterisk \* Plus \+ Comma \,
52 % Minus \- Point \. Solidus \/
53 % Colon \: Semicolon \; Less than \<
54 % Equals \= Greater than \> Question mark \?
55 % Commercial at \@ Left bracket \[ Backslash \\
56 % Right bracket \] Circumflex \^ Underscore \_
57 % Grave accent \` Left brace \{ Vertical bar \|
58 % Right brace \} Tilde \~}
59 %
60 %
61 % \changes{v1.0}{2011/10/18}{Initial version}
62 % \changes{v1.0.1}{2013/03/11}{Typos fixed}
63 %
64 % \GetFileInfo{mVersion.dtx}
65 %
66 %
67 % \title{The \textsf{mVersion} package\thanks{This document
68 % corresponds to \textsf{mVersion}~\fileversion, dated \filedate.}}
69 % \author{Michael Schmeing \\ \texttt{[email protected]}}
70 %
71 % \maketitle
72 %
73 % \section{Introduction}
74 %
75 % The \textsf{mVersion} package is an easy way to keep track of different versions of your document. It provides a counter that can be incremented each time you compile the document. By displaying the counter on each page, (e.g. with the \textsf{hyperref}-package) you can see which of two versions is the newer one.
76 %
77 % The version number is considered to consist of two parts which are separated by a dot. The first part is a fixed string that can be set by the user with |setVersion|. The second part is the build number which can be incremented by calling |increaseBuild|. The command |version| prints the complete version number, e.g. 0.1.334 with 0.1 being the fixed version number and 334 the build number.
78 %
79 % Fixed version number and build number are automatically stored in the file \emph{version.dat} which is created by mVersion. By calling |increaseBuild| in the preamble of your document, you can increase the build number of your document each time you compile.
80 %
81 % \section{Usage}
82 %
83 % The \textsf{mVersion} package provides three commands.
84 %
85 % \DescribeMacro{version}
86 % This command prints out the version number consisting of the fixed part,
87 % followed by a dot and the build number.
88 %
89 % \DescribeMacro{setBuild}
90 % Sets the fixed part of the version number
91 %
92 % \DescribeMacro{increaseBuild}
93 % Each time |increaseBuild| is called, the build number that can be
94 % displayed with |version| is increased by one.
95 %
96 % \StopEventually{}
97 % \PrintIndex
98 % \section{Implementation}
99 %
100 % We begin with a small macro |parseline| that reads a line of the form X;Y followed by one space. It then assigns X to |versionnumber| and Y to |buildnumber|. This macro helps reading the fixed version number and the build number from the file \emph{version.dat}. Since \LaTeX\ adds an additional space to each line it reads from file, we need this macro.
101 % \begin{macrocode}
102 \def\parseline#1;#2 %this space is important
103 {
104 \def\versionnumber{#1}
105 \def\buildnumber{#2}
106 }
107 % \end{macrocode}
108 %
109 % \subsection{Things to do on startup}
110 % First, check if version file \emph{version.dat} exsists.
111 % \begin{macrocode}
112 \IfFileExists{version.dat}
113 { }
114 % \end{macrocode}
115 % If not, initialize with version number 0.0 and build number 0 and write the version file to disk. Note that the version file stores the version information in the format X;Y with X being the fixed version number and Y the build number.
116 % \begin{macrocode}
117 {
118 \newwrite\outfile
119 \immediate\openout\outfile=version.dat
120 \immediate\write\outfile{0.0;0}
121 \immediate\closeout\outfile
122 }
123 % \end{macrocode}
124 % After making sure that the version file exists, read version and build number from version file
125 % \begin{macrocode}
126 \newread\versionfile
127 \openin\versionfile=version.dat
128 \read\versionfile to \versionline
129 \closein\versionfile
130 % \end{macrocode}
131 % |versionline| now contains the version information in the X;Y--format but with an additional space following. Therefore, we let |versionline| be parsed by |pareseline|.
132 % \begin{macrocode}
133 \expandafter\parseline\versionline
134 % \end{macrocode}
135 % Finally, we initialize the build counter
136 % \begin{macrocode}
137 \newcounter{buildcounter}
138 \setcounter{buildcounter}{\buildnumber}
139 % \end{macrocode}
140 %
141 % \subsection{Command definitions}
142 %
143 % \begin{macro}{\version}
144 % Get the current version number.
145 % \begin{macrocode}
146 \newcommand{\version}{\versionnumber.\thebuildcounter}
147 % \end{macrocode}
148 % \end{macro}
149 %
150 % \begin{macro}{\setVersion}
151 % |setVersion| lets you set the fixed version number. First, write the new version number and old build number to version file
152 % \begin{macrocode}
153 \newcommand{\setVersion}[1]
154 {
155 \newwrite\outfile
156 \immediate\openout\outfile=version.dat
157 \immediate\write\outfile{#1;\thebuildcounter}
158 \immediate\closeout\outfile
159 % \end{macrocode}
160 % Now re-read version file to re-read version number (not build number)
161 % \begin{macrocode}
162 \newread\versionfile
163 \openin\versionfile=version.dat
164 \read\versionfile to \versionline
165 \expandafter\parseline\versionline
166 \closein\versionfile
167 }
168 % \end{macrocode}
169 % \end{macro}
170 %
171 % \begin{macro}{\increaseBuild}
172 %Increase build number by one and save new version and build number to version file. By calling |increaseBuild| in the preamble, the build number is increased each time the document is compiled.
173 % \begin{macrocode}
174 \newcommand{\increaseBuild}
175 {
176 % \end{macrocode}
177 %Increase build number
178 % \begin{macrocode}
179 \stepcounter{buildcounter}
180 % \end{macrocode}
181 %Save version and build number to version file
182 % \begin{macrocode}
183 \newwrite\outfile
184 \immediate\openout\outfile=version.dat
185 \immediate\write\outfile{\versionnumber;\thebuildcounter}
186 \immediate\closeout\outfile
187 }
188 % \end{macrocode}
189 % \end{macro}
190 % \Finale
191 \endinput