I found an effective solution here .
John Kitchen did the trick in org-mode 9.0 on
\setcounter{equation}{<num>} as a workaround for the problem. Thus, the number of equations will be automatically increased with preview fragments. It also works well in org-mode 8.2.10, which is being tested by me.
At the same time, while there is a small error. If the equation is exactly the same as the previous one, there will be a number of repetitions.
All in all, this is a really good solution.
The source code for the solution is as follows. If you want to use this function in a future session, you can add a block to the emacs configuration file, such as init.el
(defun org-renumber-environment (orig-func &rest args) (let ((results '()) (counter -1) (numberp)) (setq results (loop for (begin . env) in (org-element-map (org-element-parse-buffer) 'latex-environment (lambda (env) (cons (org-element-property :begin env) (org-element-property :value env)))) collect (cond ((and (string-match "\\\\begin{equation}" env) (not (string-match "\\\\tag{" env))) (incf counter) (cons begin counter)) ((string-match "\\\\begin{align}" env) (prog2 (incf counter) (cons begin counter) (with-temp-buffer (insert env) (goto-char (point-min)) ;; \\ is used for a new line. Each one leads to a number (incf counter (count-matches "\\\\$")) ;; unless there are nonumbers. (goto-char (point-min)) (decf counter (count-matches "\\nonumber"))))) (t (cons begin nil))))) (when (setq numberp (cdr (assoc (point) results))) (setf (car args) (concat (format "\\setcounter{equation}{%s}\n" numberp) (car args))))) (apply orig-func args))
If you do not need a function in the current session, you can remove advice using the following code. If you do not want this in a future session, just comment or delete the above block in the emacs configuration file.
(advice-remove 'org-create-formula-image #'org-renumber-environment)
I did not make any changes to the source code, just give a few instructions. John Kitchin's original work is licensed under a Creative Commons Attribution-ShareAlike 4.0 license.
source share