summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/changelog/changelog.sty
blob: 491e78d754804fb65fc203138338e2460564c6d6 (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
\ProvidesPackage{changelog}[2019/07/06 2.1.0 Typesetting changelogs]
% Description: Provides the changelog environment for typesetting changelogs
% License:     LPPL 1.3c
% Homepage:    https://github.com/9999years/latex-changelog
%              https://ctan.org/pkg/changelog
% Maintainer:  Rebecca Turner <637275@gmail.com>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Rebecca Turner <637275@gmail.com>.
%
% This work consists of the files changelog.sty and changelog.tex.

\RequirePackage{xparse}
\RequirePackage{xkeyval}
\RequirePackage{translations}

% See https://github.com/olivierlacan/keep-a-changelog/issues/195
% for a discussion about the term yanked

% Fallback translations will be used if there is no translation for
% the current document language
\DeclareTranslationFallback{changelog-Added}{Added}
\DeclareTranslationFallback{changelog-Changed}{Changed}
\DeclareTranslationFallback{changelog-Deprecated}{Deprecated}
\DeclareTranslationFallback{changelog-Removed}{Removed}
\DeclareTranslationFallback{changelog-Fixed}{Fixed}
\DeclareTranslationFallback{changelog-Security}{Security}
\DeclareTranslationFallback{changelog-Miscellaneous}{Miscellaneous}
\DeclareTranslationFallback{changelog-Unreleased}{Unreleased}
\DeclareTranslationFallback{changelog-Yanked}{YANKED}
% English translations
\DeclareTranslation{English}{changelog-Added}{Added}
\DeclareTranslation{English}{changelog-Changed}{Changed}
\DeclareTranslation{English}{changelog-Deprecated}{Deprecated}
\DeclareTranslation{English}{changelog-Removed}{Removed}
\DeclareTranslation{English}{changelog-Fixed}{Fixed}
\DeclareTranslation{English}{changelog-Security}{Security}
\DeclareTranslation{English}{changelog-Miscellaneous}{Miscellaneous}
\DeclareTranslation{English}{changelog-Unreleased}{Unreleased}
\DeclareTranslation{English}{changelog-Yanked}{YANKED}
% German translations
% Alternative german translations as comment at the end of the line
\DeclareTranslation{German}{changelog-Added}{Hinzugef\"{u}gt}% Neu
\DeclareTranslation{German}{changelog-Changed}{Ge\"{a}ndert}
\DeclareTranslation{German}{changelog-Deprecated}{Überholt}% Veraltet
\DeclareTranslation{German}{changelog-Removed}{Entfernt}
\DeclareTranslation{German}{changelog-Fixed}{Behoben}% Fehlerbehebung
\DeclareTranslation{German}{changelog-Security}{Sicherheit}
\DeclareTranslation{German}{changelog-Miscellaneous}{Verschiedenes}
\DeclareTranslation{German}{changelog-Unreleased}{Unver\"{o}ffentlicht}
\DeclareTranslation{German}{changelog-Yanked}{Zur{\"u}ckgezogen}

\newif\ifchangelog@versionfirst
\newcommand{\changelog@item}[1]{%
	\noindent
	\ifchangelog@versionfirst
		\changelog@versionfirstfalse
	\else
		\end{changelogitemize}
	\fi
	\textbf{#1}%
	\begin{changelogitemize}%
}

\newcommand{\changelogyanked}{\fbox{\textbf{\GetTranslation{changelog-Yanked}}}}

\newcommand{\changelog@sectioncmds}{
	\newcommand{\added}     {\changelog@item{\GetTranslation{changelog-Added}}}
	\newcommand{\changed}   {\changelog@item{\GetTranslation{changelog-Changed}}}
	\newcommand{\deprecated}{\changelog@item{\GetTranslation{changelog-Deprecated}}}
	\newcommand{\removed}   {\changelog@item{\GetTranslation{changelog-Removed}}}
	\newcommand{\fixed}     {\changelog@item{\GetTranslation{changelog-Fixed}}}
	\newcommand{\security}  {\changelog@item{\GetTranslation{changelog-Security}}}
	\newcommand{\misc}      {\changelog@item{\GetTranslation{changelog-Miscellaneous}}}
}

\define@cmdkeys{version}{author, version, date, changes}
\define@key{version}{v}{\def\cmdKV@version@version{#1}}
\define@boolkey{version}{yanked}[true]{}
\define@boolkey{version}{simple}[true]{}
\define@boolkey{version}{short}[true]{}

\define@cmdkeys{changelog}{sectioncmd, title, label}
\define@boolkey{changelog}{section}[true]{}
\presetkeys{changelog}{sectioncmd=\section, title=Changelog,
	label=sec:changelog, section}{}

\newenvironment{changelogdescription}
	{\begin{description}}
	{\end{description}}
\newenvironment{changelogitemize}
	{\begin{itemize}}
	{\end{itemize}}

\newcommand{\changelog@section@maybe}{%
	\ifKV@changelog@section
		\expandafter\cmdKV@changelog@sectioncmd{\cmdKV@changelog@title}%
		\expandafter\label{\cmdKV@changelog@label}%
	\fi
}

\newcommand{\changelog@shortversion@definedate}{%
	\@ifundefined{cmdKV@version@version}{
		\@ifundefined{cmdKV@version@date}{
			\newcommand{\cmdKV@version@version}{\GetTranslation{changelog-Unreleased}}
			\let\cmdKV@version@date\today
		}{%
			\let\cmdKV@version@version\cmdKV@version@date
			\let\cmdKV@version@date\undefined
		}%
	}{}%
}

\newcommand{\changelog@yanked@maybe}
	{\ifKV@version@yanked\ \changelogyanked\fi}

\newcommand{\changelog@shortversion@item}
	{\cmdKV@version@version
	\changelog@yanked@maybe}


\newcommand{\changelog@shortversion@authordate}{%
	\@ifundefined{cmdKV@version@author}{}{\cmdKV@version@author}
	\@ifundefined{cmdKV@version@date}{%
		% if both undefined, add a linebreak
		\@ifundefined{cmdKV@version@author}{\hspace{0pt}}{}%
	}{(\cmdKV@version@date)}%
}

\newcommand{\changelog@version@pre}{%
	\par
	\changelog@versionfirsttrue
	\changelog@sectioncmds
	\ifKV@version@simple
		\begin{changelogitemize}
	\fi
}
\newcommand{\changelog@version@post}{%
	\ifchangelog@versionfirst
		\ifKV@version@simple
		\else
			\PackageError{changelog}{Something's wrong in version environment;
			perhaps a missing \protect\added, \protect\changed,
			\protect\deprecated, \protect\removed, \protect\fixed,
			\protect\security, or \protect\misc}{A version environment needs to
			introduce its \protect\item-ized lists with one of the provided
			section commands; maybe you meant to use the [simple] option?}
		\fi
	\fi
	\end{changelogitemize}%
}

\newif\ifchangelog@hadversion
\NewDocumentEnvironment{changelog}{o}
	{\global\changelog@hadversionfalse
	\IfValueT{#1}{\setkeys{changelog, version}{#1}}%
	\changelog@section@maybe
	%\today
	% version environment; wraps a list
	\NewDocumentEnvironment{version}{ O{} }%
		{\setkeys{version}{##1}%
		\@shortversion
		\ifKV@version@short
		\else
			\changelog@version@pre
		\fi}
		{\ifKV@version@short
		\else
			\changelog@version@post
		\fi}%

	% doesn't set keys so this can share code with the version
	% environment
	\NewDocumentCommand{\@shortversion}{}{%
		\changelog@shortversion@definedate
		\global\changelog@hadversiontrue
		\item[\changelog@shortversion@item]%
		\changelog@shortversion@authordate
		\ifKV@version@short
			\ ---
			\@ifundefined{cmdKV@version@changes}{}{\cmdKV@version@changes}%
		\fi
	}%

	% short version; "like" a 1-bullet list
	% extra braces keep command definitions local
	\NewDocumentCommand{\shortversion}{m}{{%
		\setkeys{version}{##1, short}%
		\@shortversion
	}}%
	\begin{changelogdescription}}
	{\ifchangelog@hadversion
	\else
		\PackageError{changelog}{No versions in changelog environment body}{A
		changelog environment must have at least one version or shortversion in
		it.}%
	\fi\end{changelogdescription}}