# How to fix 'Wrong type argument: characterp, 134217782'?

I'm using Org 8.2 on emacs 24.4, in a Windows 7 machine. Recently I've managed to install cdlatex.el script by saving this file in one of my 'load-paths'. As you may know, cdlatex is a minor mode that can work with Org-mode and helps speed up writing math in Org by the use of keyboard shortcuts. However, when in cdlatex I get this error message:

Wrong type argument: characterp, 134217782

This error appears in the mini-buffer every time I press the backquote or backtick key on my keyboard (this symbol: ).

Clearly I must add some line in the .emacs configuration file to fix this problem otherwise I'm unable to use 90% of CDLaTeX commands from keyboard. Can someone please help me out? I'm not proficient in elisp (I just copy/paste other folks lines). This is what I've got in my .emacs file regarding tilde and backquote (they respond to the same key, on my laptop's keyboard, see this question for context):

;;; a key for tilde symbol
(define-key key-translation-map (kbd "M-2") (kbd "~"))
;;; a key for backtick symbol
(define-key key-translation-map (kbd "M-6") "")
(define-key key-translation-map (kbd "M-9") (kbd ""))


# Edit 1

The reply to M-x toggle-debug-on-error is:

Debugger entered--Lisp error: (wrong-type-argument characterp 134217782)
format("No such math symbol %c on level %d" 134217782 1)
apply(format ("No such math symbol %c on level %d" 134217782 1))
error("No such math symbol %c on level %d" 134217782 1)
(if (or (not symbol) (not (stringp symbol)) (equal symbol "")) (error "No such math symbol %c on level %d" char level))
(let* ((cell (cdlatex-read-char-with-help cdlatex-math-symbol-alist-comb 1 cdlatex-math-symbol-no-of-levels "Math symbol level %d of %d: " "AVAILABLE MATH SYMBOLS.  [%c]=next level " cdlatex-math-symbol-prefix (get (quote cdlatex-math-symbol-alist-comb) (quote cdlatex-bindings)))) (char (car cell)) (level (cdr cell)) (entry (assoc char cdlatex-math-symbol-alist-comb)) (symbol (nth level entry))) (if (or (not symbol) (not (stringp symbol)) (equal symbol "")) (error "No such math symbol %c on level %d" char level)) (if (or (not (texmathp)) (cdlatex-number-of-backslashes-is-odd)) (cdlatex-dollar)) (insert symbol) (if (string-match "\\?" symbol) (progn (cdlatex-position-cursor))))
cdlatex-math-symbol()
call-interactively(cdlatex-math-symbol nil nil)
command-execute(cdlatex-math-symbol)

• If you press C-h k and then , what command does it say this key is bound to? – elethan Jan 22 '16 at 17:36
• This is what I get:  (translated from <M-kp-9>) runs the command cdlatex-math-symbol, which is an interactive Lisp function in cdlatex.el'. It is bound to  , <menu-bar> <Org> <LaTeX> <Insert math symbol>. (cdlatex-math-symbol) Read a char from keyboard and insert corresponding math char. The combinations are defined in cdlatex-math-symbol-alist'. If not in a LaTeX math environment, you also get a pair of dollars. – WobblyWindows Jan 22 '16 at 17:42
• I'd like to point out here that C-c { is working in org-cdlatex-mode, it regularly inserts a math environment such as align. However when I try to enter some other code such as - TAB then it doesn't insert \item inside an itemize environment. I also notice that if I go via menu "Org", with the mouse, then the backquote works and I'm able to insert those math symbols including Greek letters. Maybe I should change the cdlatex-math-symbol-alist? – WobblyWindows Jan 23 '16 at 10:14
• maybe try to use  on its own without binding M-9 to insert it, or have a different key to insert it (without the M modifier), just to see if this works. – elethan Jan 23 '16 at 12:43
• Mmm... that's a little complicated for a newbie like me. I'm afraid (A) I don't know how to do that, (B) doing so will jeopardize things in other situations like in auctex – WobblyWindows Jan 23 '16 at 12:51

## 2 Answers

Sounds like you have loaded byte-compiled code from an older Emacs version.

First, check by loading the Lisp source file that defines the functions in question: *.el, not the byte-compiled file (*.elc). (It sounds like the file in question might be cdlatex.el - but it might be another file.)

If that solves the problem (and it should), then you can byte-compile the library again, using your more recent Emacs version (the same version you are using at runtime). M-x byte-compile-file.

• How do I load the Lisp source file? Any keyboard magic I don't know about? Isn't it done automatically as I launch Emacs? I downloaded the script from Carsten Dominik's gitHub repo, and made sure it ended with *.el, not *.elc. I placed the file with other *.el scripts, in <C:\Program Files\emacs-24.4\share\emacs\24.4\lisp\> which is one of my load paths, as I discovered by typing C-h v RET load-path RET. Should I byte-compile 'the library' (what?), do I open an org file and then type M-x byte-compile-file? – WobblyWindows Jan 22 '16 at 21:09
• If you have no *.elc files then the *.el files will be loaded. You can move any *.elc files out of the way (out of your load-path. You can also load any file manually, using M-x load-file. E.g., you can load the *.el file using load-file, even if the *.elc has already been loaded - the *.el code will replace the *.elc code that was loaded earlier. – Drew Jan 22 '16 at 21:39
• Nope, the problem is still there. I'm using version 4.7 (2014) of cdlatex.el – WobblyWindows Jan 23 '16 at 20:01
• Trying to guess the problem from this altitude is not efficient, for me at least. Unless someone else here has a better insight or you provide a lot more info, my suggestion is to contact the maintainer of cdlatex.el. (There might even be a bug here.) In my experience, I have seen that error message when I've loaded a version of the library that was compiled with an older version of Emacs, and loading the source file (or a byte-compiled file from the same or similar Emacs version) solved it. That's all. – Drew Jan 23 '16 at 21:02
• Correct me if I'm wrong, basically there's a conflict of versions between Emacs and cdlatex.el? I may have downloaded a version of cdlatex.el that maybe is not meant for Emacs 24.4? – WobblyWindows Jan 23 '16 at 21:12

I found a work-around by remapping backquote (or back-tick). In my .emacs file I wrote:

(define-key key-translation-map (kbd "C-1") (kbd ""))

;;; how to tell cdlatex that it should keep Org-mode's backquote symbol?
;(eval-after-load "cdlatex"
;  '(define-key minor-mode-map (kbd "M-9") nil) ; clean it up
;  '(define-key minor-mode-map (kbd "M-9") (kbd ""))) ; now set it


I tried the second part, the one that's commented out but it gave me trouble so I left it out. This remapping allows me to enter the math symbols menu by invoking backquote. Once inside I can cycle through the 3 levels of symbols by pressing @. Sure enough I changed the backquote character necessary to cycle and put instead 'at the rate of' with the commands @Drew suggested above: M-x customize-option RET cdlatex-math-symbol-prefix RET.

In case I need to escape backquote I can type C-q .