%%
%% This is file `elzcards.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% elzcards.dtx  (with options: `class')
%% 
%% Copyright 2015 Emilio Lazo Zaia <emiliolazozaia@gmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%  http://www.latex-project.org/lppl/lppl-1-3c.{html|txt|tex|pdf}
%% and the latest version of this license is in
%%  http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008/05/04 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Emilio Lazo Zaia.
%% 
%% This work consists of the files README and elzcards.dtx with
%% its derived files elzcards.ins, elzcards.cls and
%% elzcards-example.tex.
%% 
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{elzcards}
[2015/03/05 v1.00 ELZ cards]
\RequirePackage{calc}
\RequirePackage{xparse}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}

\newif\if@elzc@puntos
\newif\if@elzc@lineas
\newif\if@elzc@guias
\newif\if@elzc@fichaconreverso
\newif\if@elzc@reversoficha

\newlength{\elzc@TarjXdim}
\newlength{\elzc@TarjYdim}
\newlength{\elzc@TempLen}

\newcounter{elzc@TarjXdim}
\newcounter{elzc@TarjYdim}
\newcounter{elzc@PapelX}
\newcounter{elzc@PapelY}
\newcounter{elzc@NumX}
\newcounter{elzc@NumY}
\newcounter{elzc@ContX}
\newcounter{elzc@ContY}
\newcounter{elzc@PosX}
\newcounter{elzc@PosY}
\newcounter{elzc@RestoX}
\newcounter{elzc@XInicial}
\newcounter{elzc@Punto}
\newcounter{elzc@Arista}
\newcounter{elzc@Fichas}
\newcounter{elzc@TempFichaActual}
\newcounter{elzc@TempFichaActualII}

\setlength{\parindent}{0pt}
\setlength{\unitlength}{1sp}
\pagestyle{empty}

\newlength{\elzc@DefTPXdim}
\newlength{\elzc@DefTPYdim}
\newlength{\elzc@DefFichaXdim}
\newlength{\elzc@DefFichaYdim}
\newlength{\elzc@DefLinea}
\newcounter{elzc@DefArista}
\newcounter{elzc@DefPunto}

\setlength{\elzc@DefTPXdim}{3.5in}
\setlength{\elzc@DefTPYdim}{2in}
\setlength{\elzc@DefFichaXdim}{5in}
\setlength{\elzc@DefFichaYdim}{3in}
\setlength{\elzc@DefLinea}{0.1mm}
\setcounter{elzc@DefArista}{186468}
\setcounter{elzc@DefPunto}{65536}

\newcommand{\elzc@Cuadricula}[1]{%
 \setcounter{elzc@TarjXdim}{\elzc@TarjXdim}%
 \setcounter{elzc@TarjYdim}{\elzc@TarjYdim}%
 \setcounter{elzc@PapelX}{\textwidth}%
 \setcounter{elzc@PapelY}{\textheight}%
 \setcounter{elzc@NumX}{\value{elzc@PapelX} / \value{elzc@TarjXdim}}%
 \setcounter{elzc@NumY}{\value{elzc@PapelY} / \value{elzc@TarjYdim}}%
 \setcounter{elzc@ContX}{-1}%
 \setcounter{elzc@ContY}{-1}%
 \setcounter{elzc@RestoX}{- \value{elzc@PapelX} + \value{elzc@NumX} * \value{elzc@TarjXdim}}%
 \begin{picture}(\value{elzc@PapelX},\value{elzc@PapelY})(\value{elzc@XInicial},0)%
  \loop \ifnum\value{elzc@ContY} < \value{elzc@NumY} \advance\value{elzc@ContY} by 1{%
   \loop \ifnum\value{elzc@ContX} < \value{elzc@NumX} \advance\value{elzc@ContX} by 1{%
    \if@elzc@reversoficha
     \setcounter{elzc@PosX}{\value{elzc@NumX} * \value{elzc@TarjXdim} - %
      \value{elzc@ContX} * \value{elzc@TarjXdim} - \value{elzc@TarjXdim}}%
    \else
     \setcounter{elzc@PosX}{\value{elzc@ContX} * \value{elzc@TarjXdim}}%
    \fi
    \setcounter{elzc@PosY}{\value{elzc@ContY} * \value{elzc@TarjYdim}}%
    \ifnum \value{elzc@ContX} < \value{elzc@NumX}%
     \ifnum \value{elzc@ContY} < \value{elzc@NumY}%
      \put(\value{elzc@PosX},\value{elzc@PosY}){%
      \makebox(\value{elzc@TarjXdim}, \value{elzc@TarjYdim}){%
       \ifnum\value{elzc@TempFichaActual} < \value{elzc@Fichas}%
        \addtocounter{elzc@TempFichaActual}{1}%
        \addtocounter{elzc@TempFichaActualII}{1}%
        \parbox[t][\elzc@TarjYdim]{\elzc@TarjXdim}{%
         \if@elzc@reversoficha
          \expandafter\csname FichaReverso\romannumeral\value{elzc@TempFichaActual}\endcsname
         \else
          \expandafter\csname Ficha\romannumeral\value{elzc@TempFichaActual}\endcsname
         \fi}%
       \else
         \parbox[t][\elzc@TarjYdim]{\elzc@TarjXdim}{#1}%
       \fi}}%
     \fi
    \fi
    \if@elzc@guias
     \ifnum \value{elzc@ContX} = 0
      \put(\value{elzc@PosX},\value{elzc@PosY}){\line(-1,0){\value{elzc@Arista}}}%
     \else
      \ifnum \value{elzc@ContX} = \value{elzc@NumX}%
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(2,0){\value{elzc@Arista}}}%
      \else
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(-1,0){\value{elzc@Arista}}}%
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(2,0){\value{elzc@Arista}}}%
      \fi
     \fi
     \ifnum \value{elzc@ContY} = 0
      \put(\value{elzc@PosX},\value{elzc@PosY}){\line(0,-1){\value{elzc@Arista}}}%
     \else
      \ifnum \value{elzc@ContY} = \value{elzc@NumY}%
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(0,0){\value{elzc@Arista}}}%
      \else
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(0,0){\value{elzc@Arista}}}%
       \put(\value{elzc@PosX},\value{elzc@PosY}){\line(0,-1){\value{elzc@Arista}}}%
      \fi
     \fi
    \fi
    \if@elzc@lineas
     \multiput(\value{elzc@PosX}, 0)(0, \value{elzc@TarjYdim})%
      {\value{elzc@NumY}}{\line(0,1){\value{elzc@TarjYdim}}}%
     \multiput(0, \value{elzc@PosY})(\value{elzc@TarjXdim}, 0)%
      {\value{elzc@NumX}}{\line(1,0){\value{elzc@TarjXdim}}}%
    \fi
    \if@elzc@puntos
     \put(\value{elzc@PosX}, \value{elzc@PosY}){\circle*{\value{elzc@Punto}}}
    \fi}%
   \repeat}%
  \repeat
 \end{picture}%
 \@elzc@lineasfalse\@elzc@puntosfalse\@elzc@guiasfalse\@elzc@reversofichafalse}

\NewDocumentCommand{\elzc@Tarjetas}{s s o o o m o}{%
 \IfBooleanTF{#2}{\@elzc@lineastrue}{\IfBooleanTF{#1}{\@elzc@puntostrue}{\@elzc@guiastrue}}%
 \setlength{\elzc@TarjXdim}{#3}%
 \setlength{\elzc@TarjYdim}{#4}%
 \IfValueTF{#5}{%
  \IfBooleanTF{#2}
   {\linethickness{#5}}
   {\IfBooleanTF{#1}
    {\setlength{\elzc@TempLen}{#5}\setcounter{elzc@Punto}{\elzc@TempLen}}
    {\setlength{\elzc@TempLen}{#5}\setcounter{elzc@Arista}{\elzc@TempLen}%
     \linethickness{\elzc@DefLinea}}}%
 }{%
  \IfBooleanTF{#2}
   {\linethickness{\elzc@DefLinea}}
   {\IfBooleanTF{#1}
    {\setcounter{elzc@Punto}{\value{elzc@DefPunto}}}
    {\setcounter{elzc@Arista}{\value{elzc@DefArista}}\linethickness{\elzc@DefLinea}}%
   }%
  }%
 \elzc@Cuadricula{\setlength{\unitlength}{1mm}#6}%
 \if@elzc@fichaconreverso
  \addtocounter{elzc@TempFichaActual}{-\value{elzc@TempFichaActualII}}%
  \newpage
  \setcounter{elzc@XInicial}{\value{elzc@RestoX}}%
  \@elzc@reversofichatrue
  \elzc@Cuadricula{\setlength{\unitlength}{1mm}}%
 \else
  \IfValueT{#7}{%
   \immediate\write\@auxout{\string\@twosidetrue\string\@mparswitchtrue}%
   \newpage
   \setcounter{elzc@XInicial}{\value{elzc@RestoX}}%
   \elzc@Cuadricula{\setlength{\unitlength}{1mm}#7}}%
 \fi
 \cleardoublepage
 \setcounter{elzc@TempFichaActualII}{0}%
 \setcounter{elzc@XInicial}{0}%
 \ifnum\value{elzc@TempFichaActual} < \value{elzc@Fichas}%
  \IfBooleanTF{#2}{\MakeIC**[#3][#4][#5]}{\IfBooleanTF{#1}{%
    \MakeIC*[#3][#4][#5]}{\MakeIC[#3][#4][#5]}}%
 \fi
 \setcounter{elzc@Fichas}{0}%
 \setcounter{elzc@TempFichaActual}{0}%
 \@elzc@fichaconreversofalse}

\NewDocumentCommand{\MakeBC}{s s O{\elzc@DefTPXdim} O{\elzc@DefTPYdim} o m o}{%
 \IfBooleanTF{#2}
  {\elzc@Tarjetas**[#3][#4][#5]{#6}[#7]}
  {\IfBooleanTF{#1}
   {\elzc@Tarjetas*[#3][#4][#5]{#6}[#7]}
   {\elzc@Tarjetas[#3][#4][#5]{#6}[#7]}}}

\NewDocumentCommand{\MakeIC}{s s O{\elzc@DefFichaXdim} O{\elzc@DefFichaYdim} o}{%
 \IfBooleanTF{#2}
  {\elzc@Tarjetas**[#3][#4][#5]{}}
  {\IfBooleanTF{#1}
   {\elzc@Tarjetas*[#3][#4][#5]{}}
   {\elzc@Tarjetas[#3][#4][#5]{}}}}

\let\MakeFC\MakeIC

\NewDocumentCommand{\Card}{m o}{%
 \addtocounter{elzc@Fichas}{1}%
 \expandafter\def\csname Ficha\romannumeral\value{elzc@Fichas}\endcsname{#1}%
 \IfValueTF{#2}{%
  \@elzc@fichaconreversotrue
  \expandafter\def\csname FichaReverso\romannumeral\value{elzc@Fichas}\endcsname{#2}%
  \immediate\write\@auxout{\string\@twosidetrue\string\@mparswitchtrue}}
 {\expandafter\def\csname FichaReverso\romannumeral\value{elzc@Fichas}\endcsname{}}}

\IfFileExists{\jobname.aux}{\input\jobname.aux}

\endinput
%%
%% End of file `elzcards.cls'.
