summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/datestamp/datestamp.dtx
blob: 39494d88d9bb3868bb31d980143069bdc5cb6724 (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
% \iffalse meta-comment
%
% File: datestamp.dtx
% ----------------------------------------------------
% Package:      datestamp
% Version:      v0.1 (22 October, 2021)
% Author:       निरंजन
% Description:  Fixed date-stamps with LuaLaTeX.
% Repository:   https://gitlab.com/niruvt/datestamp
% License:      GPLv3+, GFDLv1.3+
% ----------------------------------------------------
%
% LaTeX Package datestamp v0.1
% © 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.1 (22 October, 2021)
Author:       निरंजन
Description:  Fixed date-stamps with LuaLaTeX
Repository:   https://gitlab.com/niruvt/datestamp
License:      GPLv3+, GFDLv1.3+
----------------------------------------------------------
%</readme> 
%<*internal>
\fi
%</internal>
%<*driver|package>
\def\datestampname{datestamp}
\def\datestampversion{0.1}
\def\datestampdate{2021-10-22}
\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
% {^^A
% Version \datestampversion\ --- \datestampdate\\[1ex]^^A
% {^^A
% \small\faIcon{link}\quad
% \url{https://ctan.org/pkg/datestamp}^^A 
% }\\^^A
% {^^A
% \small\faIcon{gitlab}\quad
% \url{https://gitlab.com/niruvt/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}
%
%   \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}
%   \vfill
%   {^^A
%     \setlength{\parindent}{0pt}
%     \LaTeX\ package \pkg{datestamp}
%     
%     © 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/10/22 v0.1
Fixed date-stamps with LuaLaTeX.]
%    \end{macrocode}
% Load package \pkg{xparse} for declaring the robust command
% \cs{adddatestamp}. Call \cs{directlua} \& open a file in
% append mode so that it will be created if doesn't exist
% \& only appended if exists. The following code creates a
% file with 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{\adddatestamp}{ 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. Note
% that Lua itself is writing some Lua-code\footnote{The
% output of this process produces the actual syntax of Lua.}
% ;-)
%    \begin{macrocode}
    if string.find(dscontent, "#1") then
    else
      dsfile:write("#1 = \string\"\today\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 dates by calling the key as a Lua
% variable.
%    \begin{macrocode}
    tex.sprint(#1)
  }
}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
% \newpage
% \addcontentsline{toc}{section}{GNU Free Documentation License}
% \include{gfdl-tex.tex}
% \Finale