summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gfdl/gfdl.dtx
blob: 464ba10f80ef4a9c6fe6e2292f592330cbc552d9 (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
% \iffalse meta-comment
% 
% File: gfdl.dtx
% -------------------------------------------------------------
% Package:      gfdl
% Version:      v0.1 (January 1, 2023)
% Author:       निरंजन
% Description:  For using GFDL in LaTeX.
% Repository:   https://puszcza.gnu.org.ua/projects/gfdl-tex
% License:      GPLv3+, GFDLv1.3+
% -------------------------------------------------------------
% 
% The LaTeX package gfdl v0.1
% Copyright © 2022, 2023 निरंजन
% 
% 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/>.
% \fi
% \iffalse
%<*internal>
\iffalse
%</internal>
%<*readme>
-------------------------------------------------------------
Package:      gfdl
Version:      v0.1 (January 1, 2023)
Author:       निरंजन
Description:  For using GFDL in LaTeX.
Repository:   https://puszcza.gnu.org.ua/projects/gfdl-tex
License:      GPLv3+, GFDLv1.3+
-------------------------------------------------------------
%</readme>
%<*internal>
\fi
%</internal>
%<*driver>
\documentclass{l3doc}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage{gfdl}
\usepackage{fontspec}
\usepackage{hyperref,hyperxmp}
\colorlet{myblue}{blue!60!black}
\colorlet{myred}{red!60!black}
\colorlet{mygreen}{green!60!black}
\hypersetup{%
  unicode,%
  colorlinks,%
  urlcolor      = {myblue},%
  linkcolor     = {myred},%
  citecolor     = {mygreen},%
  pdftitle      = {The gfdl package},%
  pdfauthor     = {निरंजन},%
  pdfsubject    = {For using GFDL in LaTeX.},%
  pdfcreator    = {निरंजन},%
  pdfkeywords   = {%
    GFDL, LaTeX, FSF, Licensing, Documentation%
  },%
  pdfcopyright  = {%
    The LaTeX package gfdl\textLF
    Copyright © 2022, 2023 निरंजन\textLF
    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”.%
  },%
  pdflicenseurl = {%
    https://www.gnu.org/licenses/fdl-1.3.txt%
  }%
}%
\usepackage{cleveref}
\newfontfamily\devanagari[%
  Script        = {Devanagari},%
  Renderer      = {Harfbuzz},%
  Scale         = {0.8}%
]%
{Shobhika}
\NewDocumentEnvironment{dedication}{ }{%
  % Based on egreg's answer:
  % https://tex.stackexchange.com/a/102849
  \clearpage           % for a new page.
  \thispagestyle{empty}% no header and footer.
  \vspace*{\stretch{1}}% some space at the top. 
  \itshape             % to get the text in italics.
  \raggedleft          % flush to the right margin.
}{%
  \par                 % end the paragraph
  \vspace{\stretch{3}}%% space at bottom is three times that
  \clearpage          %% at the top finish off the page.
}
\NewCommandCopy\oldamp\&
\renewcommand*{\&}{\textit{\oldamp}}
\gfdlcopyrightdescription{The \LaTeX\ package \pkg{gfdl}}
\gfdlcopyrightholders{\texorpdfstring{{\devanagari निरंजन}}{निरंजन}}
\gfdlcopyrightableyears{2022, 2023}

\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
% \title{The \pkg{gfdl} package}
% \author{^^A
%   {^^A
%     \devanagari
%     निरंजन^^A
%   }^^A
%   \thanks{^^A
%     \href{mailto:hi.niranjan@pm.me}^^A
%     {\texttt{hi.niranjan@pm.me}}^^A
%   }^^A
% }
% \date{^^A
%   Version 0.1^^A
%   ---^^A
%   January 1, 2023\\[1ex]^^A
%   {^^A
%     \small\faIcon{link}\quad
%     \url{https://ctan.org/pkg/gfdl}^^A
%   }\\^^A
%   {^^A
%     \small\faIcon{bug}\quad
%     \url{https://puszcza.gnu.org.ua/bugs/?group=gfdl-tex}^^A
%   }^^A
% }
% 
% \maketitle
% 
% \begin{documentation}
% \begin{abstract}
%   The GFDL is a popular license used for programming
%   manuals, documentations \& various other textual works
%   too, but using this license with \LaTeX\ isn't very
%   convenient. This package aims to help users in easily
%   using the license without violating any rules of the
%   license. With a handful of commands, users can rest
%   assured that their document will be perfectly licensed
%   under GFDL.
% \end{abstract}
% 
% \tableofcontents
% 
% \begin{dedication}
%   Dedicated to the FSF \& it's continuous fight for
%   the freedom of software\dots
% \end{dedication}
% 
% \section*{Acknowledgment}
% 
% I acknowledge my friend Sahil Patel for reviewing the
% output of this package \& suggesting some corrections.
% I would also like to thank Karl Berry for pointing out
% some critical issues in my package \& suggesting
% alternative ways of dealing with them. This package
% modifies \& uses a few \LaTeX-files provided on the
% web-pages of respective versions of GFDL\footnote{^^A
%   GFDLv1.3:
%   \texttt{^^A
%     \url{https://www.gnu.org/licenses/fdl-1.3.tex}^^A
%   }.\\^^A
%   GFDLv1.2:
%   \texttt{^^A
%     \url{https://www.gnu.org/licenses/fdl-1.2.tex}^^A
%   }.\\^^A
%   GFDLv1.1:
%   \texttt{^^A
%     \url{https://www.gnu.org/licenses/fdl-1.1.tex}^^A
%   }.\\^^A
% } which are unlicensed \& their authors are unknown, but
% with a few typographic modifications I have used them in
% the package. I would like to thank FSF/GNU-hackers for
% providing a basic skeleton of the \LaTeX-files which I
% could modify.
% 
% \section{Documentation}
% 
% This section describes all the macros \& parameters that
% the package provides.
% 
% \subsection{Macros}
% 
% \begin{function}{^^A
%   \gfdlcopyrightdescription,^^A
%   \gfdlcopyrightableyears,^^A
%   \gfdlcopyrightholders
% }
% \begin{syntax}
%   \cs{gfdlcopyrightdescription}\marg{project-description}
%   \cs{gfdlcopyrightableyears}\marg{copyright-able years}
%   \cs{gfdlcopyrighthoders}\marg{copyright-holders}
% \end{syntax}
%   The names of these macros are pretty self-explanatory.
%   These macros store the information which is then printed
%   automatically at necessary places. Only if one has
%   loaded the |manual| option (documented in \cref{opts});
%   they will have to use the macros following this one to
%   print the notice \& the license-text.
% \end{function}
% 
% \begin{function}{\printgfdlnotice}
%   This text prints the copyright-notice. \LaTeX's
%   float-mechanism is used for printing it. It is printed
%   on the first page of the document with default
%   settings. With option |manual| user is free to print it
%   anywhere, but not printing it will produce an error.
% \end{function}
% 
% \begin{function}{\printgfdltext}
%   This text prints the entire license text. In default
%   settings this command is run after the last page of the
%   document. With option |manual|, the user is free to use
%   it anywhere, but not using it will produce an error.
% \end{function}
% 
% \subsection{Options}
% \label{opts}
% 
% \begin{function}{manual}
%   By default the package prints the copyright-notice along
%   with the license-text of GFDL in the document by
%   default. The former is printed at the bottom of the
%   first page whereas the latter is printed just after the
%   last page. If anyone wants to suppress this behavior \&
%   print both of these things anywhere in the document with
%   \cs{printgfdlnotice} \& \cs{printgfdltext} as documented
%   earlier.
% \end{function}
% 
% \subsubsection{Legacy support}
% 
% The following options are just for legacy support \&
% should be avoided for newer works. It is advised to use
% these options only when the document demands certain old
% conventions which are obsolete these days.
% 
% \begin{function}{(C)}
%   The \textcopyright\ symbol was at times written as (C)
%   \& if someone needs to use this style, then they can use
%   this package-option. The package essentially prints this
%   symbol at two places. One in the actual PDF text \& one
%   in it's metadata. At both of these places users will see
%   the change if this option is used. By default this
%   option is inactive.
% \end{function}
% 
% \begin{function}{version}
% \begin{syntax}
%   |version|=\marg{version-number}\hfill ^^A
%   |1.1|, |1.2| \textit{or} \textcolor{myred}{|1.3|}
% \end{syntax}
%   1.3 is the current version of GFDL, but there were two
%   old versions before it (i.e., 1.2 \& 1.1). By default
%   the latest version is used, but with this package
%   option, users can select previous versions too. It is
%   important to note that as of now this option does
%   \emph{not} allow any other value than |1.1|, |1.2| \&
%   \textcolor{myred}{|1.3|}.
%   
%   If a newer version is released by the FSF, the default
%   behavior of the package will most likely change to
%   produce the latest version of GFDL at that time. In that
%   case recompiling an old document with the new version of
%   this package will break your documents, but as a
%   developer I find that incompatibility reasonable \&
%   desirable, because I believe using the newer versions of
%   this license will only help the cause for which hackers
%   are fighting.
% \end{function}
% \end{documentation}
% 
% \begin{implementation}
% \section{Implementation}
% 
% Provide package with its basic information.
% 
%    \begin{macrocode}
%<*package>
\ProvidesPackage{gfdl}[2023/01/01 v0.1
For using the GFDL in LaTeX.]
%    \end{macrocode}
% 
% Load necessary packages.
% 
%    \begin{macrocode}
\RequirePackage{float}
\RequirePackage{expkv-def,expkv-opt}
%    \end{macrocode}
% 
% Define conditionals which we will be using in the package
% \& set some initial values for them.
% 
% The package issues a warning if copyright-holders aren't
% declared \& it doesn't print the GFDL-notice in this case,
% because a copyright-notice without copyright-holders makes
% no sense. The following conditional is at work for this.
% 
%    \begin{macrocode}
\newif\ifgfdl@copyrightholdersgiven
\gfdl@copyrightholdersgivenfalse
%    \end{macrocode}
% 
% With the following code we first define various internal
% conditionals which we require. We also set their initial
% values here.
% 
%    \begin{macrocode}
\newif\ifgfdl@copyrightableyearsgiven
\gfdl@copyrightableyearsgivenfalse
\newif\ifgfdl@copyrightedmaterialdesc
\gfdl@copyrightedmaterialdescfalse
\newif\ifgfdl@licensetextnotprinted
\gfdl@licensetextnotprintedtrue
\newif\ifgfdl@noticenotprinted
\gfdl@noticenotprintedtrue
%    \end{macrocode}
% 
% Define package options with \pkg{expkv}.
% 
%    \begin{macrocode}
\ekvdefinekeys{gfdl}{
%    \end{macrocode}
% 
% \begin{macro}{manual}
%   
%   The |invbool| type is used to define package option
%   |manual|\footnote{Read the documentation of \pkg{expkv}
%     for explanation.}. We define the conditional
%   |\ifgfdl@printgfdl| with it.
%     
%    \begin{macrocode}
  invbool     manual     = {\ifgfdl@printgfdl},
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{(C)}
%   
%   The following code defines the package option |(C)|
%   which defines an internally used conditional
%   |\ifgfdl@bracketedcopyright|. The default value of this
%   conditional is false.
%     
%    \begin{macrocode}
  bool        (C)        = {\ifgfdl@bracketedcopyright},
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{version}
%   
%   The following code develops the option |version| which
%   takes three options seen in the documentation. By using
%   the |initial| key-type, we set the initial value of this
%   option to |1.3|.
%   
%    \begin{macrocode}
  choice      version    = {%
    1.1                  = {\def\gfdl@version{1p1}},%
    1.2                  = {\def\gfdl@version{1p2}},%
    1.3                  = {\def\gfdl@version{1p3}}%
  },
  initial     version    = {1.3}
}
%    \end{macrocode}
% \end{macro}
% 
% After developing all the options, we set process them with
% the following code.
% 
%    \begin{macrocode}
\ekvoProcessLocalOptions{gfdl}
%    \end{macrocode}
% 
% We have used the |bool| type from \pkg{expkv} for
% developing the package option |(C)|. It defines the
% conditional |\ifgfdl@bracketedcopyright| which is by
% default false. We use an internal macro, i.e.,
% |\gfdl@copyrightsymbol| for printing the copyright symbol
% with the following code. We |\let| it be |\textcopyright|
% when the aforementioned conditional is false \& it is
% defined as |(C)| when the conditional is true (i.e., when
% the option is explicitly used by the user).
% 
%    \begin{macrocode}
\ifgfdl@bracketedcopyright
  \def\gfdl@copyrightsymbol{(C)}%
\else
  \let\gfdl@copyrightsymbol\textcopyright
\fi
%    \end{macrocode}
% 
% \begin{macro}{\gfdlcopyrightdescription}
%   The following |\NewDocumentCommand| is used to develop
%   this command.
%    \begin{macrocode}
\NewDocumentCommand{ \gfdlcopyrightdescription }{ m }{%
  \def\@copyrightedmaterialdesc{#1}%
  \gfdl@copyrightedmaterialdesctrue
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\gfdlcopyrightableyears}
%   For this command we have the following code.
%    \begin{macrocode}
\NewDocumentCommand{ \gfdlcopyrightableyears }{ m }{%
  \def\@copyrightableyears{#1}%
  \gfdl@copyrightableyearsgiventrue
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\gfdlcopyrightholders}
%   And lastly, we have this command coded as follows.
%    \begin{macrocode}
\NewDocumentCommand{ \gfdlcopyrightholders }{ m }{%
  \def\@copyrightholders{#1}%
  \gfdl@copyrightholdersgiventrue
}
%    \end{macrocode}
% \end{macro}
% We issue a warning when copyright-able years are not
% given. The following code generates the warning. We define
% the internal macro containing the copyright-able years as
% |??| in bold font here itself.
%    \begin{macrocode}
\AddToHook{begindocument/before}{%
  \ifgfdl@copyrightableyearsgiven
  \else
    \def\@copyrightableyears{\textbf{??}}%
    \PackageWarningNoLine{gfdl}{%
      Copyright-able years not given. I can't print the
      \MessageBreak
      copyright notice without them. To give me this
      \MessageBreak
      information use the \string\gfdlcopyrightableyears\space
      command.\MessageBreak Using `??' as a placeholder%
    }%
  \fi
%    \end{macrocode}
% The following code is used to check if user has given
% information about copyright-holders. If not, then we issue
% a warning with this code \& again define the internal
% macro containing this information as bold |??|.
%    \begin{macrocode}
  \ifgfdl@copyrightholdersgiven
  \else
    \def\@copyrightholders{\textbf{??}}%
    \PackageWarningNoLine{gfdl}{%
      Copyright-holders not given. I can't print the
      \MessageBreak
      copyright notice without them. To give me this
      \MessageBreak
      information use the \string\gfdlcopyrightholders\space
      command.\MessageBreak Using `??' as a placeholder%
    }%
  \fi
%    \end{macrocode}
% 
% With default settings of this package, \pkg{hyperref},
% \pkg{csquotes} \& \pkg{hyperxmp} are loaded, but to avoid
% potential conflicts, we load them conditionally. With the
% following code this is achieved.
% 
%    \begin{macrocode}
  \@ifpackageloaded{csquotes}{}{%
    \RequirePackage{csquotes}%
  }%
  \@ifpackageloaded{hyperref}{}{%
    \RequirePackage{hyperref}%
  }%
  \@ifpackageloaded{hyperxmp}{}{%
    \RequirePackage{hyperxmp}%
  }%
%    \end{macrocode}
% 
% For setting the metadata we use the following code.
% 
%    \begin{macrocode}
  \hypersetup{%
    pdfcopyright  = {%
      \ifgfdl@copyrightedmaterialdesc
        \@copyrightedmaterialdesc
        \textLF
      \fi
      Copyright
      \gfdl@copyrightsymbol\
      \@copyrightableyears\
      \@copyrightholders\textLF
      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”.%
    },%
    pdflicenseurl = {%
      https://www.gnu.org/licenses/fdl-1.3.txt%
    }%
  }%
}
%    \end{macrocode}
% 
% Printing the text automatically at the bottom of the first
% page is achieved with the help of a float. It is developed
% using package \pkg{float} for the following commands.
% 
%    \begin{macrocode}
\newfloat{gfdl@float}{b}{delme}
%    \end{macrocode}
% 
% \begin{macro}{\printgfdlnotice}
%   This command is developed using the following code.
%    \begin{macrocode}
\NewDocumentCommand{ \printgfdlnotice }{  }{%
  \begin{gfdl@float}[b!]
    \hrule\medskip
    \ifgfdl@copyrightedmaterialdesc
      \@copyrightedmaterialdesc\par
    \fi
    Copyright
    \gfdl@copyrightsymbol\
    \@copyrightableyears\
    \@copyrightholders
    
    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 \enquote{%
      GNU Free Documentation License%
    }.%
  \end{gfdl@float}%
  \gfdl@noticenotprintedfalse
}
%    \end{macrocode}
% \end{macro}
% 
% We use |\printgfdlnotice| at the first page of the
% document with the following code.
% 
%    \begin{macrocode}
\AddToHook{begindocument/end}{%
  \ifgfdl@printgfdl
    \printgfdlnotice
  \fi
}
%    \end{macrocode}
% 
% \begin{macro}{\printgfdltext}
%   
% The following code is used to define this command.
% 
%    \begin{macrocode}
\NewDocumentCommand{ \printgfdltext }{  }{%
  \input{gfdl-tex-\gfdl@version.tex}%
  \gfdl@licensetextnotprintedfalse
}
%    \end{macrocode}
% \end{macro}
% 
% In default settings the entire license text is printed
% with the following code.
% 
%    \begin{macrocode}
\AddToHook{enddocument}{%
  \ifgfdl@printgfdl
    \newpage
    \phantomsection
    \addcontentsline{toc}{section}{%
      GNU Free Documentation License%
    }%
    \printgfdltext
  \fi
  \ifgfdl@noticenotprinted
    \PackageError{gfdl}{%
      You didn't print the copyright notice%
    }{%
      You are in the `manual' mode of the GFDL package and
      hence you\MessageBreak are supposed to print the
      copyright notice at a suitable place\MessageBreak of
      your choice, but you haven't printed it at all. This
      violates\MessageBreak the requirement of the GFDL. To
      print it use:\MessageBreak
      \space\space\string\printgfdlnotice.%
    }%
  \fi
  \ifgfdl@licensetextnotprinted
    \PackageError{gfdl}{%
      You didn't print the license text%
    }%
    {%
      You are in the `manual' mode of the GFDL package and hence you%
      \MessageBreak
      are supposed to print the full license text at a suitable place%
      \MessageBreak
      of your choice, but you haven't printed it at all. This violates%
      \MessageBreak
      the requirement of the GFDL. To print it use:%
      \MessageBreak
      \space\space\string\printgfdltext.%
    }%
  \fi
}
%    \end{macrocode}
% 
% This is the end of the package.
% 
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
% \Finale