Open Mjvolk3 opened 1 year ago
I have now experience many issue when sending cards with Latex. My solution to this problem is to copy paste the Latex instance that failed directly in to the Anki GUI Mathjax inline or block editor. In every one of my instances this has worked perfectly. It seems that the Latex is getting jumbled up in an attempt to translate it to Mathjax, which might not be necessary. I can provide all of the failed instances if it is helpful.
LaTex is not the same as Mathjax; therefore the syntax will be different.
You can test your Latex with overleaf.com before you send it to Anki
The following code may help to get you started.
# latex
## Latex
$\hat{\mathcal{D}} \approx \mathcal{D}$
using
$\mathcal{X} = \{ {\mathbf{x}_1, \ldots, \mathbf{x}_n} \}$
Note: It would help others to understand your issue if you indicate Issue and a screenshot of the Expected results in your comments.
Following will also work
# Mathjax on back
## Mathjax on back
$ \hat{\mathcal{D}} \approx \mathcal{D} $
using
$ \mathcal{X} = \left \{ {\mathbf{\frac{x}{y}}_1, \ldots, \mathbf{x}_n} \right \} $
@rleyvasal I think you made a typo, but I get the point.
screenshot
I'll try to clarify my issue and my fix.
Goal: Learn an approximation $\hat{\mathcal{D}} \approx \mathcal{D}$ using $\mathcal{X}=\left\{\mathbf{x}_{1}, \dots, \mathbf{x}_{n}\right\}$
screenshot
screenshot
_
is being translated to <em>
and </em>
.$\hat{\mathcal{D}} \approx \mathcal{D}$ using $\mathcal{X}=\left\{\mathbf{x}_{1}, \dots, \mathbf{x}_{n}\right\}$
screenshot
$$
\hat{\theta}_{\mathrm{MAP}}=\operatorname{argmax}_{\theta} p\left(\theta \mid \mathbf{x}_{1: n}\right)
$$
screenshot
screenshot
screenshot
@Mjvolk3
The problem is not with the Anki for VSCode extension. The issue is with the way the Latex is beign entered into vscode.
As a rule of thumb for subscripts if there is only one character {}
are not needed, but when there are two characters as {1+m}
, then the {}
should be used such as the case below.
# test
## test
Goal: Learn an approximation $ \hat{\mathcal{D}} \approx \mathcal{D} $
using
Your example `\mathbf{x}_{1}`
$ \mathcal{X} = \left \{ \mathbf{x}_{1}, \dots, \mathbf{x}_{n} \right \}$
My example `\mathbf{x}_{1+m}` adnd `\mathbf{x}_n`
$ \mathcal{X} = \left \{ \mathbf{x}_{1+m}, \ldots, \mathbf{x}_n \right \} $
@rleyvasal How do you explain that things work when I copy the latex that contains _{x}
into the MathJax inline/block in Anki? This can be seen in the first example I provided. This is the point I don't get.
Thanks for showing work arounds. Ideally, I could find all of the necessary work arounds and implement them in my Latex, but for some of my examples, like example 2 shown, I haven't been able to find a proper work around. If you have the time, would you mind taking a look at that example?
This is very likely a bug.
Latex below does not show correctly when sending from VSCode to Anki, but entering the same code without in the Anki app (without `$$ ..$$
) as a Mathjax block gives the correct math symbols.
$$
\hat{\theta}_{\mathrm{MAP}}=\operatorname{argmax}_{\theta} p\left(\theta \mid \mathbf{x}_{1: n}\right)
$$
The issue may be happening in one of the following:
$...$
has the same issue) . @jasonwilliams may be in a better position to diagnose the issue.
I've only taken a brief look at this issue. It sounds like we would need some escape hatch whenever latex is involed so it's not interpreted as markdown (for e.g _
being <em>
) I don't know if that should fix it?
I'm guessing the fix would need to be here somewhere: https://github.com/jasonwilliams/anki/blob/main/src/markdown/parsers/cardParser.ts#L146-L167
I don't use latex myself so I don't think I would be the best person to debug it but I'm happy to help guide anyone who wants to take a look. I really appreciate the test cases put in here, especially from @Mjvolk3, from what I can see in his comment is the markdown parser is changing some things as it has no awareness of latex syntax.
It could be the Markdown parser is not parsing the underscore correctly e.g. CommonMark, or Pandoc(not sure what is being used)
We use marked.
In fact.. Here's an issue on marked where someone raised the same thing about _
https://github.com/markedjs/marked/issues/1538
I think there's more than enough solutions in that thread we could take and use, it would just take someone to make a PR
Card in VsCode
What are the classical approaches to Density Estimation? Briefly describe their procedures and important differences.
Density Estimation: Learn an approximation $\hat{\mathcal{D}} \approx \mathcal{D}$ using $\mathcal{X}=\left{\mathbf{x}{1}, \ldots, \mathbf{x}{n}\right}$
... Apparently github rendering doesn't like it either when I copy paste. I have provided a pic of the raw latex.
Card in Anki
Anyone know what this is happening? It makes it difficult to tell which equations render incorrectly before sending the cards to deck.