This is a simple program to transform LaTeX math notes (written with
the amsthm
package) into Anki notecards. It converts things
like definitions, theorems, lemmas, corrolaries, and equations into the input
format for the LaTeX Note Importer.
Table of Contents
- Definitions, theorems, and lemmas with names are treated basically the same:
- Definitions of the following (amsthm) form:
\begin{definition}[Name of Thing Being Defined]
Definition of term.
\end{definition}
- Theorems with names:
\begin{theorem}[Name of Theorem]
An important theorem.
\end{theorem}
- Lemmas with names:
\begin{lemma*}[Name of Lemma]
An important lemma.
\end{lemma*}
where "What is the term/theorem/lemma 'Name of Term/Theorem/Lemma'?" will be on the front and the definition/theorem/lemma will be on the back.
- Theorems, lemmas, and corrolaries of an if-then form with premises and a conclusion:
\begin{theorem}[Name of Theorem]
If
\begin{premises}
\item $x\in\C$
\end{premises}
then
\begin{conclusion}
there exists $y\in\C$ such that $y^2=x$.
\end{conclusion}
\end{theorem}
where the name/premises will be on the front side and the conclusion on the back.
- Equations of a specific form:
\begin{eqenv}[Name of Equation]
Setup ("Let x be a real number", etc.)
\begin{equation*}
x = y
\end{equation*}
\begin{eqenv}
where the setup and first half of the equation will be on the front side and the
second half will be on the back side. Note that the "halves" are split on the
string " = "
.
- And things that are already notes will be kept:
\begin{note}
\begin{field}
Side 1
\end{field}
\begin{field}
Side 2
\end{field}
\end{note}
You can download binaries from the tags page. Then if input.tex
is a
LaTeX2e file with the above sorts of environments in it, you can just run
./amsthm-to-anki input.tex output.tex
and import output.tex
with the LaTeX Note Importer.
- Make sure
pdflatex
is on yourPATH
(hint: it likely already is). - Install the LaTeX Note Importer. See the Anki documentation for details on installing plugins.
- Ensure your LaTeX preamble is set how you like it: go to the "Add" screen. Click on the "Basic" button. Click "Manage", then select the first "Basic" card type from the list, and click "Options". Adjust your LaTeX preamble so that your notes will compile properly.
This is the setup I have in my document preamble:
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem*{lemma*}{Lemma}
\newtheorem{corrolary}{Corrolary}
\newtheorem*{corrolary*}{Corrolary}
\theoremstyle{definition} % these are the non-italicized
\newtheorem{eqenv}{Equation}
\newtheorem*{eqenv*}{Equation}
\newtheorem{remark}{Remark}
\newtheorem*{remark*}{Remark}
\newtheorem{example}{Example}
\newtheorem*{example*}{Example}
\newtheorem{definition}{Definition}
\newtheorem*{definition*}{Definition}
Note that the evironment names must match exactly with what I've defined here (although the displayed text -- the second argument -- can be arbitrary). I also define the following environments:
\newenvironment{note}{\paragraph{Note:}}{}
\newenvironment{field}{}{}
\newenvironment{premises}{\begin{enumerate}[label=\alph*.]}{\end{enumerate}}
\newenvironment{conclusion}{}{}
This section is mainly for my own benefit, and was used to outline the code before I wrote it. Still, might be useful for those who come after!
As per the Stack default, app/
contains the executable code, src/
contains
the reusable code, and test/
contains the tests for the code in src/
, made
with the Tasty test framework, HUnit, QuickCheck, and Golden Test.
For each of the outlined transformations above, there is one file implementing that extraction and one testing it:
src/Extract.hs
andtest/Extract.hs
src/Extract/DefinitionsTheoremsLemmas.hs
andtest/DefinitionsTheoremsLemmas.hs
src/Extract/Premises.hs
andtest/Premises.hs
src/Extract/Equations.hs
andtest/Equations.hs
src/Extract/Notes.hs
andtest/Notes.hs
The src/Extract/Util.hs
and src/Types.hs
modules are imported by the
submodules of Extract
. The Main
module only imports the toplevel Extract
module, which provides a single entrypoint function. This maximizes the amount
of testable program logic.
I've used this project to experiment with the extensible-effects library, which provides an alternative to monad transformers. Its full power wasn't necessary, I currently only use it to provide a Writer monad in case I need debugging functionality.
Other newer or unusual libraries include:
- Classy Prelude
- Tasty test framework: A composable way to integrate HUnit and QuickCheck.
Data.Typeable
andData.Data
: I use these for testing. I wanted a concise way to write an HUnit assertion that the return value of a function uses a certain constructor, e.g. is aRight
. Additionally, I didn't want to collapse the information to aBool
and only seeTrue /= False
when my tests failed. Check outTest.Util
for more details. The ideas were adapted from this StackOverflow answer
Each module provides one method with the type
moduleName ∷ LaTeX → ([Error], [Notecard])
- From: http://taylor.fausak.me/2016/12/05/haskell-package-checklist/
- Use hpack, not Cabal
- extra-source-files
- doctest
- Anki txt format
- Better error messages