commit 4be43722c22cd976821bd7ca7a9cc509a491d736
Author: lumidify <nobody@lumidify.org>
Date: Sat, 11 Apr 2020 15:05:44 +0200
Commit initial scripts
Diffstat:
6 files changed, 132 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,3 @@
+all:
+ # Compile the latest flashcard
+ ./tmp_compile.sh "`cat .cur_card`"
diff --git a/README.md b/README.md
@@ -0,0 +1,49 @@
+# Flashcard Tools
+
+## Tools for working with LaTeX flashcards
+
+### Directory structure
+
+* `defs.tex` - Contains all `\usepackage` statements and commands needed for the
+ LaTeX in the flashcards. This should *not* include `\documentclass` since that
+ is added automatically by the rendering scripts (it is different for different
+ scripts, so it can't be included in `defs.tex`).
+* `flashcards/` - Contains the actual flashcard files.
+
+### Flashcard structure:
+
+* Line 1 - Contains a "theorem number" or something similar this is what the
+ file is named after when using `addcard.pl`.
+ If this line contains '|' anywhere, the text after it is taken to be the
+ name of another flashcard that must be displayed before this one when it
+ is displayed using a viewer that supports this notation (useful for
+ splitting cards into smaller parts).
+* Line 2 - Contains the front side of the card.
+* Rest of the file - Contains the back side of the card.
+
+### Helper Scripts
+
+* addcard.pl <initials> <card number> - Adds a card with the given number and
+ initials to the directory `flashcards` and opens it with `vi`. The file
+ name is based on the number and initials, so `./addcard.pl xx 1.2.3` will
+ open the file `flashcards/01-02-03_00xx`. The extra number after the underscore
+ is increased if the file already exists. The argument <card number> is pasted
+ into the first line of the file automatically. Additionally, `addcard.pl`
+ writes the file of the current card into `.cur_card` so that it can be
+ read by a Makefile (see 'Sample Workflow' below).
+* tmp_compile.sh <card name> - Compiles the given card in `flashcards/` to the
+ file `tmp_compile.pdf`.
+* compile_all.sh - Compiles all flashcards in `flashcards/` into one big file.
+* gentsv.sh - Generates a TSV file suitable for importing into Mnemosyne.
+ Note that you still need to add the definitions (`defs.tex`) for the project
+ into the Mnemosyne config.
+
+### Sample Workflow
+
+Just add a new card with `addcard.pl`. When you're done editing it, run `make`
+(assuming you have the sample Makefile in the directory). This compiles the
+card to `tmp_compile.pdf`. If your PDF viewer supports reloading documents,
+you can just leave it open and reload every time you create a new card.
+
+Once you're done adding all cards, you can use any of the other helper scripts
+to compile the cards to one big file or do whatever.
diff --git a/addcard.pl b/addcard.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+die "Loser.\n" if @ARGV != 2;
+
+sub gen_filename {
+ my ($second_idx, @groups) = @_;
+ my $str = join "-", map {sprintf "%02d", $_} @groups;
+ return sprintf("flashcards/%s_%02d%s", $str, $second_idx, $ARGV[0]);
+}
+
+my @groups;
+push @groups, $1 while $ARGV[1] =~ m/(\d+)\.?/g;
+if (@groups) {
+ my $second_idx = 0;
+ my $filename;
+ while (-e ($filename = gen_filename $second_idx, @groups)) {
+ $second_idx++;
+ }
+ open my $fh, ">", $filename or die "Moron.\n";
+ print $fh $ARGV[1];
+ close $fh;
+ open $fh, ">", ".cur_card" or die "Fool.\n";
+ print $fh $filename;
+ close $fh;
+ system("vi", $filename);
+} else {
+ die "Idiot.\n";
+}
diff --git a/compile_all.sh b/compile_all.sh
@@ -0,0 +1,16 @@
+# Compiles all flashcards to PDF
+
+echo '\\documentclass[grid,avery5371]{flashcards}' > complete.tex
+cat defs.tex >> complete.tex
+echo '\\cardfrontstyle{headings}' >> complete.tex
+printf '\\begin{document}\n' >> complete.tex
+for i in `ls flashcards`
+do
+ meta1=`head -n 1 "flashcards/$i" | tr -d '\n' | sed s/\|.*$//`
+ meta2=`sed '2!d' "flashcards/$i" | tr -d '\n'`
+ body=`tail -n +3 "flashcards/$i"`
+ printf '\\begin{flashcard}[%s]{%s}\n%s\n\\end{flashcard}\n' "$meta1" "$meta2" "$body" >> complete.tex
+done
+printf '\\end{document}\n' >> complete.tex
+pdflatex complete.tex
+rm complete.{tex,log,aux}
diff --git a/gentsv.sh b/gentsv.sh
@@ -0,0 +1,9 @@
+rm -f mnemosyne.tsv
+for i in `ls flashcards`
+do
+ printf '<latex>' >> mnemosyne.tsv
+ head -n 1 flashcards/$i | tr -d '\n' >> mnemosyne.tsv
+ printf '</latex>\t<latex>' >> mnemosyne.tsv
+ tail -n +2 flashcards/$i | sed 's/%.*$//g' | tr '\n' ' ' >> mnemosyne.tsv
+ printf '</latex>\n' >> mnemosyne.tsv
+done
diff --git a/tmp_compile.sh b/tmp_compile.sh
@@ -0,0 +1,24 @@
+# Compiles the flashcard with the given ID to PDF,
+# adding the necessary frontmatter beforehand.
+
+if [ $# -eq 0 ]
+then
+ echo "USAGE: ./tmp_compile.sh <flashcard_id>"
+ exit 1
+fi
+
+if [ ! -e "flashcards/$1" ]
+then
+ echo "File doesn't exist: flashcards/$1"
+ exit 1
+fi
+
+meta1=`head -n 1 "flashcards/$1" | tr -d '\n'`
+meta2=`sed '2!d' "flashcards/$1" | tr -d '\n'`
+body=`tail -n +3 "flashcards/$1"`
+echo '\\documentclass[grid,avery5371]{flashcards}' > tmp_compile.tex
+cat defs.tex >> tmp_compile.tex
+echo '\\cardfrontstyle{headings}' >> tmp_compile.tex
+printf '\\begin{document}\n\\begin{flashcard}[%s]{%s}\n%s\n\\end{flashcard}\n\\end{document}\n' "$meta1" "$meta2" "$body" >> tmp_compile.tex
+pdflatex tmp_compile.tex
+rm tmp_compile.{aux,log,tex}