diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/grid-system/grid-system.sty |
Initial commit
Diffstat (limited to 'macros/latex/contrib/grid-system/grid-system.sty')
-rw-r--r-- | macros/latex/contrib/grid-system/grid-system.sty | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/macros/latex/contrib/grid-system/grid-system.sty b/macros/latex/contrib/grid-system/grid-system.sty new file mode 100644 index 0000000000..1ae9e686aa --- /dev/null +++ b/macros/latex/contrib/grid-system/grid-system.sty @@ -0,0 +1,87 @@ +% !TeX root=demo.tex +\ProvidesPackage{grid-system}[2014/02/16 v. 0.3.0 LaTeX Grid System] + +\RequirePackage{calc} +\RequirePackage{xkeyval} +\RequirePackage{ifthen} +\RequirePackage{environ,forloop} + +\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}% +\noindent% +\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% +} + +\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]{% +\setkeys{row}{#1}% +\setcounter{gridsystem@cellinrow}{0}% +\setcounter{gridsystem@stripecount}{0}% +\noindent% +}{% +\setlength{\gridsystem@one@cellwidth}{(\linewidth-\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% +} |