Creating AUCTEX macros in latex/rmarkdown mode

Greetings. R Studio noob here.

I have tried to make the transition from emacs to R Studio and would like to be able to use the keyboard commands I have been using for decades. For example, when typing in a LaTeX or R Markdown document, I would like to be able to select a block of text and type Ctrl+c Ctrl+f Ctrl+b and have the selected text be marked as bold font with \textbf{} around the selected text.

For example, from the AUCTeX manual: Changing the font

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:
C-c C-f C-b
Insert bold face ‘\textbf{?}’ text.
C-c C-f C-i
Insert italics ‘\textit{?}’ text.
C-c C-f C-e
Insert emphasized ‘\emph{?}’ text.
C-c C-f C-s
Insert slanted ‘\textsl{?}’ text.
C-c C-f C-r
Insert roman ‘\textrm{?}’ text.
C-c C-f C-f
Insert sans serif ‘\textsf{?}’ text.
C-c C-f C-t
Insert typewriter ‘\texttt{?}’ text.
C-c C-f C-c
Insert small caps ‘\textsc{?}’ text.

Unfortunately, I have not been able to figure out how to perform this using the Keyboard shortcuts.

I would be willing to create many of these shortcuts and share these with the community so that users can make the transition to R Studio easier.

It would be fantastic to be able to bring in several features users have developed muscle memory for in emacs when doing literate programming using R Markdown, Sweave and Pweave (BibTeX, RefTeX and AUCTeX) but I want to find out if it's possible before spending hours trying to perform the impossible.

Is this even possible in R Studio?

Thank you,

I'm a vi guy, so I feel your finger pain. It's possible.

  1. C-c C-f C-c can be used as a keybiinding to an addin package
  2. Write a function along the lines of
sc <- function(x)  paste0("\textsc{",x,"}")
sc("Here is text to embolden")
#> [1] "\textsc{Here is text to embolden}"

Created on 2023-10-13 with reprex v2.0.2
3. Create a package for it
4. Configure RStudio to use the package

I've only confirmed the first two.

If you get struck, suggest opening a new thread specific to making the package and/or registering the addin.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.