-
Notifications
You must be signed in to change notification settings - Fork 2
/
grid-system.sty
91 lines (77 loc) · 2.95 KB
/
grid-system.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
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
% !TeX root=demo.tex
\ProvidesPackage{grid-system}[2014/01/16 v. 0.2.0 LaTeX Grid System]
\RequirePackage{calc}
\RequirePackage{xkeyval}
\RequirePackage{ifthen}
\RequirePackage{environ,forloop}
\newlength{\gridsystem@rowwidth}
\setlength{\gridsystem@rowwidth}{\linewidth}
\newlength{\gridsystem@cellsep}
\setlength{\gridsystem@cellsep}{1.75em}
\newcommand{\gridsystem@cellwidth}[2]{#1\linewidth/#2}
\newlength{\gridsystem@one@cellwidth}
\newcounter{gridsystem@cellinrow}
% Macros to finish cells and rows, so that the areas between cells and rows can be defined very flexibly.
\newcommand{\gridsystem@finishrow}{\bigskip}
\newcommand{\gridsystem@finishcell}{\hskip\gridsystem@cellsep}
\newcommand{\gridsystem@finishlastcell}{}
\define@key{row}{cellsep}{\setlength\gridsystem@cellsep{#1}}
\define@key{row}{rowwidth}{\setlength\gridsystem@rowwidth{#1}}
%\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1#1}
\newenvironment{row}[3][cellsep=1.75em,rowwidth=\linewidth]{%
\setkeys{row}{#1}%
\setcounter{gridsystem@cellinrow}{0}%
\noindent%
\newenvironment{cell}[1]{%
\addtocounter{gridsystem@cellinrow}{##1}%
\setlength{\gridsystem@one@cellwidth}{(\gridsystem@rowwidth-\gridsystem@cellsep*(#3-1))/#2}%
\begin{minipage}[t]{##1\gridsystem@one@cellwidth}%
}{%
\end{minipage}%
\@ignoretrue% Ignore spaces
\ifthenelse{\value{gridsystem@cellinrow}<#2}{%
\gridsystem@finishcell%
}{%
\gridsystem@finishlastcell%
}%
}%
}{
\gridsystem@finishrow%
}
\NewEnviron{Cell}[1]{%
%\global\@namedef{gridsystem@cellcontent\arabic{gridsystem@cellcount}}{\BODY}%
%\edef\@celltemp{\BODY}%
%\global\@namedef{gridsystem@cellcontent\arabic{gridsystem@cellcount}}{\@celltemp}%
\expandafter\global\expandafter\let\csname gridsystem@cellcontent\arabic{gridsystem@cellcount}\endcsname\BODY%
\global\@namedef{gridsystem@cellwidth\arabic{gridsystem@cellcount}}{#1}%
\stepcounter{gridsystem@cellcount}%
\addtocounter{gridsystem@stripecount}{#1}%
}
%%%%
%%%% equivalent of \@namedef for counters?
%%%%
\newcounter{gridsystem@cellcount}
\newcounter{gridsystem@stripecount}
\newenvironment{Row}[1][cellsep=1.75em,rowwidth=\linewidth]{%
\setkeys{row}{#1}%
\setcounter{gridsystem@cellinrow}{0}%
\setcounter{gridsystem@stripecount}{0}%
\noindent%
}{%
\setlength{\gridsystem@one@cellwidth}{(\gridsystem@rowwidth-\gridsystem@cellsep*(\value{gridsystem@cellcount}-1))/\value{gridsystem@stripecount}}%
% For each 1..gridsystem@cellcount
\forloop{gridsystem@cellinrow}{0}{\value{gridsystem@cellinrow} < \value{gridsystem@cellcount}}{%
\expandafter\begin{minipage}[t]{\dimexpr\@nameuse{gridsystem@cellwidth\arabic{gridsystem@cellinrow}}\gridsystem@one@cellwidth\relax}%
\@nameuse{gridsystem@cellcontent\arabic{gridsystem@cellinrow}}%
\end{minipage}%
\@ignoretrue% Ignore spaces
\ifthenelse{\value{gridsystem@cellinrow}<\value{gridsystem@cellcount}}{%
\gridsystem@finishcell%
}{%
\gridsystem@finishlastcell%
}%
}%
\setcounter{gridsystem@cellcount}{0}%
\setcounter{gridsystem@stripecount}{0}%
%\gridsystem@finishrow%
}