I have the following skeleton pair setup to quickly insert LaTeX fragents into org-mode documents:

(setq skeleton-pair t)
(global-set-key (kbd "$") 'skeleton-pair-insert-maybe)

This works. But the trouble is that it works everywhere. How can I limit this behavior, so that it affects the body text of Emacs org documents (i.e., not applied to babel code-blocks)?


While I can't tell you anything about skeletons, you can try the following:

(define-key org-mode-map (kbd "$")
  (lambda ()
    (if (org-in-block-p '("SRC" "EXAMPLE"))
        (self-insert-command 1)
      (self-insert-command 2)

The binding works only for org-mode and inserts $$ if the cursor is not in BEGIN_SRC or BEGIN_EXAMPLE blocks. Otherwise it inserts only one $.

You can adjust block names you want to avoid double $ to be inserted -- I know not that much about block names in org but I believe you can figure it out.

PS Short demo: https://youtu.be/h4Gxl0zRk5Y

| improve this answer | |
  • Perfect! Thanks @Maxim Kim – Adam Mar 12 at 9:00

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.