ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.52k stars 2.21k forks source link

LaTeX with Cloze displays incorrectly #2598

Closed hssm closed 9 years ago

hssm commented 9 years ago

Originally reported on Google Code with ID 1696

What steps will reproduce the problem?
1. Create a Cloze note with the following content:

[latex]
Formula for a Gaussian pdf: $f_X(x)=\frac{1}{ {{c1::\sqrt{2\pi\sigma} }} }e^{-\frac{
{{c2::(x-\mu)^2}} }{ {{c3::\sigma^2}} } }$
[/latex]

This is a problem for other mixed LaTeX-Cloze notes as well.

2. Sync to AnkiDroid
3. Attempt to review it.

What is the expected output? What do you see instead?
The expected output is what I see in Anki. It displays correctly there. In AnkiDroid,
I see a box with a question mark for all three cards generated.

Does it happen again every time you repeat the steps above? Or did it
happen only one time?
Every time.

What version of AnkiDroid are you using? (Decks list > menu > About > Look at the title)
On what version of Android? (Home screen > menu > About phone > Android
version)
AnkiDroid version 2.0.1.
Android version 4.0.3

If it is a crash or "Force close" and you can reproduce it, the following
would help immensely: 1) Install the "SendLog" app, 2) Reproduce the crash,
3) Immediately after, launch SendLog, 4) Attach the resulting file to this
report. That will make the bug much easier to fix.

Please provide any additional information below.
This is neither a crash nor a force close. However, in the event that it proves useful,
I have included a log anyway.

Reported by paulbunc on 2013-02-26 03:28:45


hssm commented 9 years ago
I've figured out at least part of the problem. Sometimes one of the Cloze deletions
will cause LaTeX compilation to fail, but when you click "Card" it only shows you the
picture or failure information for the card without any deletions applied. As a result,
some of the generated cards will display correctly in AnkiDroid and some won't, because
they weren't generated correctly in the first place. In fact, I'm not entirely sure
if the Cloze deletion pictures are even generated before you review them for the first
time in Anki.

Reported by paulbunc on 2013-02-28 03:45:29

hssm commented 9 years ago
After additional experimentation, viewing each generated card in Anki and then syncing
only fixes the problem some of the time. Some cards display correctly in Anki but not
in AnkiDroid. Example:

[$$]{{c1::\text{Profit} }}=({{c2::P}}-{{c3::AC}})\times {{c4::Q}}=\left(\frac{ {{c5::TR}}
}{ {{c4::Q}} }-\frac{ {{c7::TC}} }{ {{c4::Q}} }\right)\times {{c4::Q}}[/$$]

c7 was up for review.

Oddly enough, adding this note to a new test deck ("Profit" has been changed to "Profitness"
so the cards don't conflict), reviewing each card on Anki, and then syncing enables
me to see the new cards in the test deck. After deleting and recreating the original
note it now displays correctly, but I've lost all the review data associated with it.
Even then, only some of the cards displayed correctly. I deleted it again, and this
time cleared unused media, checked the database, and did a full sync, and now they
all display correctly. I'm still not sure what caused the original problem, and I'd
prefer not to have to do this frequently.

Reported by paulbunc on 2013-03-04 00:59:18

hssm commented 9 years ago

Reported by nicolas.raoul on 2013-03-13 06:35:07

hssm commented 9 years ago
I think I've worked out what causes it, it's a combination of problems with Anki Desktop
- first, the images are not generated when adding a new note - they are only generated
for a given card when you review that card. This means that they won't display correctly
in AnkiDroid until you've seen them once in Anki and synced. Second, clicking "Card"
wasn't intended to generate all associated images for a note - it just generates enough
to show a sample card. Image generation is left to Unused Media, which is the third
problem: Unused Media does not correctly generate cards containing cloze deletions
within LaTeX blocks - it evaluates the LaTeX without performing the cloze substitutions,
so only one image is generated for each note and that image is generated incorrectly
(it contains cn:: all over the place, where n is an integer). Furthermore, Unused Media
identifies all the images generated by LaTeX blocks containing cloze deletions as unused,
so if you don't know that and tell it to delete unused media, then those images are
gone and you can't get them back until you review the cards on Anki Desktop again,
which (depending on the interval) could take weeks to months to years. As such, I currently
have no reason to believe that AnkiDroid or AnkiWeb are to blame. I've filed issues
for Anki Desktop for these issues and they've been accepted.

Reported by paulbunc on 2013-03-13 13:06:30

hssm commented 9 years ago
I see this problem too. It happens as Anki get confused between the {} of Latex when
there are two of them (for instance, when you use \frac{}{}) and the {} of the cloze
itself.
Is there any fix?

Reported by omerros on 2015-01-16 14:02:15

hssm commented 9 years ago
If someone could attach a sample deck that exhibits this issue I will take a look at
it. I'm doing some work right now on the bits that handle parsing cloze tags so it
could be related to (or even the same) issue here.

Reported by Houssam.Salem.Au on 2015-01-17 07:29:32

hssm commented 9 years ago
Great,
I just created a short example that demonstrates it clearly:

Sulfuric acid in water is {{c1::[$]H_2SO_{4_{(aq)}}[/$]}}

As you can see, the problem is that LaTeX requires '}}', but Anki parses this is the
end of the cloze.
If that's not clear I can easily create more samples.

Reported by omerros on 2015-01-17 07:44:01

hssm commented 9 years ago
Actually, having read comment #5 I don't think this is an AnkiDroid problem but something
the desktop client needs to fix first. It's unrelated to the issue I thought this was,
so I'm going to leave it for now.

Reported by Houssam.Salem.Au on 2015-01-17 07:49:06

hssm commented 9 years ago
The previous poster has already mentioned them being raised and accepted on the desktop
end of things.

Reported by Houssam.Salem.Au on 2015-01-17 07:52:46

hssm commented 9 years ago
I wasn't able to find the relevant thread. Can you please share a link?

Reported by omerros on 2015-01-17 07:54:39

hssm commented 9 years ago
https://anki.lighthouseapp.com/projects/100923/tickets/54-cant-cloze-latex-text-that-contains

Reported by Houssam.Salem.Au on 2015-01-17 07:58:03

hssm commented 9 years ago
Thanks! I seem to have a silly question, it's a private project so it requires me to
login but I have no account. Is there a sign up page somewhere?

Reported by omerros on 2015-01-18 09:28:20

hssm commented 9 years ago
I don't remember how I created my account. Maybe it was by invite. Anyway, there is
a section in the manual about this issue with a workaround for this exact problem:

http://ankisrs.net/docs/manual.html#latex-conflicts

Reported by Houssam.Salem.Au on 2015-01-18 23:57:12

hssm commented 9 years ago
Great, thanks!

Reported by omerros on 2015-01-19 09:10:31

hssm commented 9 years ago
Closing since we are consistent with Anki Desktop

Reported by perceptualchaos2 on 2015-06-04 02:25:50