-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoMultiColItemize.sty
64 lines (63 loc) · 2.19 KB
/
AutoMultiColItemize.sty
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% itemize in automatic multi columns
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{etoolbox,refcount}
\newcounter{countitems}
\newcounter{nextitemizecount}
\newcommand{\setupcountitems}{%
\stepcounter{nextitemizecount}%
\setcounter{countitems}{0}%
\preto\item{\stepcounter{countitems}}%
}
\makeatletter
\newcommand{\computecountitems}{%
\edef\@currentlabel{\number\c@countitems}%
\label{countitems@\number\numexpr\value{nextitemizecount}-1\relax}%
}
\newcommand{\nextitemizecount}{%
\getrefnumber{countitems@\number\c@nextitemizecount}%
}
\newcommand{\previtemizecount}{%
\getrefnumber{countitems@\number\numexpr\value{nextitemizecount}-1\relax}%
}
\makeatother
\newenvironment{AutoMultiColItemize}{%
\ifnumcomp{\nextitemizecount}{>}{3}{
\def\columnseprulecolor{\color{black}}
\setlength{\columnseprule}{0.4pt}
\begin{multicols}{2}}{}%
\setupcountitems\begin{itemize}}%
{\end{itemize}%
\unskip\computecountitems\ifnumcomp{\previtemizecount}{>}{3}{\end{multicols}}{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% enumerate in multi columns
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{countenums}
\newcounter{nextenumeratecount}
\newcommand{\setupcountenums}{%
\stepcounter{nextenumeratecount}%
\setcounter{countenums}{0}%
\preto\item{\stepcounter{countenums}}%
}
\makeatletter
\newcommand{\computecountenums}{%
\edef\@currentlabel{\number\c@countenums}%
\label{countenums@\number\numexpr\value{nextenumeratecount}-1\relax}%
}
\newcommand{\nextenumeratecount}{%
\getrefnumber{countenums@\number\c@nextenumeratecount}%
}
\newcommand{\prevenumeratecount}{%
\getrefnumber{countenums@\number\numexpr\value{nextenumeratecount}-1\relax}%
}
\makeatother
\newenvironment{AutoMultiColEnumerate}{%
\ifnumcomp{\nextenumeratecount}{>}{3}{
\def\columnseprulecolor{\color{black}}
\setlength{\columnseprule}{0.4pt}
\begin{multicols}{2}}{}%
\setupcountenums\begin{enumerate}}%
{\end{enumerate}%
\unskip\computecountenums\ifnumcomp{\prevenumeratecount}{>}{3}{\end{multicols}}{}}