Disclaimer: This is a question about Emacs and AUCTeX. Sorry if this is out of the scope of tex.sx.

How can I add a new command to AUCTeX?

I want my AUCTeX mode to have the command C-c C-f C-p insert a \pname{ } and behave similarly to the other ways of changing fonts, e.g. C-c C-f C-e for \emph{ }.

The manual page Changing the font, explains that

AUCTeX provides convenient keyboard shortcuts for inserting macros which specify the font to be used for typesetting certain parts of the text. They start with C-c C-f, and the last C- combination tells AUCTeX which font you want

Font list:   KEY        TEXTFONT           MATHFONT

         C-a                          \mathcal{ }  
         C-b        \textbf{ }         \mathbf{ }  
         C-c        \textsc{ }                     
         C-e          \emph{ }                     
         C-f        \textsf{ }         \mathsf{ }  
         TAB        \textit{ }         \mathit{ }  
         RET        \textmd{ }                     
         C-n    \textnormal{ }     \mathnormal{ }  
         C-r        \textrm{ }         \mathrm{ }  
         C-s        \textsl{ }         \mathbb{ }  
         C-t        \texttt{ }         \mathtt{ }  
         C-u        \textup{ }                     
         C-d  -- delete font

I want to bind the command C-c C-f C-p to \pname{ } in AUCTeX mode.

  • 1
    Not completely inappropriate, but there is now an emacs site. It's still beta, too, so it could use the traffic. – jon Apr 20 '15 at 3:02

AUCTeX actually makes this very easy: customize LaTeX-font-list.

(add-to-list 'LaTeX-font-list
  '(?\C-p "\\pname{" "}"))

should work. You'll have to re-run LaTeX-mode in the appropriate buffers if you have any open.

Note that this must be done after LaTeX-font-list has been defined in latex.el. Here is a simple configuration with use-package:

(use-package latex
  :ensure auctex
  (add-to-list 'LaTeX-font-list
               '(?\C-p "\\pname{" "}")))
  • Whoa. That's a cool-looking package! – jon Apr 20 '15 at 5:20
  • @jon It is pretty neat :) Simplified my config like you wouldn't believe. – Sean Allred Apr 20 '15 at 12:31

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.