summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/changelog/changelog.sty
blob: 53e7299bb90907571c520b661e065b02443a2326 (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
\ProvidesPackage{changelog}[2018-12-28 1.0.0 Typesetting changelogs]
% Description: Provides the changelog environment for typesetting changelogs
% License:     GPL-3.0
% Homepage:    https://github.com/9999years/latex-changelog
%              https://ctan.org/pkg/changelog
% Maintainer:  Rebecca Turner <637275@gmail.com>

\newif\ifchangelog@color\changelog@colorfalse
\DeclareOption{color}{\changelog@colortrue}
\ProcessOptions

\ifchangelog@color
	\RequirePackage{xcolor}

	\colorlet{ChangelogAdded}     {green}
	\colorlet{ChangelogChanged}   {blue}
	\colorlet{ChangelogDeprecated}{orange}
	\colorlet{ChangelogRemoved}   {red}
	\colorlet{ChangelogFixed}     {cyan}
	\colorlet{ChangelogSecurity}  {magenta}
	\colorlet{ChangelogMiscellaneous}{.}

	\newcommand{\changelog@yanked@pre}{\color{ChangelogSecurity}}
	% parameter = item type (Added, Changed, etc.)
	\newcommand{\changelog@item@preitem}[1]{\color{Changelog#1}}
	\newcommand{\changelog@item@postitem}{\hspace{0pt}}
\else
	\newcommand{\changelog@yanked@pre}{}
	\newcommand{\changelog@item@preitem}[1]{}
	\newcommand{\changelog@item@postitem}{}
\fi

\newif\ifchangelog@versionfirst
\newcommand{\changelog@item@pre}{%
	\ifchangelog@versionfirst
		\changelog@versionfirstfalse
	\else
		\end{changelogitemize}
	\fi
}

\newcommand{\changelog@item}[1]{%
	\noindent
	\changelog@item@pre
	{\changelog@item@preitem{#1}\textbf{#1}}\changelog@item@postitem
	\begin{changelogitemize}%
}

\newcommand{\changelogyanked}{{\changelog@yanked@pre\fbox{\textbf{YANKED}}}}

\newcommand{\changelog@sectioncmds}{
	\newcommand{\added}     {\changelog@item{Added}}
	\newcommand{\changed}   {\changelog@item{Changed}}
	\newcommand{\deprecated}{\changelog@item{Deprecated}}
	\newcommand{\removed}   {\changelog@item{Removed}}
	\newcommand{\fixed}     {\changelog@item{Fixed}}
	\newcommand{\security}  {\changelog@item{Security}}
	\newcommand{\misc}      {\changelog@item{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@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}{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}{\end{changelogitemize}}

\NewDocumentEnvironment{changelog}{o}
	{\IfValueT{#1}{\setkeys{changelog, version}{#1}}%
	\changelog@section@maybe
	%\today
	% version environment; wraps a list
	\NewDocumentEnvironment{version}{ O{} }
		{\setkeys{version}{##1}%
		\@shortversion
		\changelog@version@pre}
		{\changelog@version@post}%

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

	% short version; "like" a 1-bullet list
	% extra braces keep command definitions local
	\NewDocumentCommand{\shortversion}{m}{{
		\setkeys{version}{##1}%
		\@shortversion
	}}
	\begin{changelogdescription}}
	{\end{changelogdescription}}