How can I call org-toggle-latex-fragment
on all LaTeX fragments in an Org mode doc? I'm coming from Vim, so my instinct is to put something in the init.el
that loops through the document and looks for $
and \[
to call org-toggle-latex-fragment
on if the file extension is .org
. How can I implement this, and is this generally a good approach?
Asked
Active
Viewed 2,230 times
3

Drew
- 75,699
- 9
- 109
- 225
1 Answers
4
org-toggle-latex-fragment
is obsolete since Org 9.3. Use org-latex-preview
.
To preview all latex fragments in the buffer pass C-u
twice before calling org-latex-preview
. Note that a single C-u
before org-latex-preview
actually removes all previews. For instance, I set the keybinding C-f5
to org-latex-preview
then C-u C-f5
removes all previews and C-u C-u C-f5
preview latex fragments on the whole buffer.
Note: org-toggle-latex-fragment
has the same behavior, in case you are using an org-mode version before 9.3.
You might be also interested in org-fragtog.
Automatically toggle org-mode latex fragment previews as the cursor enters and exits them

darcamo
- 303
- 1
- 8
-
Is it also possible to set `C-f5` to what `C-u C-u org-latex-preview` does directly? If so, how to do it? – student Nov 09 '20 at 20:38
-
I'm not sure. You can set keybindings to lambda functions and call `org-latex-preview` in a lambda function (or create a named function). The trick part is passing `C-u C-u` programmatically. Maybe [this question](https://emacs.stackexchange.com/questions/21626/how-to-apply-call-interactively-to-an-interactive-command-that-accepts-the-uni) can help. – darcamo Nov 09 '20 at 22:47