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?


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

  • 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 9 '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 can help. – darcamo Nov 9 '20 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.