1

This is essentially a modified question of 1 but with math fonts instead.

What I want is an AucTex command to add to my .emacs to do the following:

If I'm outside a math environment like equation or outside a pair of dollar signs $, If I press `1 C, $\mathbb{C}$@ is inserted in the buffer where @ denotes the position of the cursor. However, if I'm inside a math environment or inside a a pair of dollar signs, only \mathbb{C}@ is inserted. I want `2 C to do the same as `1 C but with \mathcal instead. The insertion of math fonts is very common, so this would save a bit of time. I tried modifying the answer of @giordano but I couldn't do it.

2 Answers 2

1

Maybe you can use the font specifier facility provided by AUCTeX: When you're in math mode and you press C-c C-f C-a, it inserts \mathcal{@} and if you mark a portion of text, say C, and hit the keystroke, it inserts \mathcal{C@} (@ donates the cursor position). You get the same thing for \mathbb by hitting C-c C-f C-b. The keystrokes are stored in LaTeX-font-list which is pre-defined like this:

(defcustom LaTeX-font-list
  '((?\C-a ""              ""  "\\mathcal{"    "}")
    (?\C-b "\\textbf{"     "}" "\\mathbf{"     "}")
    (?\C-c "\\textsc{"     "}")
    (?\C-e "\\emph{"       "}")
    (?\C-f "\\textsf{"     "}" "\\mathsf{"     "}")
    (?\C-i "\\textit{"     "}" "\\mathit{"     "}")
    (?\C-l "\\textulc{"    "}")
    (?\C-m "\\textmd{"     "}")
    (?\C-n "\\textnormal{" "}" "\\mathnormal{" "}")
    (?\C-r "\\textrm{"     "}" "\\mathrm{"     "}")
    (?\C-s "\\textsl{"     "}" "\\mathbb{"     "}")
    (?\C-t "\\texttt{"     "}" "\\mathtt{"     "}")
    (?\C-u "\\textup{"     "}")
    (?\C-w "\\textsw{"     "}")
    (?\C-d "" "" t))
  "Font commands used with LaTeX2e.  See `TeX-font-list'.")
1
  • This is not exactly what I've asked but it's close. I think I should try to modify that TeX-font-list and/or LaTeX-font-list, right?
    – Zero
    Commented Jun 12, 2023 at 17:29
0

It turned out to be simpler than I thought. To get the desired effect with \mathcal, just add the following to .emacs

(defun my-LaTeX-math-cal (char dollar)
  (interactive "*c\nP")
  (if (texmathp)
      (LaTeX-math-cal char dollar)
    (LaTeX-math-cal char t))
    )

and then bind my-LaTeX-math-cal to whatever shortcut. Similar things can be done for \mathbb and \mathfrak.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .