# Error adding new value to LaTeX-math-list with custom function

I am using Auctex with math mode enabled. One of my favorite features is insert \mathcal with the key sequence "[backtick] c". I decided to try and customize the variable LaTeX-math-list so I can do something similar for \mathbb. Borrowing the code for the function LaTeX-math-cal, I added following code to my .emacs file:

(defun my-LaTeX-math-mathbb (char dollar)
"Insert {\Bbb CHAR} or \mathbb{CHAR} if latex2e is in TeX-style-list.  If DOLLAR is non-nil, put $'s around it." (interactive "*c\nP") (if dollar (insert "$"))
(if (member "latex2e" (TeX-style-list))
(insert "\\mathbb{" (char-to-string char) "}")
(insert "{\\Bbb " (char-to-string char) "}"))
(if dollar (insert "\$")))

(setq LaTeX-math-list ())
(add-to-list 'LaTeX-math-list '("=" 'my-LaTeX-math-mathbb "" nil))


However when I try to type th sequence "[backtick] =" I get the following error message:

Wrong type argument: commandp, (quote my-LaTeX-math-mathbb)


When I manually evaluate the expression (commandp 'my-LaTeX-math-mathbb) in the scratch buffer, the expression returns true, so I am perplexed as to why I receive the error message.

P.S. I am using = for the binding only as a temporary measure during testing because this symbol had no previous definition in math mode.

• Remove the quote before my-LaTeX-math-mathbb in the last line ;-) – giordano Sep 10 '14 at 17:41
• Thanks @giordano! My lisp skills are still pretty light, so I am still not sure about when I need to quote my variables. Do you have a recommendation for where I could see why this is so? My understanding was that the unquoted expression would evaluate to it's variable value, which would be void. Regardless, I will read a bit and post an answer later explaining the subtlety for future readers. – Carl Morris Sep 10 '14 at 17:54
• The entry you are adding to LaTeX-math-list is a quoted list, so you don't need to quote its elements. See the difference between (nth 1 '("=" 'my-LaTeX-math-mathbb "" nil)) and (nth 1 '("=" my-LaTeX-math-mathbb "" nil)). HTH – giordano Sep 10 '14 at 18:04
• @giordano, the return values of those two expressions definitely explain why the function call was not working. I think I am bit a clearer, though the return value of (nth 1 '("=" 'my-LaTeX-math-mathbb "" nil)) is still a bit perplexing to me. – Carl Morris Sep 12 '14 at 15:16