Reputation: 2226
I am slightly new to emacs. I am editing a document in latex and I have words that I would like to put in italics. I would like a simple macro where if I place a cursor on the word, and hit a key combination the word is sorrounded with italics like this \textit{word}
.
Is there a plugin or a quick way to achieve this or an emacs-lisp macro?
Upvotes: 2
Views: 295
Reputation: 3811
Personally, I use AUCTeX
for TeX/LaTeX editing in emacs
. There is a number of good tutorials on how to use it out there, e.g. A simpleton's guide to (…)TeX workflow with emacs or Emacs as the Ultimate LaTeX Editor. To answer your question: yes this is possible and AUCTeX
provides the tools:
The relevant chapter in the manual is Changing the Font, excerpt from manual:
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-i
Insert italics ‘\textit{∗}’ text.
If you execute the command with an active region it will place that region into the argument of the formatting command. Without a region, the formatting command will be inserted and you and enter the desired content.
By combining this with a package such as expand-region
or thing-cmds
you can change the format of a word in to steps
expand-region
/ mark-thing
AUCTeX
One could combine those two steps into one fire-and-forget function (e.g. TeX-italicise-word
, however, I strongly advise against doing so because (in my opinion) emacs
' true power comes from composing functions / actions.
If you really insist on a single-key solution I suggest you read up on Keyboard Macros which can be used to create composite commands in an interactive manner.
Upvotes: 4