io12 / org-fragtog

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

No space before and after $. math preview is not activated #17

Closed jinlin82 closed 3 years ago

jinlin82 commented 3 years ago

sorry to bother again, this works great in markdown-mode, thanks. But I have a small problem.

When there is no space before and after $. math preview is not activated, for example:

math $\alpha$ frag, this line works.

math$\alpha$frag, this line doesn't.

When in English math fragment always have space before and after $, but when in Eastern Asian languages, no space before and after $ is common.

Can this be fixed? Thanks.

io12 commented 3 years ago

https://github.com/io12/org-fragtog/issues/16#issuecomment-752853936

jinlin82 commented 3 years ago

Thanks, I come up with a function by regexp which adds space before and after $ for each inline latex fragment in selected region, then org-fragtog works. The function is:

(defun math-delimiter-add-space-inline(beg end)
  (interactive "*r")
  (let ((beg (if (region-active-p)
                 (region-beginning)
               (line-beginning-position)))
        (end (if (region-active-p)
                 (region-end)
               (line-end-position))))
    (save-restriction
      (narrow-to-region beg end)
      (save-excursion
    (goto-char (point-min)) 
    (while 
        (search-forward-regexp " *\\$\\([^$].*?[^$]\\)\\$[^$] *" nil t)
      (replace-match " $\\1$ " nil nil))))
    ))

So I close this issue.