| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: datestamp.dtx |
| 4 |
% ---------------------------------------------------------- |
| 5 |
% Package: datestamp |
| 6 |
% Version: v0.3 (14 December, 2021) |
| 7 |
% Author: निरंजन |
| 8 |
% Description: Fixed date-stamps with LuaLaTeX. |
| 9 |
% Repository: http://puszcza.gnu.org.ua/projects/datestamp |
| 10 |
% License: GPLv3+, GFDLv1.3+ |
| 11 |
% ---------------------------------------------------------- |
| 12 |
% |
| 13 |
% LaTeX Package datestamp v0.3 |
| 14 |
% Copyright © 2021 निरंजन |
| 15 |
% |
| 16 |
% This program is free software: you can redistribute it |
| 17 |
% and/or modify it under the terms of the GNU General Public |
| 18 |
% License as published by the Free Software Foundation, |
| 19 |
% either version 3 of the License, or (at your option) any |
| 20 |
% later version. |
| 21 |
% |
| 22 |
% This program is distributed in the hope that it will be |
| 23 |
% useful, but WITHOUT ANY WARRANTY; without even the implied |
| 24 |
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 25 |
% PURPOSE. See the GNU General Public License for more |
| 26 |
% details. |
| 27 |
% |
| 28 |
% You should have received a copy of the GNU General Public |
| 29 |
% License along with this program. If not, see |
| 30 |
% <https://www.gnu.org/licenses/>. |
| 31 |
% |
| 32 |
% The current maintainer of this work is निरंजन. |
| 33 |
% |
| 34 |
% This work consists of the files datestamp.dtx |
| 35 |
% datestamp.ins |
| 36 |
% and the derived file datestamp.sty. |
| 37 |
% \fi |
| 38 |
% \iffalse |
| 39 |
%<*internal> |
| 40 |
\iffalse |
| 41 |
%</internal> |
| 42 |
%<*readme> |
| 43 |
----------------------------------------------------------- |
| 44 |
Package: datestamp |
| 45 |
Version: v0.3 (14 December, 2021) |
| 46 |
Author: निरंजन |
| 47 |
Description: Fixed date-stamps with LuaLaTeX |
| 48 |
Repository: http://puszcza.gnu.org.ua/projects/datestamp |
| 49 |
License: GPLv3+, GFDLv1.3+ |
| 50 |
----------------------------------------------------------- |
| 51 |
%</readme> |
| 52 |
%<*internal> |
| 53 |
\fi |
| 54 |
%</internal> |
| 55 |
%<*driver|package> |
| 56 |
\def\datestampname{datestamp} |
| 57 |
\def\datestampversion{0.3} |
| 58 |
\def\datestampdate{2021-12-14} |
| 59 |
\def\datestampdescription{% |
| 60 |
Fixed date-stamps with LuaLaTeX.% |
| 61 |
} |
| 62 |
%</driver|package> |
| 63 |
%<*driver> |
| 64 |
\documentclass{l3doc} |
| 65 |
\usepackage{xcolor} |
| 66 |
\usepackage{fontawesome5} |
| 67 |
\usepackage{fancyvrb} |
| 68 |
\usepackage{hyperref} |
| 69 |
\hypersetup{% |
| 70 |
unicode,% |
| 71 |
colorlinks,% |
| 72 |
urlcolor=blue!60!black,% |
| 73 |
linkcolor=blue!60!black,% |
| 74 |
citecolor=green!60!black,% |
| 75 |
pdftitle={The datestamp package},% |
| 76 |
pdfauthor={निरंजन},% |
| 77 |
pdfsubject={\datestampdescription} |
| 78 |
}% |
| 79 |
\usepackage{fontspec} |
| 80 |
\newfontfamily\devanagari[% |
| 81 |
Script=Devanagari,% |
| 82 |
Scale=0.8% |
| 83 |
]% |
| 84 |
{Shobhika} |
| 85 |
\newcommand\textcode[1]{\Verb|#1|} |
| 86 |
|
| 87 |
\begin{document} |
| 88 |
\DocInput{\datestampname.dtx} |
| 89 |
\end{document} |
| 90 |
%</driver> |
| 91 |
% \fi |
| 92 |
% \title{The \pkg{\datestampname} package} |
| 93 |
% \author{{\devanagari निरंजन}} |
| 94 |
% \date |
| 95 |
% {^^A |
| 96 |
% Version \datestampversion\ --- \datestampdate\\[1ex]^^A |
| 97 |
% {^^A |
| 98 |
% \small\faIcon{link}\quad |
| 99 |
% \url{https://ctan.org/pkg/datestamp}^^A |
| 100 |
% }\\^^A |
| 101 |
% {^^A |
| 102 |
% \small\faIcon{bug}\quad |
| 103 |
% \url{http://puszcza.gnu.org/bugs/?group=datestamp}^^A |
| 104 |
% }^^A |
| 105 |
% } |
| 106 |
% |
| 107 |
% \maketitle |
| 108 |
% |
| 109 |
% \begin{documentation} |
| 110 |
% \begin{abstract} |
| 111 |
% \href{https://tex.stackexchange.com/q/611721/174620}% |
| 112 |
% {This} question on SE inspired me to write a code |
| 113 |
% which can store and recall dates whenever needed. |
| 114 |
% Lua\LaTeX\ provided a smooth interface for achieving |
| 115 |
% this and thus this package was developed. |
| 116 |
% \end{abstract} |
| 117 |
% \section{Documentation} |
| 118 |
% \begin{function}{\adddatestamp} |
| 119 |
% \begin{syntax} |
| 120 |
% \cs{adddatestamp} \marg{key} |
| 121 |
% \end{syntax} |
| 122 |
% This command takes one mandatory argument which is the |
| 123 |
% key that we set for printing the date. The key is |
| 124 |
% printed in the auxiliary file with extension |
| 125 |
% \verb|.ds|. If in case one loses their auto-generated |
| 126 |
% \verb|.ds| file, they can simply write one with |
| 127 |
% whichever dates of their choice. e.g.\ A sample |
| 128 |
% \verb|.ds| file might look like the following. |
| 129 |
% \begin{verbatim} |
| 130 |
% firstdate = "August 21, 2021" |
| 131 |
% seconddate = "September 21, 2021" |
| 132 |
% thirddate = "October 22, 2021" |
| 133 |
% \end{verbatim} |
| 134 |
% One can fool the program by writing a file like this |
| 135 |
% themselves! |
| 136 |
% \end{function} |
| 137 |
% \begin{function}{\addmonthstamp} |
| 138 |
% \begin{syntax} |
| 139 |
% \cs{addmonthstamp} \marg{key} |
| 140 |
% \end{syntax} |
| 141 |
% Similar to \cs{adddatestamp}, this command prints a |
| 142 |
% fixed month-stamp. |
| 143 |
% \end{function} |
| 144 |
% \begin{function}{\addyearstamp} |
| 145 |
% \begin{syntax} |
| 146 |
% \cs{addyearstamp} \marg{key} |
| 147 |
% \end{syntax} |
| 148 |
% This command prints a fixed year-stamp. |
| 149 |
% \end{function} |
| 150 |
% \vfill |
| 151 |
% |
| 152 |
% \hrule |
| 153 |
% |
| 154 |
% \medskip |
| 155 |
% {^^A |
| 156 |
% \setlength{\parindent}{0pt} |
| 157 |
% \LaTeX\ package \pkg{datestamp} |
| 158 |
% |
| 159 |
% Copyright © 2021 {\devanagari निरंजन} |
| 160 |
% |
| 161 |
% Permission is granted to copy, distribute and/or |
| 162 |
% modify this document under the terms of the GNU Free |
| 163 |
% Documentation License, Version 1.3 or any later |
| 164 |
% version published by the Free Software Foundation; |
| 165 |
% with no Invariant Sections, no Front-Cover Texts, and |
| 166 |
% no Back-Cover Texts. A copy of the license is included |
| 167 |
% in the section entitled ``GNU Free Documentation |
| 168 |
% License''. |
| 169 |
% }% |
| 170 |
% \end{documentation} |
| 171 |
% \newpage |
| 172 |
% \begin{implementation} |
| 173 |
% \section{Implementation} |
| 174 |
% Provide package with its basic information. |
| 175 |
% \begin{macrocode} |
| 176 |
%<@@=datestamp> |
| 177 |
%<*package> |
| 178 |
\ProvidesPackage{datestamp}[2021/12/14 v0.3 |
| 179 |
Fixed date-stamps with LuaLaTeX.] |
| 180 |
% \end{macrocode} |
| 181 |
% Load package \pkg{xparse} for declaring the robust command |
| 182 |
% \cs{luacodefordatestamp}. This is a generic \& internal |
| 183 |
% command. We will Call \cs{directlua} \& open a file in |
| 184 |
% append mode so that it will be created if doesn't exist \& |
| 185 |
% just appended if exists. The following code creates a file |
| 186 |
% with the extension \verb|.ds| \& the name of the root |
| 187 |
% file. Note that using \verb|a+| mode also enables the |
| 188 |
% \verb|read| mode. |
| 189 |
% \begin{macrocode} |
| 190 |
\RequirePackage{xparse} |
| 191 |
\NewDocumentCommand{\luacodefordatestamp}{ m m }{% |
| 192 |
\directlua{% |
| 193 |
dsfile = io.open("\jobname.ds", "a+") |
| 194 |
% \end{macrocode} |
| 195 |
% Now we store the content of the \verb|.ds| file in a |
| 196 |
% variable named \verb|dscontent|. |
| 197 |
% \begin{macrocode} |
| 198 |
dscontent = dsfile:read "*a" |
| 199 |
% \end{macrocode} |
| 200 |
% We first check if the key used in the argument of |
| 201 |
% \cs{adddatestamp} is already present in our aux file and |
| 202 |
% if it is present, our code does nothing. It adds the key |
| 203 |
% followed by the \verb|=| sign and the date to the |
| 204 |
% \verb|.ds| file if the key is absent. We close the file |
| 205 |
% when this job is done \& we end the if-conditional. |
| 206 |
% \begin{macrocode} |
| 207 |
if string.find(dscontent, "#1") then |
| 208 |
else |
| 209 |
dsfile:write("#1 = \string\"#2\string\"\string\n") |
| 210 |
io.close(dsfile) |
| 211 |
end |
| 212 |
% \end{macrocode} |
| 213 |
% With \verb|dofile| command we execute the \verb|.ds| file |
| 214 |
% as a Lua code. With this our keys automatically become Lua |
| 215 |
% variables which store the dates. |
| 216 |
% \begin{macrocode} |
| 217 |
dofile("\jobname.ds") |
| 218 |
% \end{macrocode} |
| 219 |
% Finally we print the date by calling the key as a Lua |
| 220 |
% variable (which is by the way our \TeX-argument XD). |
| 221 |
% \begin{macrocode} |
| 222 |
tex.sprint(#1) |
| 223 |
}% |
| 224 |
} |
| 225 |
% \end{macrocode} |
| 226 |
% After creating this generic internal command, we use it |
| 227 |
% for producing various stamps. i.e.\ date, month \& year. I |
| 228 |
% am using the default \TeX-commands for producing them as |
| 229 |
% these commands have great localization-support. |
| 230 |
% \begin{macrocode} |
| 231 |
\NewDocumentCommand{\adddatestamp}{ m }{% |
| 232 |
\luacodefordatestamp{#1}{\today}% |
| 233 |
}% |
| 234 |
\NewDocumentCommand{\addyearstamp}{ m }{% |
| 235 |
\luacodefordatestamp{#1}{\the\year}% |
| 236 |
}% |
| 237 |
\NewDocumentCommand{\addmonthstamp}{ m }{% |
| 238 |
\luacodefordatestamp{#1}{\the\month}% |
| 239 |
}% |
| 240 |
\NewDocumentCommand{\adddaystamp}{ m }{% |
| 241 |
\luacodefordatestamp{#1}{\the\day}% |
| 242 |
}% |
| 243 |
% \end{macrocode} |
| 244 |
% End of the package. |
| 245 |
% \begin{macrocode} |
| 246 |
%</package> |
| 247 |
% \end{macrocode} |
| 248 |
% \end{implementation} |
| 249 |
% \newpage |
| 250 |
% \phantomsection |
| 251 |
% \addcontentsline{toc}{section}{GNU Free Documentation License} |
| 252 |
% \include{gfdl-tex.tex} |
| 253 |
% \Finale |