io12 / org-fragtog

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them
MIT License
404 stars 14 forks source link

can make this package work in markdown-mode? #16

Closed jinlin82 closed 3 years ago

jinlin82 commented 3 years ago

This package is so useful for reproducible research. But sometimes I write rmarkdown document which supports latex math too with markdown-mode. So I wonder can make this package work in markdown-mode too? Thanks.

io12 commented 3 years ago

I'm glad you find my package useful.

It should work in markdown-mode by enabling org-fragtog-mode just like in org-mode.

So you could try adding the following to your config:

(add-hook 'markdown-mode-hook 'org-fragtog-mode)

I tested this and it seems to work but let me know if you have issues.

jinlin82 commented 3 years ago

if the markdown file does not have level headings, it works, minimum example:


math $\alpha$ frag

if the markdown file has level headings, it doesn't work, minimum example:

# h1

## h2

### h3

math $\alpha$ frag

and the error message:

Error in post-command-hook (org-fragtog--post-cmd): (wrong-type-argument stringp nil)

but if I move cursor to the text line, disable org-fragtog-mode and re-enable org-fragtog-mode, it works.

Can you repeat the error and check this? Thanks.

markdown-mode version: markdown-mode-20200416.116

org-fragtog-mode version: org-fragtog-20201224.428

io12 commented 3 years ago

The latest version fixes this. Thanks!

io12 commented 3 years ago

When there is no space before and after $. math preview is not activated

This seems to be the intended behavior of Org mode.

https://orgmode.org/manual/LaTeX-fragments.html

The manual recommends using \( ... \) instead of $ ... $, which seems to work.

math\(\alpha\)frag

However, \( ... \) seems to not be supported Markdown syntax. Since org-fragtog relies on Org mode for parsing LaTeX fragments, I don't think there's much I can do here. Sorry. You might want to try something else like texfrag.