summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/datestamp/datestamp.dtx
blob: 7e9861f42e364192c981aecd9ab52307045fc775 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
% \iffalse meta-comment
%
% File: datestamp.dtx
% ----------------------------------------------------------
% Package:     datestamp
% Version:     v0.2 (08 December, 2021)
% Author:      निरंजन
% Description: Fixed date-stamps with LuaLaTeX.
% Repository:  http://savannah.nongnu.org/projects/datestamp
% License:     GPLv3+, GFDLv1.3+
% ----------------------------------------------------------
%
% LaTeX Package datestamp v0.2
% Copyright © 2021 निरंजन
%
% This program is free software: you can redistribute it
% and/or modify it under the terms of the GNU General Public
% License as published by the Free Software Foundation,
% either version 3 of the License, or (at your option) any
% later version.
%
% This program is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU General Public License for more
% details.
%
% You should have received a copy of the GNU General Public
% License along with this program. If not, see
% <https://www.gnu.org/licenses/>.
%
% The current maintainer of this work is निरंजन.
%
% This work consists of the files datestamp.dtx
%                                 datestamp.ins
% and the derived file            datestamp.sty.
% \fi
% \iffalse
%<*internal>
\iffalse
%</internal>
%<*readme>
-----------------------------------------------------------
Package:      datestamp
Version:      v0.2(08 December, 2021)
Author:       निरंजन
Description:  Fixed date-stamps with LuaLaTeX
Repository:   http://savannah.nongnu.org/projects/datestamp
License:      GPLv3+, GFDLv1.3+
-----------------------------------------------------------
%</readme> 
%<*internal>
\fi
%</internal>
%<*driver|package>
\def\datestampname{datestamp}
\def\datestampversion{0.2}
\def\datestampdate{2021-12-08}
\def\datestampdescription{%
  Fixed date-stamps with LuaLaTeX.%
}
%</driver|package>
%<*driver>
\documentclass{l3doc}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage{fancyvrb}
\usepackage{hyperref}
\hypersetup{%
  unicode,%
  colorlinks,%
  urlcolor=blue!60!black,%
  linkcolor=blue!60!black,%
  citecolor=green!60!black,%
  pdftitle={The datestamp package},%
  pdfauthor={निरंजन},%
  pdfsubject={\datestampdescription}
}%
\usepackage{fontspec}
\newfontfamily\devanagari[%
  Script=Devanagari,%
  Scale=0.8%
]%
{Shobhika}
\newcommand\textcode[1]{\Verb|#1|}

\begin{document}
    \DocInput{\datestampname.dtx}
\end{document}
%</driver>
% \fi
% \title{The \pkg{\datestampname} package}
% \author{{\devanagari निरंजन}}
% \date
% {^^A
%   Version \datestampversion\ --- \datestampdate\\[1ex]^^A
%   {^^A
%     \small\faIcon{link}\quad
%     \url{https://ctan.org/pkg/datestamp}^^A
%   }\\^^A
%   {^^A
%     \small\faIcon{bug}\quad
%     \url{http://savannah.nongnu.org/bugs/?group=datestamp}^^A
%   }^^A
% }
%
% \maketitle
% 
% \begin{documentation}
%   \begin{abstract}
%     \href{https://tex.stackexchange.com/q/611721/174620}%
%     {This} question on SE inspired me to write a code
%     which can store and recall dates whenever needed.
%     Lua\LaTeX\ provided a smooth interface for achieving
%     this and thus this package was developed.
%   \end{abstract}
%   \section{Documentation}
%   \begin{function}{\adddatestamp}
%     \begin{syntax}
%       \cs{adddatestamp} \marg{key}
%     \end{syntax}
%     This command takes one mandatory argument which is the
%     key that we set for printing the date. The key is
%     printed in the auxiliary file with extension
%     \verb|.ds|. If in case one loses their auto-generated
%     \verb|.ds| file, they can simply write one with
%     whichever dates of their choice. e.g.\ A sample
%     \verb|.ds| file might look like the following.
% \begin{verbatim}
% firstdate = "August 21, 2021"
% seconddate = "September 21, 2021"
% thirddate = "October 22, 2021"
% \end{verbatim}
%     One can fool the program by writing a file like this
%     themselves!
%   \end{function}
%   \begin{function}{\addmonthstamp}
%     \begin{syntax}
%       \cs{addmonthstamp} \marg{key}
%     \end{syntax}
%     Similar to \cs{adddatestamp}, this command prints a
%     fixed month-stamp.
%   \end{function}
%   \begin{function}{\addyearstamp}
%     \begin{syntax}
%       \cs{addyearstamp} \marg{key}
%     \end{syntax}
%     This command prints a fixed year-stamp.
%   \end{function}
%   \vfill
%
%   \hrule
%
%   \medskip
%   {^^A
%     \setlength{\parindent}{0pt}
%     \LaTeX\ package \pkg{datestamp}
%     
%     Copyright © 2021 {\devanagari निरंजन}
%   
%     Permission is granted to copy, distribute and/or
%     modify this document under the terms of the GNU Free
%     Documentation License, Version 1.3 or any later
%     version published by the Free Software Foundation;
%     with no Invariant Sections, no Front-Cover Texts, and
%     no Back-Cover Texts. A copy of the license is included
%     in the section entitled ``GNU Free Documentation
%     License''.
%   }%
% \end{documentation}
% \newpage
% \begin{implementation}
% \section{Implementation}
% Provide package with its basic information.
%    \begin{macrocode}
%<@@=datestamp>
%<*package>
\ProvidesPackage{datestamp}[2021/12/08 v0.2
Fixed date-stamps with LuaLaTeX.]
%    \end{macrocode}
% Load package \pkg{xparse} for declaring the robust command
% \cs{luacodefordatestamp}. This is a generic \& internal
% command. We will Call \cs{directlua} \& open a file in
% append mode so that it will be created if doesn't exist \&
% just appended if exists. The following code creates a file
% with the extension \verb|.ds| \& the name of the root
% file. Note that using \verb|a+| mode also enables the
% \verb|read| mode.
%    \begin{macrocode}
\RequirePackage{xparse}
\NewDocumentCommand{\luacodefordatestamp}{ m m }{%
  \directlua{%
    dsfile = io.open("\jobname.ds", "a+")
%    \end{macrocode}
% Now we store the content of the \verb|.ds| file in a
% variable named \verb|dscontent|.
%    \begin{macrocode}
    dscontent = dsfile:read "*a"
%    \end{macrocode}
% We first check if the key used in the argument of
% \cs{adddatestamp} is already present in our aux file and
% if it is present, our code does nothing. It adds the key
% followed by the \verb|=| sign and the date to the
% \verb|.ds| file if the key is absent. We close the file
% when this job is done \& we end the if-conditional.
%    \begin{macrocode}
    if string.find(dscontent, "#1") then
    else
      dsfile:write("#1 = \string\"#2\string\"\string\n")
      io.close(dsfile)
    end
%    \end{macrocode}
% With \verb|dofile| command we execute the \verb|.ds| file
% as a Lua code. With this our keys automatically become Lua
% variables which store the dates.
%    \begin{macrocode}
    dofile("\jobname.ds")
%    \end{macrocode}
% Finally we print the date by calling the key as a Lua
% variable (which is by the way our \TeX-argument XD).
%    \begin{macrocode}
    tex.sprint(#1)
  }%
}
%    \end{macrocode}
% After creating this generic internal command, we use it
% for producing various stamps. i.e.\ date, month \& year. I
% am using the default \TeX-commands for producing them as
% these commands have great localization-support.
%    \begin{macrocode}
\NewDocumentCommand{\adddatestamp}{ m }{%
  \luacodefordatestamp{#1}{\today}%
}%
\NewDocumentCommand{\addyearstamp}{ m }{%
  \luacodefordatestamp{#1}{\the\year}%
}%
\NewDocumentCommand{\addmonthstamp}{ m }{%
  \luacodefordatestamp{#1}{\the\month}%
}%
\NewDocumentCommand{\adddaystamp}{ m }{%
  \luacodefordatestamp{#1}{\the\day}%
}%
%    \end{macrocode}
% End of the package.
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
% \newpage
% \phantomsection
% \addcontentsline{toc}{section}{GNU Free Documentation License}
% \include{gfdl-tex.tex}
% \Finale