Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add a space between two curly braces inside a Latex block to avoid conflicts with the cloze syntax #313

Open
RoamanEmpire opened this issue Jan 21, 2022 · 3 comments · May be fixed by #508
Labels
waiting-for-response Waiting for OP response (maybe stale)

Comments

@RoamanEmpire
Copy link

RoamanEmpire commented Jan 21, 2022

Here is an example of a cloze card containing a latex formula

Formula: {{c1:: $f(x) = \frac{1}{\sqrt{x}}$}}

Unfortunately, the two curly braces after sqrt{x conflict with Anki's cloze syntax which also expects two }}. A simple solution would be to add a space between the two curly braces at runtime, right before creating the card in Anki, as shown below.

Formula: {{c1:: $f(x) = \frac{1}{\sqrt{x} }$}}
@niposch
Copy link
Contributor

niposch commented Jan 25, 2024

Got a pr that resolves this issue #508

@ShootingKing-AM
Copy link
Member

I think this issue has nothing to do with this plugin. Seems like a bug with Anki's Cloze syntax and its inter-op with math formating. Or am i misunderstanding something ?

@ShootingKing-AM ShootingKing-AM added the waiting-for-response Waiting for OP response (maybe stale) label Jan 25, 2024
@niposch
Copy link
Contributor

niposch commented Jan 25, 2024

@ShootingKing-AM addressing this here is sensible imo.
Anki mentions in their documentation, that double curlies cause issues when they aren't meant to end a cloze when inside a math expression that is contained within a cloze.

Cloze deletions are terminated with }}, which can conflict with a }} appearing in your LaTeX. To prevent LaTeX from being interpreted as a closing cloze marker, you can put a space between any double closing braces that do not indicate the end of the cloze - anki documentation https://docs.ankiweb.net/math.html#cloze-conflicts

So I could do something like this in anki: \(z^2 = {{c1:: x^2 + y^2}}\) and it would create a cloze inside the math. Here, a double closing curly brace is intended to be placed and it works fine.
However, when we do something like this: {{c1::\(\frac{\frac{1}{2}}{3}\)}} the documentation advises users to create it like this {{c1::\(\frac{\frac{1}{2} }{3}\)}} to avoid issues with ending the cloze prematurely and therefore breaking the math.

I've run in this issue quite frequently and manually adjusting my notes to avoid it is sometimes a bit of a pain as it is only during the review of the notes that the issue becomes apparent and having to frequently stop doing my anki reps just to fix up the notes is a pain.
On top of that the fix is rather simple. Add a space in front of every double curly that isn't part of a cloze inside a math block. We have the cloze regex directly from the anki source code so implementing this shouldn't be an issue.
https://github.com/ankitects/anki/blob/29f9f0dca7799cf270eb41c51a9db0c3ad9fa47d/ts/editable/mathjax.ts#L85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-response Waiting for OP response (maybe stale)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants