% \iffalse meta-comment
%
% elzcards.dtx
% 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.
%
%<*internalbatchfile>
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX
\else
  \expandafter\begingroup
\fi
%</internalbatchfile>
%<*batchfile>
\input docstrip.tex
\preamble

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.

\endpreamble
\keepsilent
\askforoverwritefalse
\obeyspaces
\Msg{************************************************************}
\Msg{************************* \jobname *************************}
\Msg{************************************************************}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\Msg{\jobname.sty written.}
\Msg{}
\immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx}
\immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo}
\Msg{}
\Msg{Change history and index updated.}
\postamble
\endpostamble
%</batchfile>
%<*internalbatchfile>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\Msg{\jobname.ins written.}
%</internalbatchfile>
%<*batchfile>
\generate{\file{\jobname-example.tex}{\from{\jobname.dtx}{ejemplo}}}
\Msg{\jobname-example.tex written.}
\Msg{************************************************************}
\Msg{To produce the documentation, compile \jobname.dtx file with}
\Msg{ pdflatex \jobname.dtx}
\Msg{If write18 is not enabled, type}
\Msg{ makeindex -s gind.ist -o \jobname.ind \jobname.idx}
\Msg{ makeindex -s gglo.ist -o \jobname.gls \jobname.glo}
\Msg{to update index and changelog respectively.}
\Msg{In either case, compile again.}
\Msg{************************************************************}
\Msg{}
%</batchfile>
%<batchfile>\endbatchfile
%<*internalbatchfile>
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internalbatchfile>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[letterpaper,vmargin={3cm,2cm},hmargin={3cm,2cm}]{geometry}
\usepackage[usenames,dvipsnames]{color}
\usepackage[english]{babel}
\usepackage{paralist,calc,array}
\usepackage{elzcards}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\setlength{\parskip}{5pt}
\begin{document}
 \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{922}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.00}{2015/03/05}{First release as a class.}
% \changes{v1.20}{2015/04/26}{01. Changes in \texttt{.dtx} header and spaces on embedded \texttt{.ins} file. Now it should compile with pdf\TeX{} to produce only package files.}
% \changes{v1.20}{2015/04/26}{02. It isn't a class anymore. Now is a package.}
% \changes{v1.20}{2015/04/26}{03. Supports adjustable gaps between cards.}
% \changes{v1.20}{2015/04/26}{04. Added commands to control default values of optional arguments of {\slshape make} commands.}
% \changes{v1.20}{2015/04/26}{05. \cs{unitlength} is handled transparently.}
% \changes{v1.20}{2015/04/26}{06. Added key-val package to drop positional parameters and stars on {\slshape make} commands.}
% \changes{v1.20}{2015/04/26}{07. Added \cs{BusinessCard} command instead of defining the card's design with \cs{MakeBC}.}
% \changes{v1.20}{2015/04/26}{08. Added optional stars on {\slshape make} commands to allow not clearing the cards in order to have the possibility of being processed again.}
% \changes{v1.20}{2015/04/26}{09. Added informational output to log and console about what is being processed.}
% \changes{v1.20}{2015/04/26}{10. Added macros to change default crop behavior.}
%
% \GetFileInfo{\jobname.sty}
%
% \DoNotIndex{\\, \addtocounter, \advance, \arabic, \@auxout, \begin, \BusinessCard, \circle, \cleardoublepage, \clearpage, \CropMarksSize, \csname, \def, \define@key, \documentclass, \else, \@elzc@conreversofalse, \@elzc@conreversotrue, \elzc@DefArista, \elzc@DefFichaXdim, \elzc@DefFichaYdim, \elzc@DefLinea, \elzc@DefPunto, \elzc@DefSeparaX, \elzc@DefSeparaY, \elzc@DefTPXdim, \elzc@DefTPYdim, \@elzc@fichaconreversofalse, \@elzc@fichaconreversotrue, \@elzc@guiasfalse, \@elzc@guiastrue, \@elzc@lineasfalse, \@elzc@lineastrue, \@elzc@puntosfalse, \@elzc@puntostrue, \@elzc@reversofalse, \@elzc@reversotrue, \elzc@SeparaX, \elzc@SeparaY, \@elzc@TarjetaAnverso, \@elzc@tarjetaconreversofalse, \@elzc@tarjetaconreversotrue, \@elzc@tarjetafalse, \@elzc@TarjetaReverso, \@elzc@tarjetatrue, \elzc@TarjXdim, \elzc@TarjYdim, \elzc@TempLen, \elzc@TempUnitLength, \end, \endcsname, \expandafter, \fi, \hfill, \if@elzc@conreverso, \if@elzc@fichaconreverso, \if@elzc@guias, \if@elzc@lineas, \if@elzc@puntos, \if@elzc@reverso, \if@elzc@tarjeta, \if@elzc@tarjetaconreverso, \InputIfFileExists, \ifnum, \IfBooleanF, \IfBooleanTF, \IfValueT, \IfValueTF, \ifx, \immediate, \input, \jobname, \LARGE, \let, \line, \linethickness, \LineThickness, \loop, \makebox, \mbox, \@mparswitchtrue, \message, \mycenter, \NeedsTeXFormat, \newcommand, \newcounter, \NewDocumentCommand, \newif, \newlength, \PackageError, \parbox, \parindent, \ProvidesPackage, \put, \relax, \repeat, \RequirePackage, \romannumeral, \setcounter, \setkeys, \setlength, \string, \textheight, \textwidth, \the, \thispagestyle, \TotalFC, \TotalIC, \@twosidetrue, \undefined, \unitlength, \usepackage, \value, \vfill, \@wholewidth, \write}
%
% \title{The \textsf{\jobname} package\thanks{This document
%   corresponds to \textsf{\jobname}~\fileversion, dated \filedate.}}
% \author{Emilio Lazo Zaia\\ \texttt{< emiliolazozaia at gmail.com >}}
%
% \maketitle
%
% \tableofcontents
%
% \section{Introduction}
%
% |elzcards| is a package meant to be an easy and flexible way to typeset business cards, index cards and flash cards, with -optional- back side. You must bother only by setting the paper size, margins and the design of your cards\footnote{No predefined design is given; you must typeset your cards.}. Everything else is done by |elzcards|.
%
% It uses the printable area of the paper to print the cards, so it relies on |\textwidth| and |\textheight| (not on |\paperwidth| and |\paperheight|) to calculate how many cards fits in a page.
%
% You should typeset the design of the cards with one macro the package provides, followed by another macro to write them on paper. Macros used to manage business cards are not the same as for index/flash cards. Business cards are all equal, one design is repeated many times in a page, but index/flash cards are all different, so the macro to typeset index/flash cards manages a stack of cards. You should execute it many times as cards you have and all them will be stored to be processed when you have finished adding them. However, index cards and flash cards are in essence the same; the package provides macros for ``both'' cases but they behave the same. Macros aliases for flash cards were added for completeness.
%
% \section{Usage}
%
% Please load your class (i.e. |article|) and load the package. {\itshape It does not have options.}
%
% \noindent {\color{RoyalBlue}|\documentclass{article}|}
%
% \noindent {\color{RoyalBlue}|\usepackage{elzcards}|}
%
% \noindent Now I'll recommend you inserting the |geometry| package and setting the margins according to
%
% \noindent \hspace*{2em}\parbox{\textwidth-2em}{\begin{enumerate}[\bfseries 1.]
%  \item the desired size of your cards,
%  \item the paper you'll use,
%  \item the printable area of your printer.
% \end{enumerate}}
%
% \noindent For example, for the default business card size (3.5 inches x 2 inches) in a letter paper, you would use:
%
% \noindent {\color{RoyalBlue}|\usepackage[letterpaper,landscape,vmargin={0.25in,0.25in},hmargin={0.25in,0.25in}]|
%
% \hfill |{geometry}|}
%
% After |\begin|ning your |{document}|, you have four principal macros to produce the cards you want. These macros are:
% \begin{itemize}
%  \item |\BusinessCard| and |\MakeBC| to typeset business cards, and
%  \item |\IndexCard| and |\MakeIC| to typeset index cards and flash cards\footnote{Also the package provides the aliases \cs{FlashCard} and \cs{MakeFC} for your convenience when writing flash cards but they are the same as its corresponding index cards macros.}.
% \end{itemize}
%
% \subsection{Typesetting the cards}
%
% \noindent \DescribeMacro{\BusinessCard}{\color{RoyalBlue}|\BusinessCard|\marg{front side design}\oarg{back side design}}
%
% To produce a business card, you should issue the command |\BusinessCard|. What you write as the first argument (with braces) will be the card's front face design, and its second -optional- argument (with square brackets) is the card's back side\footnote{There is no need to specify the |twoside| option when loading the class even if you are writing twosided cards, but you must compile your document twice.}. Everything you put inside |{ }| and inside |[ ]| will be stored in a box and repeated in a grid until the page has been filled.
%
% \noindent \DescribeMacro{\IndexCard}{\color{RoyalBlue}|\IndexCard|\marg{front side design}\oarg{back side design}}
%
% \noindent \DescribeMacro{\FlashCard}{\color{RoyalBlue}|\FlashCard|\marg{front side design}\oarg{back side design}}
%
% To produce an index/flash card you have |\IndexCard|\footnote{or \cs{FlashCard}, which is the same command.}. This command has the same syntax as |\BusinessCard|, but it manages a stack of index/flash cards. You should execute it many times as cards you have to add all them into the stack. You can add the number of cards you want with many instances of |\IndexCard|. All these cards will be processed when you issue the {\slshape make} command, no matter how many pages are needed to print all them.
%
% \noindent \DescribeMacro{\CurrentIC}{\color{RoyalBlue}|\CurrentIC|}
% \noindent \DescribeMacro{\CurrentFC}{\color{RoyalBlue}|\CurrentFC|}
%
% \noindent \DescribeMacro{\TotalIC}{\color{RoyalBlue}|\TotalIC|}
% \noindent \DescribeMacro{\TotalFC}{\color{RoyalBlue}|\TotalFC|}
%
% With |\CurrentIC| and |\TotalIC| you can access the counters associated with index/flash cards. |\CurrentIC| prints the number of the current index/flash card and |\TotalIC| print the total of card. For example, you can add something like |Card: \CurrentIC{} of \TotalIC| somewhere on the content of your cards.
%
% \subsection{Writing cards on paper}
%
% At this time, nothing has been written yet on the paper. The commands described on previous section only define contents of the cards; to write them on paper you should issue |\MakeBC| for business cards or |\MakeIC|\footnote{or \cs{MakeFC}, which is also an alias.} for index/flash cards.
%
% \noindent \DescribeMacro{\MakeBC}{\color{RoyalBlue}|\MakeBC[*]|\oarg{key-val comma separated list of options}}
%
% \noindent \DescribeMacro{\MakeIC}{\color{RoyalBlue}|\MakeIC[*]|\oarg{key-val comma separated list of options}}
%
% \noindent \DescribeMacro{\MakeFC}{\color{RoyalBlue}|\MakeFC[*]|\oarg{key-val comma separated list of options}}
%
% They have a possible star and a key-val list of options, both optional with square brackets. The key-val options are intented to change sizes, gaps and crop options (as described on next section). The star means that the {\slshape make} command won't clear all cards it has processed. Normally, when you execute any of these {\slshape make} commands, a later execution of it will have no cards to process. If you issue a {\slshape make} command with a star |*| you may later use the same {\slshape make} command every time you want without adding again the same set of cards. Otherwise, without |*| all cards are purged.
%
% \subsection{key-val options: defining sizes, gaps, crop options}
%
% Both {\slshape make} commands accepts a key-val list of comma-separated options. These options are:
%
% {\tabcolsep4pt
% \begin{tabular}{lll}
%  Option & What changes? & \rmfamily Default value \\ \hline
%  hsize= & horizontal size of each card & |3.5in| in business cards, |5in| on index/flash cards \\
%  vsize= & vertical size of each card & |2in| in business cards, |3in| on index/flash cards \\
%  hgap= & horizontal gap between cards & 0pt \\
%  vgap= & vertical gap between cards & |0pt| \\
%  segment length= & segment (arista) of crop crosses & |1mm| \\
%  dot size= & diameter of crop dots & |1pt| \\
%  line thickness= & thickness of crop line & |0.1mm| \\
%  crosses & use crosses as crop marks & true \\
%  dots & use dots as crop marks & false \\
%  lines & use lines as crop marks & false \\
% \end{tabular}}
%
% You may change whatever length on this list\footnote{All these key-val options except the latter three are \LaTeX{} length.}. Everything you don't specify will be taken from its default value. As you can see, business cards and index/flash cards have different default sizes, but both can be changed with |hsize| and |vsize| in the {\slshape make} command. Both gaps are set by default to zero, meaning no distance between cards. The default crop mark is the cross (which really are segments and crosses); if you want dots or lines you must specify it. Using lines you'll have lines between all cards, like a grill. This may be useful also if you want the line as the border of the card, part of the design itself of the card. {\itshape Back side cards will have no crop marks.}
%
% \subsection{Changing default values and options}
%
% You can change all the default behavior and values; it may be convenient instead of issuing {\slshape make} commands with parameters, specially if you typeset more than one set of cards in the same document, which uses the same lengths and are different than default values. Changing default values at some point of the document may be preferred than calling these {\slshape make} commands with optional arguments over and over. This package provides commands to change all default values in whatever place of the document and that will apply to every card onwards:
%
% \newpage
% \noindent \DescribeMacro{\BCdim}{\color{RoyalBlue}|\BCdim|\marg{h-size}\marg{v-size}}
%
% This command |\BCdim| takes two arguments, the horizontal and vertical default size of business cards. {\slshape Key-val options: |hsize=| and |vsize=|.}
%
% \noindent \DescribeMacro{\ICdim}{\color{RoyalBlue}|\ICdim|\marg{h-size}\marg{v-size}}
% \DescribeMacro{\FCdim}
%
% With |\ICdim| or |\FCdim| you can change default size of index/flash cards, like with |\BCdim|. {\slshape Key-val options: |hsize=| and |vsize=|.}
%
% \noindent \DescribeMacro{\BCgap}{\color{RoyalBlue}|\BCgap|\marg{h-gap}\marg{v-gap}}
% \DescribeMacro{\ICgap}
% \DescribeMacro{\FCgap}
%
% With |\BCgap|, |\ICgap| or |\FCgap| you can change the gap between cards. |elzcards| doesn't manages gaps differently between business cards and index/flash cards, like in the case of the above commands representing sizes. {\itshape If you specify only one parameter, this will be taken as the gap in both directions.} {\slshape Key-val options: |hgap=| and |vgap=|.}
%
% \noindent \DescribeMacro{\CrossSegment}{\color{RoyalBlue}|\CrossSegment|\marg{segment length}}
%
% This macro can be used to change the length of segments used as crop marks. {\slshape Key-val option: |segment length=|.}
%
% {\parindent0pt
% \DescribeMacro{\DotSize}{\color{RoyalBlue}|\DotSize|\marg{dot size}}
%
% With |\DotSize| you can change the diameter of the dots. {\slshape Key-val option: |dot size=|}
%
% \DescribeMacro{\LineThickness}{\color{RoyalBlue}|\LineThickness|\marg{thickness}}
%
% |\LineThickness| changes the default value of the thickness of the line. {\slshape Key-val option: |line thickness=|.}
%
% \DescribeMacro{\CropCrosses}{\color{RoyalBlue}|\CropCrosses|}
%
% This command make default drawing crosses and segments as crop marks. {\itshape That's the default, but you may change it with the followind two macros.} {\slshape Key-val option: |crosses|.}
%
% \DescribeMacro{\CropDots}{\color{RoyalBlue}|\CropDots|}
%
% This command make default drawing dots as crop marks. {\slshape Key-val option: |dots|.}
%
% \DescribeMacro{\CropCrosses}{\color{RoyalBlue}|\CropLines|}
%
% This command make default drawing lines as crop marks. {\slshape Key-val option: |lines|.}
% }
%
% \section{Final words}
%
% In the same document you can typeset many different sets of cards. You can combine business cards with index cards in the order you want; also using different sizes of cards, different gaps, designs, cropping options, and even changing the paper geometry with |\geometry|.
%
% If only one card has back side, the whole document behaves like a twosided document, i.e. it will swap horizontal margins and will have interleaved blank pages when a set of cards has only front side; this is the behavior of |twoside| option but you don't have to specify it by hand in |\documentclass|.
%
% Take into account that this is \LaTeX, so you can define your own commands and use them inside the |\BusinessCard| and |\IndexCard| macros, like in examples with macro |\mycenter|.
%
% \section{Sample output of a business card}
%
% In the following page you'll see the first set of business cards of the all-in-one included example:
% \savegeometry{migeo}
% \newgeometry{vmargin={0.5in,0.5in},hmargin={0.75in,0.75in}}
% \newcommand{\mycenter}[1]{top left corner\vfill\mbox{}%
%  \begin{center}\LARGE#1\end{center}\mbox{}\vfill \hfill bottom right corner}
% \BusinessCard{\mycenter{Business card \\ only front side \\ default options}}%
% \MakeBC
% \newpage
% \loadgeometry{migeo}
%
% \section{Code of the all-in-one example included}
%
% The following example is included as |elzcards-example.tex|.
%
% \StopEventually{\clearpage\PrintIndex\PrintChanges}
%
%    \begin{macrocode}
%<*ejemplo>
\documentclass{article}
\usepackage{elzcards}
\usepackage[landscape,letterpaper,vmargin={0.25in,0.25in},hmargin={0.25in,0.25in}]{geometry}
\newcommand{\mycenter}[1]{%
 top left corner\vfill\mbox{}%
 \begin{center}\LARGE#1\end{center}%
 \mbox{}\vfill \hfill bottom right corner}
\begin{document}
 \BusinessCard{\mycenter{Business card \\ only front side \\ default options}}
 \MakeBC
 \BusinessCard{\mycenter{Business card \\ front side \\ other size: vertical \\
  with thicker and longer crosses}}%
  [\mycenter{Business card \\ front side \\ other size: vertical}]
 \MakeBC[hsize=2in, vsize=3.5in, line thickness=1pt, segment length=0.5cm]
 \BusinessCard{\mycenter{Business card \\ only front side \\ with dots}}
 \MakeBC[dots]
 \BusinessCard{\mycenter{Business card \\ only front side \\ with big dots and gaps}}
 \MakeBC[dots, dot size=4pt, hgap=1.666cm, vgap=0.666cm]
 \BusinessCard{\mycenter{Business card \\ only front side \\ with lines}}
 \MakeBC[lines]
 \BusinessCard{\mycenter{Business card \\ only front side \\ with thicker lines}}
 \MakeBC[lines, line thickness=2pt]
 \BusinessCard{\mycenter{Business card \\ front side \\ other size \\ with gaps}}%
  [\mycenter{Business card \\ other size \\ back side}]
 %% We can specify size also with \BCdim command, outsize of \MakeBC command:
 \BCdim{74mm}{52mm}
 \MakeBC[hgap=1.666cm, vgap=0.666cm]
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}%
  [\mycenter{Index/flash card \CurrentIC{} of \TotalIC \\ back side}]
 %% Note that not all cards has back side.
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}%
  [\mycenter{Index/flash card \CurrentIC{} of \TotalIC \\ back side}]
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}
 \IndexCard{\mycenter{Index/flash card \\ front side \CurrentIC{} of \TotalIC}}
 %% Now \MakeIC* instead of \MakeIC, so we can process them again with \MakeIC or \MakeIC*.
 \MakeIC*
 %% We define some default parameters instead of giving options to \MakeIC:
 \ICgap{0.5cm}{0.5cm}
 \CrossSegment{10pt}
 \LineThickness{1pt}
 %% \MakeIC* again because we did use \MakeIC* before:
 \MakeIC*
 \FCgap{0pt}{0pt}% \FCgap is an alias to \ICgap.
 \ICdim{6in}{4in}
 \DotSize{1mm}
 \CropDots
 %% \CropCrosses
 %% \CropLines
 \MakeFC*% \MakeFC is an alias to \MakeIC.
\end{document}
%</ejemplo>
%    \end{macrocode}
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
\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

%</package>
%    \end{macrocode}
% \Finale
