louietan / anki-editor

Emacs minor mode for making Anki cards with Org
705 stars 87 forks source link

Lines ending with '\)', '\]' are replaced incorrectly with '[/$]' #17

Closed tigoesnumb3rs closed 6 years ago

tigoesnumb3rs commented 6 years ago

Hey there,

great package you wrote, I found it yesterday and have been looking for something similiar for a long time already! :)

One of the first things I ran into was making cards containing pseudocode. After a bit of searching I found the alltt environment, which allows for code blocks which include math symbols (To make alltt work in anki you can put the \usepackage{alltt} into the cards latex header by going to Tools/Manage Note Types/Options).

So at first everything worked great, however I sometimes got errors, in my code blocks..

When you write something like:

\begin{alltt}
for i in \(\mathcal{M\sb{\epsilon}}\):
  do something 
\end{alltt}

everything just works fine. When I however have lines ending with \) or \], I get latex errors in anki. The following for example does not work:

\begin{alltt}
for i in \(\mathcal{M\sb{\epsilon}}\)
  do something 
\end{alltt}

In anki [/$] is created at the end of the line, but since there is no opening [$], anki can't compile the generated latex code. Also this happens inside the [latex] ... [/latex] region, where it shouldn't replace \) with the anki specific notation, from what I understand, since the whole region will be compiled as a whole anyway.

I haven't looked at the code, but I guess at some point it seems to replace \) and \] always, when they are at the end of a line.

Oh also for anyone else who runs into this problem: if you insert a whitespace behind the \), the line does not end with \) anymore and everything will work fine in anki.

Really great package! :)