The doc string of org-latex-preview
says
(org-latex-preview &optional ARG)
Toggle preview of the LaTeX fragment at point.
If the cursor is on a LaTeX fragment, create the image and
overlay it over the source code, if there is none. Remove it
otherwise. If there is no fragment at point, display images for
all fragments in the current section.
With a ‘C-u’ prefix argument ARG, clear images for all fragments
in the current section.
With a ‘C-u C-u’ prefix argument ARG, display image for all
fragments in the buffer.
With a ‘C-u C-u C-u’ prefix argument ARG, clear image for all
fragments in the buffer.
The C-u
prefixes pass an optional ARG
to the function:
C-u
passes the argument '(4)
, i.e. a list of one element, the number 4.
C-u C-u
passes the argument '(16)
.
C-u C-u C-u
passes the argument '(64)
.
Basically every additional C-u
multiplies the previous value by 4. See the Numeric Arguments section of the Emacs manual and the Prefix Command Arguments in the Emacs Lisp manual for these and other forms of prefix arguments.
In this case, what you need to do is call the function with an argument of '(16)
. So define a command that does that:
(defun my/org-preview-all-latex-fragments-in-buffer ()
(interactive)
(org-latex-preview '(16)))
and bind it to the key of your choice:
(define-key org-mode-map (kbd "C-c p") #'my/org-preview-all-latex-fragments-in-buffer)