5

I wanted to make a macro that inserts \left \right delimiters, but I wanted to write it only once and have different bindings pass different delimiters. To wit, I wanted to add the following code:

(setq LaTeX-math-list (quote ( ("C-(" (LaTeX-my-leftright "(" ")") "" nil)
    ("C-{" (LaTeX-my-leftright "\{" "\}") "" nil)
    )))

Where the program does the following:

(defun LaTeX-my-leftright (charopen charclose)
"Inserts the pattern '\leftC  \rightD' where C is the open input char and D the closed, and places the cursor in the center."
    (interactive)
    (setq out1 (concat "\\left" charopen " "))
    (setq out2 (concat " \\right" charclose))
    (insert out1)
    (push-mark)
    (insert out2)
    (exchange-point-and-mark)
)

However, when I run this by pressing ` and then C-( I get a

Wrong type argument: commandp (LaTeX-my-leftright "(" ")")

error message.

Does anyone know what the correct syntax is here, or if this is even possible with LaTeX-math-list? I've looked a little bit at the latex.el file and I'm beginning to think the answer is no, but maybe I missed something.

6

The value slot needs to be a 0-argument interactive function not an evaluated expression, also \{ needs an extra level of \ quoting to get the backslash into the lisp string.

This seems to work

(setq LaTeX-math-list (quote ( 
    ("C-(" (lambda ()(interactive)(LaTeX-my-leftright "(" ")")) "" nil)
    ("C-{" (lambda ()(interactive)(LaTeX-my-leftright "\\{" "\\}")) "" nil)
    )))

Your Answer

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

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