0

In AUCTex, my font-latex-math-face has green color that also colors $ $ or \( \) into green as well. Here I just want to have different color for dollar sign than font-latex-math-face's

enter image description here

Is it possible to change the color of dollar sign and \( \) into different color?

As example built-in math-mode at tex.stackexchange.com/ has this feature where dollar-sign shows up in different color:

enter image description here

1
  • It is bothersome to recreate text from screen. Put the math in a text block, so that it is easy to copy-paste.
    – user31220
    Oct 21, 2022 at 4:28

1 Answer 1

2

If you want this

$ math delimiter gets its own face

$ math delimiter gets its own face

instead of this

$ math delimiter has same face math text

$ math delimiter has same face math text

do this


(defface font-latex-dollar-face
  '((t :foreground "lime green"))
  "Face for tikzpicture environment."
  :group 'font-latex-highlighting-faces)

(eval-after-load 'font-latex
  (advice-add
   'font-latex-match-dollar-math :around
   (defun font-latex-match-dollar-math--around
       (orig-fun &rest orig-args)
     (pcase-let*
         ((`(,limit)
           orig-args)
          (val (apply orig-fun orig-args))
          (beg (when val
                 (match-beginning 0)))
          (end (when val
                 (match-end 0))))
       (when (and beg
                  end
                  (save-excursion
                    (goto-char beg)
                    (looking-at-p (rx "$"))))
         (set-match-data
          (save-excursion
            (list
             (let* ((beg beg)
                    (end (progn (goto-char beg)
                                (skip-chars-forward (rx "$"))
                                (point))))
               (prog1 end
                 (add-text-properties beg end '(
                                                face font-latex-dollar-face
                                                fontified t))))
             (let* ((end end)
                    (beg (progn (goto-char end)
                                (skip-chars-backward (rx "$"))
                                (point))))
               (prog1 beg
                 (add-text-properties beg end '(face font-latex-dollar-face
                                                     fontified t)))))))
         val)))))

;; (advice-remove 'font-latex-match-dollar-math 'font-latex-match-dollar-math--around)

2
  • Even I read the manual I was not able to come up with this solution :-) I don't understand how it works but it works like magic, thanks.
    – alper
    Oct 22, 2022 at 12:06
  • How can this solution be extended to include \(, \(, \[ and \]? Feb 21 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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