Debian Codegraph @

texmf-dist/doc/latex/association-matrix/association-matrix.tex

raw
1 %% association-matrix.sty
2 %% Copyright 2020 Whisperity
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3c
6 % of this license or (at your option) any later version.
7 % The latest version of this license is in
8 % http://www.latex-project.org/lppl.txt
9 % and version 1.3c or later is part of all distributions of LaTeX
10 % version 2008/05/04 or later.
11 %
12 % This work has the LPPL maintenance status `maintained'.
13 %
14 % The Current Maintainer of this work is Whisperity.
15 %
16 % This work consists of the files association-matrix.sty
17 % and association-matrix.tex.
18 %
19 \documentclass{article}
20 \usepackage{association-matrix} % Own package! :3
21
22 \usepackage{etoolbox}
23 \usepackage{hyperref}
24 \hypersetup{
25 pdftitle={The 'association-matrix' Package}, % title
26 pdfauthor={Whisperity}, % author
27 pdfsubject={An easy and clear assocation matrix generator}, % subject of the document
28 pdfnewwindow=true, % links in new window
29 hidelinks, % disable link borders
30 %colorlinks=false, % false: boxed links; true: colored links
31 }
32 \usepackage{cleveref} % *MUST* be loaded *after* HyperRef.
33 \usepackage{minted}
34 \usemintedstyle{borland}
35 \setminted{autogobble}
36 \usepackage{xcolor}
37
38 \newrobustcmd{\release}[3]{%
39 \subsection{\emph{#1}: \texttt{#2} - #3}\label{release:#2}%
40 }
41
42 \newrobustcmd{\command}[3]{%
43 \paragraph{\textsf{#1}} \textbf{\color{blue} \texttt{#2}}\label{command:#1}%
44
45 #3
46 }
47
48 % Turn off the execution of \amxgenerate.
49 % This is used internally in the document to prevent code examples from firing the matrix when loaded.
50 \newrobustcmd{\amxDisable}{%
51 \let\theOldAMX\amxgenerate%
52 \def\amxgenerate{}%
53 }
54 \newrobustcmd{\amxEnable}{%
55 \let\amxgenerate\theOldAMX
56 }
57
58 % Escaped special characters for \texttt and the \write calls.
59 % (via http://tex.stackexchange.com/a/223089)
60 \def\atchar#1{}
61 \edef\atchar{\expandafter\atchar\string\@}
62 \def\bslchar#1{}
63 \edef\bslchar{\expandafter\bslchar\string\\}
64 \def\spchar#1{}
65 \edef\spchar{\expandafter\spchar\string\ }
66 \def\lbchar#1{}
67 \edef\lbchar{\expandafter\lbchar\string\{}
68 \def\rbchar#1{}
69 \edef\rbchar{\expandafter\rbchar\string\}}
70 \def\hschar#1{}
71 \edef\hschar{\expandafter\hschar\string\#}
72
73 \newwrite\tempfile
74
75 \begin{document}
76
77 \vspace*{0in}
78 \begin{center}
79 \LARGE The \textsf{association-matrix} Package \\
80 \small \rule{0in}{1em} An easy and clear association matrix generator \\
81 \large \rule{0in}{2em} Whisperity \\
82 % \\
83 \rule{0em}{2em}\amxDate \\
84 Version \amxVersion
85 \end{center}
86
87 \tableofcontents
88
89
90 \section{Introduction}\label{intro}
91 The \textsf{association-matrix} package allows the convenient creation of association matrices.
92 The package aims to automate the generation, without the user having to manually write the table's code and have to deal with the inefficiency of copy-pasting information.
93 The package's interface is simple, the user needs to define the table's contents (\Cref{define}) and then can generate the table (\Cref{tablegen}).
94
95 Note that it is important to have \emph{every} necessary row entries and column headings defined \textbf{before} the first call to a table generation, otherwise, only a partial table will be generated.
96
97 \subsection{Association matrix}\label{association-mx}
98 At the author's University, it is customary for Ph.D.\ students to write their doctoral dissertation organised into individual \emph{theses} (corresponding to chapters), and to provide a breakdown on which of their publications are ``proof'' behind the thesis (chapter).
99 Originally, the package \textsc{theses-vs-publications} had been devised, but then we turned it to a more generic solution.
100
101 Commonly, the dissertation's \emph{``Introduction''} and \emph{``Summary''} chapters will provide the full table.
102 In addition, at the end of each individual thesis chapters will provide a table with the current thesis's row in the table \emph{highlighted}.
103
104 An example usage and association matrix is provided in \Cref{example}.
105
106 \subsection{Licence}
107 Copyright \textcopyright\ 2020 Whisperity.
108 Permission is granted to copy, distribute and\slash or modify this software under the terms of the \emph{\LaTeX{} Project Public License}, version \emph{1.3c} or newer.\footnote{%
109 \url{http://www.latex-project.org/lppl}%
110 }
111
112 \subsection{Example}\label{example}
113 The definitions (\Cref{define}) should be done early in the document, but at least before the first table render (\Cref{tablegen}) call.
114
115 \immediate\openout\tempfile=assoc-mx-example.aux
116 \immediate\write\tempfile{\bslchar amxrow{association-matrix}{Association Matrices}}
117 \immediate\write\tempfile{\bslchar amxrow{latex}{\bslchar LaTeX}}
118 \immediate\write\tempfile{}
119 \makeatletter
120 \immediate\write\tempfile{\@percentchar\spchar Using the bibliography at the end of document!}
121 \makeatother
122 \immediate\write\tempfile{\bslchar amxcol{amxdoc}{\bslchar cite{associationmatrix}}}
123 \immediate\write\tempfile{\bslchar amxcol{latexdoc}{\bslchar cite{latex}}}
124 \immediate\write\tempfile{\bslchar amxcol{etoolboxdoc}{\bslchar cite{etoolbox}}}
125 \immediate\write\tempfile{}
126 \immediate\write\tempfile{\bslchar amxassociate{amxdoc}{association-matrix}}
127 \immediate\write\tempfile{\bslchar amxassociate{etoolboxdoc}{association-matrix}}
128 \immediate\write\tempfile{\bslchar amxassociate{latexdoc}{latex}}
129 \immediate\write\tempfile{\bslchar amxassociate{etoolboxdoc}{latex}}
130 \immediate\write\tempfile{}
131 \immediate\write\tempfile{\detokenize{\amxgenerate}}
132 \immediate\closeout\tempfile
133
134 \amxDisable
135 \input{assoc-mx-example.aux}
136 \amxEnable
137 \begin{figure}[H]
138 \centering
139 \inputminted{latex}{assoc-mx-example.aux}
140 \amxgenerate
141 \end{figure}
142
143 \clearpage
144 \section{Commands}\label{commands}
145 \subsection{Registering entries}\label{define}
146
147 \command{amxrow}{\bslchar amxrow\lbchar <key>\rbchar\lbchar <text>\rbchar}{%
148 Registers the row entry named \texttt{<key>} with the given \texttt{<text>}.
149 The \emph{title} of the entry is printed in the first cell of the row, \textbf{in the order of} \texttt{\bslchar amxrow} calls.
150 }
151
152 \command{amxcol}{\bslchar amxcol\lbchar <key>\rbchar\lbchar <text>\rbchar}{%
153 Registers the column named \texttt{<key>} with the given \texttt{<text>}.
154 The contents of \emph{body} is printed as the column headings of the table, \textbf{in the order of} \texttt{\bslchar amxcol} calls.
155 }
156
157 \command{amxassociate}{\bslchar amxassociate\lbchar <col-key>\rbchar\lbchar <row-key>\rbchar}{%
158 Registers the association between \texttt{<col-key>} and \texttt{<row-key>}.
159 The cells at the intersection of the row and the column will have a \textbullet{}, indicating the relevancy.
160 }
161
162 \subsection{Queries}\label{query}
163
164 \command{amxrows}{\bslchar amxrows}{%
165 Returns the number of rows defined.
166 }
167
168 \command{amxcols}{\bslchar amxcols}{%
169 Returns the number of columns defined.
170 }
171
172 \command{amxrowtext}{\bslchar amxrowtext\lbchar <key>\rbchar}{%
173 Returns the registered \emph{text} for the \textbf{row} registered with \texttt{<key>}.
174 }
175
176 \command{amxcoltext}{\bslchar amxcoltext\lbchar <key>\rbchar}{%
177 Returns the registered \emph{text} for the \textbf{column} registered with \texttt{<key>}.
178 }
179
180 \subsection{Table generator: \texttt{amxgenerate}}\label{tablegen}
181
182 \command{amxgenerate}{\bslchar amxgenerate[<row>]}{%
183 Generates the full table incorporating the previously registered data.
184 Internally, a \texttt{tabular} environment is created with the table's data generated by the package.
185 It is the user's responsibility to wrap this into a floating \texttt{table}, if they so wish.
186
187 If \texttt{[<row>]} is given a row's \emph{key}, the row for that key will be \textbf{highlighted}.
188 Highlighting is done by typesetting the row's \emph{text} in \textbf{bold face}, and changing every \textbullet{} in the \emph{other} rows to \textopenbullet{}.
189
190 \begin{figure}[H]
191 \centering
192 \amxgenerate[latex]
193 \end{figure}
194 }
195
196
197 % Let's use an example of 2×2 matrix for the customisations.
198 \newcommand{\docExampleResetTableTwoByTwo}{%
199 \amxReset%
200 \amxrow{sample}{Sample}%
201 \amxrow{simple}{Simple}%
202 \amxcol{x}{x}%
203 \amxcol{y}{y}%
204 \amxassociate{x}{sample}%
205 \amxassociate{y}{simple}%
206 }
207 \newcommand{\loadAndRenderResettingExample}[2][0]{%
208 \begin{figure}[H]
209 \centering
210 \inputminted{latex}{#2}
211
212 \docExampleResetTableTwoByTwo
213 \input{#2}
214 \amxgenerate[#1]
215 \end{figure}%
216 }
217
218 \subsection{Customisation}\label{customise}
219 All aspects on how the individual elements in the table are rendered can be customised by setting \emph{renderer} control sequences.
220
221 \makeatletter
222 \def\defaultTopCorner{\amx@Renderer@Default@TopCorner}
223 \makeatother
224 \command{amxsetTopCorner}{\bslchar amxsetTopCorner\lbchar <new-heading>\rbchar}{%
225 Sets the rendered table's top left cell value (by default, ``\emph{\defaultTopCorner}'') to the given \texttt{<new-heading>} value.
226
227 \immediate\openout\tempfile=settopcorner-example.aux
228 \immediate\write\tempfile{\bslchar amxsetTopCorner{Correlations}}
229 \immediate\closeout\tempfile
230 \loadAndRenderResettingExample{settopcorner-example.aux}
231 }
232
233 \command{amxsetColumnHeading}{\bslchar amxsetColumnHeading\lbchar<render-command>\rbchar}{%
234 Sets the rendered table's top row's cells to be rendered via passing the column heading's text (see \Cref{query}) to the given \texttt{<render-command>}.
235 This command must be a command that takes \textbf{1} argument, defined by the user earlier.
236
237 \immediate\openout\tempfile=setcolheading-example.aux
238 \immediate\write\tempfile{\bslchar newcommand{\bslchar ttColHead}[1]{\bslchar texttt{\hschar1}}}
239 \immediate\write\tempfile{\bslchar amxsetColumnHeading{\bslchar ttColHead}}
240 \immediate\closeout\tempfile
241 \loadAndRenderResettingExample{setcolheading-example.aux}
242 }
243
244 \command{amxsetRowFormat}{\bslchar amxsetRowFormat(Highlighted)\lbchar<render-command>\rbchar}{%
245 Sets the rendered table's left cells' to be rendered via passing the row's index and text (see \Cref{query}) to the given \texttt{<render-command>}.
246 This command must be a command that takes \textbf{2} arguments, defined by the user earlier.
247 The \texttt{Highlighted} version sets the renderer for the highlighted row, if highlighted rendering (see \Cref{tablegen}) is done.
248
249 \immediate\openout\tempfile=setrowformat-example.aux
250 \immediate\write\tempfile{\bslchar newcommand{\bslchar parenRow}[2]{(\hschar1) \bslchar emph{\hschar2}}}
251 \immediate\write\tempfile{\bslchar newcommand{\bslchar parenRowBl}[2]{!\hschar1! \bslchar texttt{\hschar2}}}
252 \immediate\write\tempfile{\bslchar amxsetRowFormat{\bslchar parenRow}}
253 \immediate\write\tempfile{\bslchar amxsetRowFormatHighlighted{\bslchar parenRowBl}}
254 \immediate\closeout\tempfile
255 \loadAndRenderResettingExample[simple]{setrowformat-example.aux}
256 }
257
258 \clearpage
259 \makeatletter
260 \def\defaultIndicator{\amx@Renderer@Default@Indicator}
261 \makeatother
262 \command{amxsetIndicator}{\bslchar amxsetIndicator\lbchar<indicator>\rbchar}{%
263 Sets the indicators of association in the matrix in \emph{non-highlighting} mode to the result of the \texttt{<indicator>}.
264 The default indicator is: \defaultIndicator{}.
265
266 \immediate\openout\tempfile=setindicator-example.aux
267 \immediate\write\tempfile{\bslchar amxsetIndicator{a}}
268 \immediate\closeout\tempfile
269 \loadAndRenderResettingExample{setindicator-example.aux}
270 }
271
272 \makeatletter
273 \def\defaultIndicatorHC{\amx@Renderer@Default@Indicator@Highlighted@Current}
274 \def\defaultIndicatorHO{\amx@Renderer@Default@Indicator@Highlighted@Other}
275 \makeatother
276 \command{amxsetIndicatorHighlighted}{\linebreak\bslchar amxsetIndicatorHighlighted\lbchar<hl-indicator>\rbchar\lbchar<ot-indicator>\rbchar}{%
277 Sets the indicators of association in the matrix in \emph{highlighting} mode to the result of the \texttt{<hl-indicator>} for the \textbf{highlighted row} and \texttt{<ot-indicator>} for every other row.
278 The default indicators are: \defaultIndicatorHC{} and \defaultIndicatorHO{}, respectively.
279
280 \immediate\openout\tempfile=setindicator-hl-example.aux
281 \immediate\write\tempfile{\bslchar amxsetIndicatorHighlighted{c}{o}}
282 \immediate\closeout\tempfile
283 \loadAndRenderResettingExample[simple]{setindicator-hl-example.aux}
284 }
285
286 \subsection{Multiple distinct tables: \texttt{amxReset}}
287
288 \command{amxReset}{\bslchar amxReset}{%
289 Clears \textbf{all} internal data structures and customisations for the package, allowing the user to later typeset a different, independent matrix.
290 The previously defined entries are lost, and in case the ``previous'' matrix is needed, it must be set up again with a sequence of definition commands (see \Cref{define}).
291
292 For example, putting the code in \Cref{example} and the one below into the same source file will create the smaller matrix at the second invocation of \texttt{\bslchar amxgenerate}.
293
294 \immediate\openout\tempfile=reset-example.aux
295 \immediate\write\tempfile{\bslchar amxReset}
296 \immediate\write\tempfile{\bslchar amxrow{sample}{Sample}}
297 \immediate\write\tempfile{\bslchar amxcol{x}{x}}
298 \immediate\write\tempfile{\bslchar amxassociate{x}{sample}}
299 \immediate\write\tempfile{\detokenize{\amxgenerate}}
300 \immediate\closeout\tempfile
301
302 \amxDisable
303 \input{reset-example.aux}
304 \amxEnable
305
306 \begin{figure}[H]
307 \centering
308 \inputminted{latex}{reset-example.aux}
309 \amxgenerate
310 \end{figure}
311 }
312
313 \clearpage
314 \section{Interaction \& compatibility with other packages}\label{compatibility}
315 There are several packages that interact with commands in a way that interferes with the behaviour of \texttt{association-matrix}.
316 When using such packages, \texttt{association-matrix} \textbf{must be loaded after} them.
317 During the initialisation of \texttt{association-matrix}, compatibility is ensured by rewiring some of the logic.
318
319 \begin{enumerate}
320 \item\label{compatibility:array} \texttt{array}:
321 Replaced the \texttt{tabular} environment's logic (used by \hyperref[command:amxgenerate]{\mintinline{latex}{\amxgenerate}}) by eagerly attempting to consume the number of columns to create, which was previously created by a macro locally.
322 The issue was fixed in \hyperref[release:v1.1]{release 1.1} by making sure that in presence of the \texttt{array} package, our package does the right thing.
323 \end{enumerate}
324
325 \section{Development}
326 The development of \textsf{association-matrix} is done on GitHub: \url{http://github.com/whisperity/association-matrix}.
327 Please report issues and submit patches here.
328
329 Note that this document acts as a \textbf{test file} to the package, not only a user-facing documentation.
330 Any new command or change should be supplemented with appropriate documentation, and the check of the rendered examples.
331 If there is a discrepancy or regression in the looks of \emph{this document} that is not explained by the changes, it should be investigated!
332
333 \section{Changelog}\label{changelog}
334 \release{2022/10/29}{v1.1}{Compatibility with \texttt{array}}
335 \begin{itemize}
336 \item Fixed error message ``\texttt{Illegal pream-token: \`{}c' used}'' emitted by the \texttt{array} package by injecting a compatibility shim.
337 (See \cref{compatibility:array} in \Cref{compatibility}.)
338 \end{itemize}
339
340 \release{2020/10/25}{v1.0}{Initial release}
341 \begin{itemize}
342 \item Basic functionality of defining entries, rendering tables, and customising the renderers are implemented.
343 \end{itemize}
344
345 \begin{thebibliography}{3}
346 \bibitem{associationmatrix}
347 Whisperity. \textit{The \textsf{association-matrix} Package -- An easy and clear association matrix generator}.
348 Online, \url{http://ctan.org/pkg/association-matrix} (accessed 2020/10/25), 2020.
349
350 \bibitem{latex}
351 Leslie B.\ Lamport, Donald E.\ Knuth et al.
352 \textit{\LaTeX{} -- A document preparation system}.
353 Online, \url{http://latex-project.org/} (accessed 2020/10/25), 1984.
354
355 \bibitem{etoolbox}
356 Philipp Lehman, Joseph Wright.
357 \textit{The \textsf{etoolbox} Package -- An e-\TeX{} Toolbox for Class and Package Authors}
358 Online, \url{http://ctan.org/pkg/etoolbox} (accessed 2020/10/25), 2007.
359 \end{thebibliography}
360
361 \end{document}