aboutsummaryrefslogtreecommitdiff
path: root/comparison.sty
blob: d10f95fce57938f01dea0b7d86bdc87dfac51db4 (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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{comparison}[2024-01-19 package comparison]

\RequirePackage{booktabs}
\RequirePackage{etoolbox}
\RequirePackage{tabularx}
\RequirePackage{environ}
\RequirePackage{enumitem}

% comparison environment, usage:
%
% \begin{comparison}
% 	\pro{reason why thing is good}
% 	\pro{...}
% 	\con{reason why thing is bad}
% 	\con{...}
% \end{comparison}
%
% output:
%
% Pros (2)                      Cons (2)
% ----------------------------------------------------------
%  - reason why thing is good    - reason why thing is bad
%  - ...                         - ...
%

\newcounter{pro-count}
\newcounter{pro-index}
\newcounter{con-count}
\newcounter{con-index}
\newcounter{cmp-count}
\newcounter{cmp-index}
\NewEnviron{comparison}{%
	\par%
	\setcounter{pro-count}{0}%
	\newcommand{\pro}[1]{%
		\stepcounter{pro-count}%
		\csdef{pro-\the\value{pro-count}}{##1}%
	}%
	\setcounter{con-count}{0}%
	\newcommand{\con}[1]{%
		\stepcounter{con-count}%
		\csdef{con-\the\value{con-count}}{##1}%
	}%
	\BODY%
	\def\spacing{3mm}%
	\newcommand{\halfbox}[1]{%
		\begin{minipage}[t]{\dimexpr(\linewidth - \spacing) / 2\relax}%
			##1%
		\end{minipage}%
	}%
	\begin{minipage}{\linewidth}%
		\halfbox{\strut\centering\textsc{Benefits}~(\the\value{pro-count})\strut}%
		\hfill%
		\halfbox{\strut\centering\textsc{Drawbacks}~(\the\value{con-count})\strut}%
		\par%
		\vspace*{\dimexpr-\parskip-0.5\baselineskip\relax}%
		\noindent\rule{\linewidth}{0.66pt}\par%
		\vspace*{\dimexpr-\parskip\relax}%
		\halfbox{%
			\begin{itemize}[leftmargin=5mm]%
				\setcounter{pro-index}{0}%
				\whileboolexpr{test{\ifnumcomp{\value{pro-index}}{<}{\value{pro-count}}}}{%
					\stepcounter{pro-index}%
					\item \csuse{pro-\the\value{pro-index}}%
				}%
			\end{itemize}%
		}\hfill\halfbox{%
			\begin{itemize}[leftmargin=5mm]%
				\setcounter{con-index}{0}%
				\whileboolexpr{test{\ifnumcomp{\value{con-index}}{<}{\value{con-count}}}}{%
					\stepcounter{con-index}%
					\item \csuse{con-\the\value{con-index}}%
				}%
			\end{itemize}%
		}%
	\end{minipage}%
	\par%
}