lervag / apy

CLI script for interacting with local Anki collection
MIT License
218 stars 17 forks source link

Question about markdown detection and LaTeX #92

Closed camoz closed 1 day ago

camoz commented 1 month ago

Markdown seems to be autodetected when adding a note via markdown files, e.g. apy add, but it can interfere with latex syntax.

For very simple latex it's fine I guess, but for more complex latex there is the risk that parts of it get interpreted as markdown and then become unusable. I have a few questions about this:

Side note: I think it's a bit unfortunate, albeit understandable, that Anki chose \[\] \(\) over $/$$ delimiters. Because, the $/$$ syntax is quite popular in markdown and is/will be supported by quite a few markdown tools. Btw there is a nice overview at the bottom of https://github.com/cben/mathdown/wiki/math-in-markdown

lervag commented 1 month ago

Hi! Just a heads up: I don't have time to answer right now; I've noticed you have several interesting and useful issues. I'm very happy to see someone interested in contributing like this, and I promise I will address them all. However, it might take a few days until I have the time to do so.

camoz commented 1 month ago

No worries! Take all the time you want and need of course. It's your project after all :) None of those issues are urgent for me, I'm just reporting on the fly what I find while I'm happily exploring apy.

But thanks for letting me know!

lervag commented 1 month ago

None of those issues are urgent for me, I'm just reporting on the fly what I find while I'm happily exploring apy.

Great, and please continue to do so! If possible, I will be very happy to improve apy where possible (within my capacity and competence).

lervag commented 1 day ago

For very simple latex it's fine I guess, but for more complex latex there is the risk that parts of it get interpreted as markdown and then become unusable. I have a few questions about this: …

To be honest, it's a little bit hard to answer here. It would be much easier to consider concrete examples of things that don't work as expected for you. Do you happen to have some examples?

Still, I'll try.

  • Is there a way (right now) to exclude latex equations from markdown conversion? Perhaps I'm missing something...

No, not really. But you can disable the markdown parsing alltogether with markdown: false in the note header.

  • Would it make sense to modify the markdown detection such that fields get only interpreted as markdown if there is not any latex? I guess this is a minor issue since one can just turn on/off markdown explicitly via markdown: false.

I'm not sure. I write plenty LaTeX and it works well for me. But I tend to write short and simple cards, so perhaps I've just not created something that triggers the conflicts/problems you see?

  • How do you personally handle this? Resort to HTML formatting when you have complex latex?

As above: I don't really have any big problems. I mostly use one of two patterns, but I use both with Markdown.

In both cases, things generally work well on my end, even when the text is parsed with the Markdown parser.

Side note: I think it's a bit unfortunate, albeit understandable, that Anki chose \[\] \(\) over $/$$ delimiters. Because, the $/$$ syntax is quite popular in markdown and is/will be supported by quite a few markdown tools.

Yes, I'll agree here. Although, Anki fields are HTML, not plain text or Markdown. Still, I think math in HTML could also be included with $/$$ tags. And it would make more sense to use <latex>...</latex> instead of [] variants. I think.

In any case, you should notice the difference between the MathJax support and the full LaTeX support. I only use full LaTeX support, and (more or less) never the MathJax variant.

lervag commented 1 day ago

I'll close the issue - feel free to continue the discussion here and provide some examples of fields that don't work as you expect here or in new issues.