Assume that I have mistakenly written $\signa$ instead of $\sigma$ in a TeX file. Considering the fact that all correct math commands are stored in the file latex.el under LaTeX-math-default constants, is it possible that Emacs detect this error?

More precisely is it possible that Emacs detects that \signa does not belong to the list of commands in latex.el under LaTeX-math-default?

Obviously after compiling the tex file, one can discover this error. But my question is about the detection of this error at Emacs level. Also assume that ispell is not at disposal.

Edited: After the comment of Giordano let me make it precise that I am interested in checking the correctness of a single math command not the entire document. Defining a function which detects that \signa does not belong to the list of commands provided by Latex-math-default when the cursor is at \signa would be perfect.

  • 1
    Use flymake or flycheck, they are made exactly for that purpose. The only problem with latex as syntax checker is that it is extremely slow for large document. There are other syntax checkers for latex but they are not as reliable as latex itself.
    – giordano
    Commented Jan 25, 2015 at 17:06
  • @giordano I am interested to check the correctness of the syntax of a single command like \signa (not the entire document). As I explained above I thought as the correct syntax are already available to Emacs via Latex-math-default, a simple solution is perhaps conceivable. Let me make it precise it at the body of my question. By the way I couldn't find flycheck on my Emacs.
    – Name
    Commented Jan 25, 2015 at 17:40

1 Answer 1


You can get the symbol the point is on using symbol-at-point. Then just check if it is LaTeX-math-default. There are various ways to do the test, but you have to deal with the fact that LaTeX-math-default is list of 4-tuples and you only care about the second element.

Here's one way to do it. It returns nil if the symbol is not in the the list and the element otherwise.

(defun test-latex-symbol-at-point ()
  (let ((sym (symbol-at-point)))
    (TeX-member sym LaTeX-math-default
            (lambda (a b)
              (string= a (nth 1 b))))

Of course this will fail on any custom commands you've defined or that are in packages you've loaded. You're likely to see a lot of spurious errors in a complex document. Like other commenters mentioned, this is what flycheck is for. Install it with M-x package-install flycheck and turn it on with M-x flycheck-mode.

  • Thank you. I executed your function test-latex-symbol-at-point at $\sigma$ also at $\signa$, nothing happens. If I understand well what you said, executing it at $\signa$ should gives the value nil to test-latex-symbol-at-point but evaluating it at $\signa$ and $\sigma$ is the same. Maybe I miss something.
    – Name
    Commented Jan 25, 2015 at 21:49
  • 1
    This function just returns nil or non-nil. Try running (if (test-latex-symbol-at-point) (message "valid") (message "invalid"))
    – erikstokes
    Commented Jan 25, 2015 at 22:21
  • There should be a problem, evaluating (if (test-latex-symbol-at-point) (message "valid") (message "invalid")) for both $\sigma$ and $\signa$ gives the message "invalid"
    – Name
    Commented Jan 25, 2015 at 22:31
  • This is a terrible answer, but it works on my machine. Does it work if you start clean emacs (emacs -Q) and just load auctex?
    – erikstokes
    Commented Jan 25, 2015 at 22:35
  • I confirm that your code perfectly works. Many thanks.
    – Name
    Commented Jan 26, 2015 at 9:29

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.