%%
%% This is file `elzcards.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% elzcards.dtx  (with options: `package')
%% 
%% 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.sty and
%% elzcards-example.tex.
%% 
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{elzcards}[2015/04/26 v1.20 ELZ cards]

\RequirePackage{calc}
\RequirePackage{xparse}
\RequirePackage{keyval}

\newif\if@elzc@guias
\newif\if@elzc@puntos
\newif\if@elzc@lineas
\newif\if@elzc@tarjeta
\newif\if@elzc@tarjetaconreverso
\newif\if@elzc@fichaconreverso
\newif\if@elzc@conreverso
\newif\if@elzc@reverso

\newlength{\elzc@TarjXdim}
\newlength{\elzc@TarjYdim}
\newlength{\elzc@SeparaX}
\newlength{\elzc@SeparaY}
\newlength{\elzc@TempLen}
\newlength{\elzc@TempUnitLength}
\newlength{\elzc@DefTPXdim}
\newlength{\elzc@DefTPYdim}
\newlength{\elzc@DefFichaXdim}
\newlength{\elzc@DefFichaYdim}
\newlength{\elzc@DefSeparaX}
\newlength{\elzc@DefSeparaY}
\newlength{\elzc@DefArista}
\newlength{\elzc@DefPunto}
\newlength{\elzc@DefLinea}

\newcounter{elzc@TarjXdim}
\newcounter{elzc@TarjYdim}
\newcounter{elzc@PapelX}
\newcounter{elzc@PapelY}
\newcounter{elzc@NumX}
\newcounter{elzc@NumY}
\newcounter{elzc@NumXY}
\newcounter{elzc@ContX}
\newcounter{elzc@ContY}
\newcounter{elzc@PosX}
\newcounter{elzc@PosY}
\newcounter{elzc@SeparaX}
\newcounter{elzc@SeparaY}
\newcounter{elzc@XInicial}
\newcounter{elzc@RestoX}
\newcounter{elzc@Punto}
\newcounter{elzc@Arista}
\newcounter{elzc@Fichas}
\newcounter{elzc@FichaActual}
\newcounter{elzc@TempNumX}
\newcounter{elzc@TempNumY}
\newcounter{elzc@TempMarcaX}
\newcounter{elzc@TempMarcaY}
\newcounter{elzc@TempFichaActualRev}
\newcounter{elzc@TempInfo}

\define@key{ELZc}{hsize}{\setlength{\elzc@TarjXdim}{#1}}
\define@key{ELZc}{vsize}{\setlength{\elzc@TarjYdim}{#1}}
\define@key{ELZc}{hgap}{\setlength{\elzc@SeparaX}{#1}}
\define@key{ELZc}{vgap}{\setlength{\elzc@SeparaY}{#1}}
\define@key{ELZc}{segment length}{%
 \setlength{\elzc@TempLen}{#1}\setcounter{elzc@Arista}{\elzc@TempLen}}
\define@key{ELZc}{dot size}{\setlength{\elzc@TempLen}{#1}\setcounter{elzc@Punto}{\elzc@TempLen}}
\define@key{ELZc}{line thickness}{\linethickness{#1}}
\define@key{ELZc}{crosses}[true]{\@elzc@guiastrue\@elzc@puntosfalse\@elzc@lineasfalse}
\define@key{ELZc}{dots}[true]{\@elzc@guiasfalse\@elzc@puntostrue\@elzc@lineasfalse}
\define@key{ELZc}{lines}[true]{\@elzc@guiasfalse\@elzc@puntosfalse\@elzc@lineastrue}

\newcommand*{\CurrentIC}{\arabic{elzc@FichaActual}}
\let\CurrentFC\CurrentIC

\newcommand*{\TotalIC}{\arabic{elzc@Fichas}}
\let\TotalFC\TotalIC

\newcommand*{\BCdim}[2]{\setlength{\elzc@DefTPXdim}{#1}\setlength{\elzc@DefTPYdim}{#2}}

\newcommand*{\ICdim}[2]{\setlength{\elzc@DefFichaXdim}{#1}\setlength{\elzc@DefFichaYdim}{#2}}
\let\FCdim\ICdim

\NewDocumentCommand{\BCgap}{m g}{%
 \setlength{\elzc@DefSeparaX}{#1}%
 \IfValueTF{#2}{\setlength{\elzc@DefSeparaY}{#2}}{\setlength{\elzc@DefSeparaY}{#1}}}%
\let\ICgap\BCgap
\let\FCgap\BCgap

\newcommand*{\CrossSegment}[1]{\setlength{\elzc@DefArista}{#1}}

\newcommand*{\DotSize}[1]{\setlength{\elzc@DefPunto}{#1}}

\newcommand*{\LineThickness}[1]{\setlength{\elzc@DefLinea}{#1}}

\newcommand*{\CropDots}{%
 \def\elzc@DefMarcasCorte{\@elzc@guiasfalse\@elzc@puntostrue\@elzc@lineasfalse}}

\newcommand*{\CropCrosses}{%
 \def\elzc@DefMarcasCorte{\@elzc@guiastrue\@elzc@puntosfalse\@elzc@lineasfalse}}

\newcommand*{\CropLines}{%
 \def\elzc@DefMarcasCorte{\@elzc@guiasfalse\@elzc@puntosfalse\@elzc@lineastrue}}

\NewDocumentCommand{\MakeBC}{s o}{%
 \ifx\undefined\@elzc@TarjetaAnverso
  \PackageError{elzcards}{There are no business cards defined}{}%
 \else
  \@elzc@tarjetatrue
  \if@elzc@tarjetaconreverso \@elzc@conreversotrue \else \@elzc@conreversofalse \fi
  \elzc@Predeterminados
  \setlength{\elzc@TarjXdim}{\elzc@DefTPXdim}%
  \setlength{\elzc@TarjYdim}{\elzc@DefTPYdim}%
  \IfValueT{#2}{\setkeys{ELZc}{#2}}%
  \elzc@Tarjetas
  \IfBooleanF{#1}{\elzc@TodoCero}%
 \fi}

\NewDocumentCommand{\MakeIC}{s o}{%
 \ifnum \value{elzc@Fichas} = 0
  \PackageError{elzcards}{There are no index/flash cards in stack}{}%
 \else
  \@elzc@tarjetafalse
  \if@elzc@fichaconreverso \@elzc@conreversotrue \else \@elzc@conreversofalse \fi
  \elzc@Predeterminados
  \setlength{\elzc@TarjXdim}{\elzc@DefFichaXdim}%
  \setlength{\elzc@TarjYdim}{\elzc@DefFichaYdim}%
  \IfValueT{#2}{\setkeys{ELZc}{#2}}%
  \elzc@Tarjetas
  \IfBooleanF{#1}{\elzc@TodoCero*}%
 \fi}
\let\MakeFC\MakeIC

\NewDocumentCommand{\BusinessCard}{+m +o}{%
 \def\@elzc@TarjetaAnverso{#1}%
 \IfValueTF{#2}{%
  \@elzc@tarjetaconreversotrue
  \def\@elzc@TarjetaReverso{#2}%
  \immediate\write\@auxout{\string\@twosidetrue\string\@mparswitchtrue}}
 {\def\@elzc@TarjetaReverso{}}}

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

\newcommand*{\elzc@Cuadricula}{%
 \setlength{\elzc@TempUnitLength}{\unitlength}%
 \setlength{\unitlength}{1sp}%
 \setlength{\parindent}{0pt}%
 \thispagestyle{empty}%
 \setcounter{elzc@NumX}{0}%
 \setcounter{elzc@NumY}{0}%
 \setcounter{elzc@TempNumX}{0}%
 \setcounter{elzc@TempNumY}{0}%
 \setcounter{elzc@TarjXdim}{\elzc@TarjXdim}%
 \setcounter{elzc@TarjYdim}{\elzc@TarjYdim}%
 \setcounter{elzc@SeparaX}{\elzc@SeparaX}%
 \setcounter{elzc@SeparaY}{\elzc@SeparaY}%
 \setcounter{elzc@PapelX}{\textwidth}%
 \setcounter{elzc@PapelY}{\textheight}%
 \loop \ifnum\value{elzc@TempNumX} < \value{elzc@PapelX}%
  \advance\value{elzc@TempNumX} by \value{elzc@TarjXdim}{%
   \addtocounter{elzc@NumX}{1}%
   \addtocounter{elzc@TempNumX}{\value{elzc@SeparaX}}}%
 \repeat
 \loop \ifnum\value{elzc@TempNumY} < \value{elzc@PapelY}%
  \advance\value{elzc@TempNumY} by \value{elzc@TarjYdim}{%
   \addtocounter{elzc@NumY}{1}%
   \addtocounter{elzc@TempNumY}{\value{elzc@SeparaY}}}%
 \repeat
 \addtocounter{elzc@TempNumX}{-\value{elzc@SeparaX}}%
 \addtocounter{elzc@TempNumY}{-\value{elzc@SeparaY}}%
 \ifnum\value{elzc@TempNumX} > \value{elzc@PapelX}%
  \addtocounter{elzc@NumX}{-1}%
 \fi
 \ifnum\value{elzc@TempNumY} > \value{elzc@PapelY}%
  \addtocounter{elzc@NumY}{-1}%
 \fi
 \setcounter{elzc@NumXY}{\value{elzc@NumX} * \value{elzc@NumY}}%
 \setcounter{elzc@ContX}{-1}%
 \setcounter{elzc@ContY}{-1}%
 \setcounter{elzc@RestoX}{- \value{elzc@PapelX} + \value{elzc@NumX} *
  (\value{elzc@TarjXdim} + \value{elzc@SeparaX}) - \value{elzc@SeparaX}}%
 \elzc@Informacion
 \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@reverso
     \setcounter{elzc@PosX}{(\value{elzc@NumX} - \value{elzc@ContX} - 1) * \value{elzc@TarjXdim}%
      + (\value{elzc@NumX} - \value{elzc@ContX} - 1) * \value{elzc@SeparaX}}%
    \else
     \setcounter{elzc@PosX}{\value{elzc@ContX} * (\value{elzc@TarjXdim} + \value{elzc@SeparaX})}%
    \fi
    \setcounter{elzc@PosY}{\value{elzc@ContY} * (\value{elzc@TarjYdim} + \value{elzc@SeparaY})}%
    \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}){%
        \setlength{\unitlength}{\elzc@TempUnitLength}%
        \parbox[t][\elzc@TarjYdim]{\elzc@TarjXdim}{%
         \if@elzc@tarjeta
          \if@elzc@reverso \@elzc@TarjetaReverso \else \@elzc@TarjetaAnverso \fi
         \else
          \ifnum\value{elzc@FichaActual} < \value{elzc@Fichas}%
           \addtocounter{elzc@FichaActual}{1}%
           \addtocounter{elzc@TempFichaActualRev}{1}%
           \if@elzc@reverso
            \expandafter\csname @elzc@FichaReverso\romannumeral\value{elzc@FichaActual}\endcsname
           \else
            \expandafter\csname @elzc@FichaAnverso\romannumeral\value{elzc@FichaActual}\endcsname
           \fi
          \fi
         \fi}}}%
     \fi
    \fi
    \if@elzc@reverso \else \elzc@CalculaMarcas \fi
   }\repeat
  }\repeat
 \end{picture}}

\newcommand*{\elzc@Tarjetas}{%
 {\pagestyle{empty}\cleardoublepage}%
 \elzc@Cuadricula
 \if@elzc@conreverso
  \@elzc@reversotrue
  \if@elzc@tarjeta \else \addtocounter{elzc@FichaActual}{-\value{elzc@TempFichaActualRev}}\fi
  \setcounter{elzc@XInicial}{\value{elzc@RestoX}}%
  \clearpage
  \elzc@Cuadricula
  \setcounter{elzc@XInicial}{0}%
  \@elzc@reversofalse
 \fi
 \if@elzc@tarjeta
 \else
  \setcounter{elzc@TempFichaActualRev}{0}%
  \ifnum\value{elzc@FichaActual} < \value{elzc@Fichas}%
   \elzc@Tarjetas%
  \fi
  \setcounter{elzc@FichaActual}{0}%
 \fi
 \clearpage}

\NewDocumentCommand{\elzc@TodoCero}{s}{%
 \IfBooleanTF{#1}{%
  \setcounter{elzc@Fichas}{0}%
  \@elzc@fichaconreversofalse}
 {\let\@elzc@TarjetaAnverso\undefined
  \let\@elzc@TarjetaReverso\undefined
  \@elzc@tarjetaconreversofalse}}

\newcommand*{\elzc@Predeterminados}{%
 \elzc@DefMarcasCorte
 \setlength{\elzc@SeparaX}{\elzc@DefSeparaX}%
 \setlength{\elzc@SeparaY}{\elzc@DefSeparaY}%
 \setlength{\elzc@TempLen}{\elzc@DefArista}\setcounter{elzc@Arista}{\elzc@TempLen}%
 \setlength{\elzc@TempLen}{\elzc@DefPunto}\setcounter{elzc@Punto}{\elzc@TempLen}%
 \linethickness{\elzc@DefLinea}}

\newcommand*{\elzc@CalculaMarcas}{%
 \setcounter{elzc@TempMarcaX}{\value{elzc@PosX}}%
 \setcounter{elzc@TempMarcaY}{\value{elzc@PosY}}%
 \ifnum \value{elzc@ContX} = \value{elzc@NumX}%
 \else
  \ifnum \value{elzc@ContY} = \value{elzc@NumY}%
  \else
   \elzc@DibujaMarcas{\value{elzc@TempMarcaX}}{\value{elzc@TempMarcaY}}%
  \fi
 \fi
 \addtocounter{elzc@TempMarcaX}{-\value{elzc@SeparaX}}%
 \ifnum \value{elzc@ContX} = 0%
 \else
  \ifnum \value{elzc@ContY} = \value{elzc@NumY}%
  \else
   \elzc@DibujaMarcas{\value{elzc@TempMarcaX}}{\value{elzc@TempMarcaY}}%
  \fi
 \fi
 \addtocounter{elzc@TempMarcaY}{-\value{elzc@SeparaY}}%
 \ifnum \value{elzc@ContX} = 0%
 \else
  \ifnum \value{elzc@ContY} = 0%
  \else
   \elzc@DibujaMarcas{\value{elzc@TempMarcaX}}{\value{elzc@TempMarcaY}}%
  \fi
 \fi
 \addtocounter{elzc@TempMarcaX}{\value{elzc@SeparaX}}%
 \ifnum \value{elzc@ContY} = 0%
 \else
  \ifnum \value{elzc@ContX} = \value{elzc@NumX}%
  \else
   \elzc@DibujaMarcas{\value{elzc@TempMarcaX}}{\value{elzc@TempMarcaY}}%
  \fi
 \fi}

\newcommand*{\elzc@DibujaMarcas}[2]{%
 \ifnum \value{elzc@ContX} = 0%
  \if@elzc@guias\put(#1,#2){\line(-1,0){\value{elzc@Arista}}}\fi
  \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
 \else
  \ifnum \value{elzc@ContX} = \value{elzc@NumX}%
   \if@elzc@guias\put(#1,#2){\line(2,0){\value{elzc@Arista}}}\fi
   \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
  \else
   \if@elzc@guias
    \put(#1,#2){\line(-1,0){\value{elzc@Arista}}}%
    \put(#1,#2){\line(2,0){\value{elzc@Arista}}}%
   \fi
   \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
   \if@elzc@lineas
    \put(#1,#2){\line(-1,0){\value{elzc@TarjXdim}}}%
    \put(#1,#2){\line(2,0){\value{elzc@TarjXdim}}}%
   \fi
  \fi
 \fi
 \ifnum \value{elzc@ContY} = 0%
  \if@elzc@guias\put(#1,#2){\line(0,-1){\value{elzc@Arista}}}\fi
  \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
 \else
  \ifnum \value{elzc@ContY} = \value{elzc@NumY}%
   \if@elzc@guias\put(#1,#2){\line(0,0){\value{elzc@Arista}}}\fi
   \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
  \else
   \if@elzc@guias
    \put(#1,#2){\line(0,0){\value{elzc@Arista}}}%
    \put(#1,#2){\line(0,-1){\value{elzc@Arista}}}%
   \fi
   \if@elzc@puntos\put(#1,#2){\circle*{\value{elzc@Punto}}}\fi
   \if@elzc@lineas
    \put(#1,#2){\line(0,0){\value{elzc@TarjYdim}}}%
    \put(#1,#2){\line(0,-1){\value{elzc@TarjYdim}}}%
   \fi
  \fi
 \fi}

\newcommand*{\elzc@Informacion}{%
 \message{^^JProcessing}%
 \if@elzc@tarjeta
  \message{business cards,}%
 \else
  \message{index/flash cards,}%
  \setcounter{elzc@TempInfo}{\value{elzc@NumXY} + \value{elzc@FichaActual}}%
  \ifnum \value{elzc@TempInfo} > \value{elzc@Fichas}%
   \setcounter{elzc@TempInfo}{\value{elzc@Fichas}}%
  \fi
  \addtocounter{elzc@FichaActual}{1}%
  \message{current=\arabic{elzc@FichaActual}-\arabic{elzc@TempInfo},
   total=\arabic{elzc@Fichas},}%
  \addtocounter{elzc@FichaActual}{-1}%
 \fi
 \if@elzc@reverso\message{back side,^^J}\else\message{front side,^^J}\fi
 \message{ per page: \arabic{elzc@NumXY} (\arabic{elzc@NumX}x\arabic{elzc@NumY}),}%
 \message{ hsize=\the\elzc@TarjXdim, vsize=\the\elzc@TarjYdim,
  hgap=\the\elzc@SeparaX, vgap=\the\elzc@SeparaY,^^J}%
 \if@elzc@guias
  \message{ with crosses,}%
  \setlength{\elzc@TempLen}{\value{elzc@Arista}sp}%
  \message{segment length=\the\elzc@TempLen, line thickness=\the\@wholewidth.^^J}%
 \fi
 \if@elzc@puntos
  \message{ with dots,}%
  \setlength{\elzc@TempLen}{\value{elzc@Punto}sp}%
  \message{dot size=\the\elzc@TempLen.^^J}%
 \fi
 \if@elzc@lineas
  \message{ with lines, line thickness=\the\@wholewidth.^^J}%
 \fi}

\setlength{\elzc@DefTPXdim}{3.5in}
\setlength{\elzc@DefTPYdim}{2in}
\setlength{\elzc@DefFichaXdim}{5in}
\setlength{\elzc@DefFichaYdim}{3in}
\setlength{\elzc@DefSeparaX}{0cm}
\setlength{\elzc@DefSeparaY}{0cm}
\setlength{\elzc@DefArista}{1mm}
\setlength{\elzc@DefPunto}{1pt}
\setlength{\elzc@DefLinea}{0.1mm}
\CropCrosses

\InputIfFileExists{\jobname.aux}{}\relax

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