latexmk
uses hashing to determine whether a file was changed. The hash algorithm used is md5
, it isn't completely secure but this isn't really important in this respect. So you can use a hash-based test instead of (buffer-modified-p)
. The following code should work:
(setq current-buffer-hash nil)
(make-variable-buffer-local 'current-buffer-hash)
(defun my-run-latex ()
(interactive)
(if (equal current-buffer-hash
(setq current-buffer-hash (secure-hash 'md5 (current-buffer))))
(TeX-view)
(setq TeX-save-query nil)
(TeX-save-document (TeX-master-file))
(TeX-command "Latexmk" 'TeX-master-file -1)))
As pointed out by @student, the function secure-hash
was introduced in Emacs 24.2. For previous versions one can use (md5 (current-buffer))
.