#!/usr/bin/env python #(c) May 2002 Thomas Guettler http://www.thomas-guettler.de #This Script is in the public domain #Feedback welcome # #This script creates a pdf file with pdflatex #for creating a memory-game (card-game). #Put images with extension .jpg in a directory called images #For each image create .txt file (foo.jpg --> foo.txt) containing #a short description. #The script creates a memory-card for each image. #Print it twice, cut the cards, stick them on thick paper. #A nice present for you grandmother #Bugs: # +box is 6.5 x 6cm instead of 6x6 import os import os.path import re file=open('cards.tex', 'w') file.write( r"""%pdf-tex: \documentclass[a4paper,11pt]{article} \usepackage{ngerman} \usepackage[pdftex]{graphicx} % erlaube üöäßÜÖÄ im tex-file \usepackage[latin1]{inputenc} \pagestyle{empty} % keine Seitenzahlen anzeigen \begin{document} \noindent """) for img_filename in os.listdir('images'): text_filename=re.sub(r'(.*)\.jpg', r'\1', img_filename) if text_filename==img_filename: continue img_text=open('images/' + text_filename + ".txt") text=img_text.read() img_text.close() file.write(r"""\fbox{ \centering{ \parbox[c][6cm]{6cm}{ \centering{ \includegraphics[width=5.5cm,height=4.8cm,keepaspectratio]{%s} \noindent %s } } } } \hspace{.5cm} \vspace{.5cm} """ % ('images/' + img_filename, text)) print "wrote", text file.write("\end{document}\n") file.close()