summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/grid-system/grid-system.sty
blob: d880fd72430ce4f9312b8ba7a06826d282be7dd3 (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
% !TeX root=demo.tex
\ProvidesPackage{grid-system}[2013/11/04 v. 0.1 LaTeX Grid System]

\RequirePackage{calc}
\RequirePackage{xkeyval}
\RequirePackage{ifthen}

\newcommand{\gridsystem@cellwidth}[2]{#1\linewidth/#2}

\newlength{\gridsystem@cellsep}
\setlength{\gridsystem@cellsep}{1.75em}

\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}}

%\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1#1}

\newenvironment{row}[3][cellsep=1.75em]{
	\setkeys{row}{#1}%
	\setcounter{gridsystem@cellinrow}{0}
	\newenvironment{cell}[1]{%
		\addtocounter{gridsystem@cellinrow}{##1}%
		\setlength{\gridsystem@one@cellwidth}{(\linewidth-\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%
}