This version includes a toggle following \documentclass
. If this is set to true, then individual cards are produced using TiKZ. If it is set to false, then the old layout is used. The code requires the --shell-escape
option or equivalent as it writes the contents of the cards to an external file and then reads them back in using textmerg
.
I have never written anything to an external file before myself so I am not at all sure that this is a proper way to do it. I based the code on a question with an answer by egreg but I may well have introduced my own varieties of mangling.
Caveat emptor...
\documentclass{article}
% The next line defines and sets the toggle. Remove the % to get the original layout; replace it to get individual cards.
\newif\ifcards\cardstrue%\cardsfalse
\usepackage{array,xcolor,calc}
\renewcommand*\arraystretch{10}
\newcounter{counter}
\newlength\sidewidth
\newlength\cardwidth
\newlength\cardheight
\setlength\sidewidth{10mm + 2\tabcolsep + 2\arrayrulewidth}
\newcolumntype\specifier{|%
*2{
>{\centering\selectfont\stepcounter{counter}\thecounter}m{1cm}
|>{\centering}m{\dimexpr.5\linewidth-1cm-4\tabcolsep-3\arrayrulewidth\relax}
|}
}
\makeatletter
\newif\if@mywriteopen % initially false http://tex.stackexchange.com/questions/42204/help-wanted-on-openout-write-and-closeout
\def\row[#1]#2{%
& #1 \par \vspace{15pt} \textcolor{red}{#2}
\ifodd\value{counter}
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{&}{\tabularnewline\hline}}
\ifcards
\usepackage{geometry,tikz,textmerg}
\usetikzlibrary{calc}
\newwrite\mywriter
\def\@writecard#1{% http://tex.stackexchange.com/questions/42204/help-wanted-on-openout-write-and-closeout
\if@mywriteopen\else
\global\@mywriteopentrue
\immediate\openout\mywriter=mycards.dat\relax
\fi
\immediate\write\mywriter{#1}}
\settototalheight{\cardheight}{%
\begin{tabular}{\specifier}\hline
\let\@writecard\relax
\let\stepcounter\relax
\row[RAM]{Random Access Memory}
\end{tabular}}
\settowidth{\cardwidth}{%
\begin{tabular}{\specifier}\hline
\let\@writecard\relax
\let\stepcounter\relax
\row[RAM]{Random Access Memory}
\end{tabular}}
\def\row[#1]#2{%
\ifcards
\stepcounter{counter}%
\@writecard{\thecounter}%
\@writecard{#1}%
\@writecard{#2}%
\fi}
\geometry{%
paperwidth=1.25\cardwidth,
paperheight=1.25\cardheight,
textheight=.4pt+\cardheight,
textwidth=.4pt+\cardwidth,
hratio=1:1,
vratio=1:1,
}
\setlength\parindent{0pt}
\newenvironment{flashcards}{%
\setcounter{counter}{0}%
}{%
\immediate\closeout\mywriter\relax
\Fields{\flashnumber\flashacro\flashcontent}
\Merge{mycards.dat}{%
\pgfkeyssetvalue{/flashcards/number}{\flashnumber}
\pgfkeyssetvalue{/flashcards/acro}{\flashacro}
\pgfkeyssetvalue{/flashcards/content}{\flashcontent}
\begin{tikzpicture}[outer sep=0pt, inner sep=0pt]
\path [draw]
(0,0) coordinate (a) -| (\cardwidth,-\cardheight) coordinate [midway] (c) coordinate (d) -| cycle
(a) +(\sidewidth,0) coordinate (b) -- (b |- d)
;
\node [minimum width=\sidewidth, minimum height=.75\cardheight, anchor=south west, text centered] at (a |- d) {\pgfkeysvalueof{/flashcards/number}};
\node [minimum width={\cardwidth-\sidewidth}, minimum height=.75\cardheight, anchor=south west, text centered, align=center] at (b |- d) {\pgfkeysvalueof{/flashcards/acro}\\[15pt]\color{red}\pgfkeysvalueof{/flashcards/content}};
\end{tikzpicture}}}
\else
\usepackage{longtable}
\let\oldendlongtable\endlongtable
\def\endlongtable{%
\ifodd\value{counter}\omit\tabularnewline\cline{1-2}\fi
\oldendlongtable}
\newenvironment{flashcards}{%
\begin{longtable}{\specifier}\hline
}{%
\end{longtable}
}
\fi
\makeatother
\begin{document}
\begin{flashcards}%
\row[RAM]{Random Access Memory}%
\row[BIOS]{Basic Input Output System}%
\row[OMG]{Oh My Ghost}%
\row[PS]{Post Script}%
% and many more
\end{flashcards}%
\end{document}

Setting \cardsfalse
produces:

12pt
around each output page should be fine enough.