I discovered that auctex's texmathp-match-switch does not check whether or not dollar signs are commented out or not, therefore i get wrong results when i all M-x `texmathp' in very specific contexts. So i wanted to redefine the function in a custom library that is loaded automatically as soon as LaTeX-Mode is invoked (by adding the library to the LaTeX-mode-hook). The relevant parts of my code are:

(require 'tex)  
(require 'latex)

(defun texmathp-match-switch (bound)
  "Search backward for any of the math switches.
Limit searched to BOUND."
  ;; The return value is like ("\\(" . (point)).
    (if (and (re-search-backward texmathp-onoff-regexp bound t)
             ;; my addition (and the `and' above):
             (not (TeX-in-commented-line)))
        (cons (buffer-substring-no-properties (match-beginning 1) (match-end 1))
              (match-beginning 1))

Unfortunalety, this naive approach doesn't work.

Whenever I am in a tex file and do M-h 'texmathp-match-switch' it says "texmathp-match-switch is an autoloaded compiled Lisp function in `texmathp.el'.". Ho do I do this the right way?

EDIT: In case, it's relevant: AUCTeX-version is 11.87; emacs-version is 24.3.1. And no, I cannot update either: "Never change a running system".

  • I can't reproduce this, could you provide more details. What I tried was putting your code in a separate file, start a new emacs, load-library on the file with your code, open a latex file, and then requested the help on your function. It still shows the function as autoloaded, but points to the new file for the definition. – Andrew Swann Nov 17 '18 at 11:37
  • @AndrewSwann The file with my code is loaded via the latex-mode-hook, that is, upon or immediately after starting latex mode, not beforehands. I'm afraid, i cant change that for it would break my and my co-workers' workflow. – Lupino Nov 18 '18 at 12:37
  • Can you show the code in your hook? – Andrew Swann Nov 18 '18 at 14:10
  • (add-hook 'LaTeX-mode-hook (lambda () (require 'letex-tex-base "tex-basis.el" nil)) t) The file with this line is loaded within my .emacs file. – Lupino Nov 19 '18 at 10:36
  • Loading via such a hook also works for me, if I add (provide 'letex-tex-base) in the file of commands. (Should letex be latex?) – Andrew Swann Nov 19 '18 at 11:10

Your Answer

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

Browse other questions tagged or ask your own question.