Generating Flashcards with Linux and Latex 用 Linux 和 Latex 生成记忆卡

If you get bored of those fancy electronic ways of memorise words or other stuff and would like to resort to the old fashioned flashcards, here with the help of Linux and Latex, it is just in a few steps.

First, stuff everything you would like to memorise into a text file say listfile, which contains a list of items in the following format:
A [TAB] B
whrere A is to show on the front of the flashcard and B is to show on the back, [TAB] stands for a horitontal tab.

Then, execute the following script (better to save it into a file, say flashcard_gen.sh) ./flashcard_gen.sh listfile > latexfile.tex

# Argument checkingif["$#"-ne1]; thenecho"Usage:"$0"filename"exit1fi# Print the LaTeX headersecho"\documentclass[xkcard,grid,frame]{flashcards}"echo"\cardfrontstyle[\LARGE\bf]{headings}"echo"\cardbackstyle[\LARGE\slshape]{plain}"echo"% turn of those nasty overfull and underfull hboxes"echo"\hbadness=10000"echo"\hfuzz=50pt"echo"\begin{document}"# Read the file providedwhileIFS=$'\t'read-r-a arr
# The -r tells read that \ isn't special in the input data; # The -a arr tells it to split the input-line into words and store the results in arr; # The IFS=$'\t' tells it to use only tabs to split words, instead of the regular Bash default of also allowing spaces to split words as well.doecho"\begin{flashcard}{${arr[0]}}"echo${arr[1]}echo"\end{flashcard}"done<$1echo"\end{document}"exit0

Then compile the generated tex file and print out the pdf file, cut along the grids and everything is DONE.