TentativeConvert / LaTeX-Note-Importer-for-Anki

Add-on for the memory training program Anki, allowing to import and export notes written in LaTeX.
GNU Affero General Public License v3.0
32 stars 8 forks source link

Support tikz-cd diagrams #7

Closed rjraya closed 4 years ago

rjraya commented 4 years ago

In my study of category theory I often use tikz-cd diagrams (but please note that any other encoding of diagrams in latex would be good for me). It seems that anki does not support this diagrams at the moment. I wonder if there is a way of either:

  1. Import tikz-cd diagrams in a format that anki can read
  2. Convert them to pictures and import those pictures to anki (so I guess related to the issue #2).
TentativeConvert commented 4 years ago

This should work out of the box as long as you remember to load tikz-cd with \usepackage{tikz-cd} (and any other packages you might be using) in the preamble. See section 4.1.1 Preamble of the documentation for instructions how to edit the preamble in Anki.

rjraya commented 4 years ago

Here is the example card I tried:

% -- coding:utf-8 -- % LATEX PREAMBLE --- needs to be imported manually \documentclass[12pt]{article} \special{papersize=3in,5in} \usepackage[utf8]{inputenc} \usepackage{amssymb,amsmath} \usepackage{tikz-cd} \pagestyle{empty} \setlength{\parindent}{0in} \newcommand{\detail}[1]{{\scriptsize(#1)\par}~} \newcommand{\refs}[1]{{\scriptsize\textit{Refs: }#1\par}\hfill.}

%%% commands that do not need to imported into Anki: \usepackage{mdframed} \newcommand{\tags}[1]{\paragraph{tags: }#1\bigskip} \newcommand{\xfield}[1]{\begin{mdframed}\centering #1\end{mdframed}\bigskip} \newenvironment{field}{}{} \newcommand*{\xplain}[1]{\begin{mdframed}\texttt{#1}\end{mdframed}\bigskip} \newenvironment{plain}{\ttfamily}{\par} \newenvironment{note}{}{} % END OF THE PREAMBLE \begin{document} \tags{basic-category} \begin{note} \xfield{def: Euler function} \begin{field} \begin{tikzcd} F(S) \arrow[d, "\alpha"] & F(R) \arrow[l, "F(\pi_1)"] \arrow[d, "\gamma",dashed] \arrow[r, "F(\pi_2)"] & F(T) \arrow[d, "\beta"]\ S & R \arrow[l, "\pi_1"] \arrow[r, "\pi_2"] & T \end{tikzcd} \end{field} \end{note}

\end{document}

and here is the preamble of the card type to what is imported (basic and reversed):

% -- coding:utf-8 -- % LATEX PREAMBLE --- needs to be imported manually \documentclass[12pt]{article} \special{papersize=3in,5in} \usepackage[utf8]{inputenc} \usepackage{amssymb,amsmath} \usepackage{tikz-cd} \pagestyle{empty} \setlength{\parindent}{0in} \newcommand{\detail}[1]{{\scriptsize(#1)\par}~} \newcommand{\refs}[1]{{\scriptsize\textit{Refs: }#1\par}\hfill.}

%%% commands that do not need to imported into Anki: \usepackage{mdframed} \newcommand{\tags}[1]{\paragraph{tags: }#1\bigskip} \newcommand{\xfield}[1]{\begin{mdframed}\centering #1\end{mdframed}\bigskip} \newenvironment{field}{}{} \newcommand*{\xplain}[1]{\begin{mdframed}\texttt{#1}\end{mdframed}\bigskip} \newenvironment{plain}{\ttfamily}{\par} \newenvironment{note}{}{} % END OF THE PREAMBLE \begin{document}

Still there is an error:

error.txt

TentativeConvert commented 4 years ago

Does the file compile outside of Anki? If so, perhaps your Anki installation is using a different version of tikz-cd from the one you use natively? (The syntax for labels on arrows changed between different versions of tikz-cd.)

In any case, this does not look like a problem related to LaTeX-Note-Importer.

rjraya commented 4 years ago

Just to confirm, the file compiles outside of Anki on TexStudio. I will check the version of tikz-cd used by Anki.