In line with what @Johannes_B says and @DavidCarlisle 's response, you would be better of creating a abbreviation within emacs. By typing something such as
/eqn
emacs will see this as an abbreviation and expand it to what you want.
There are various ways of setting up abbreviations. Here's an approach that I use:
Create an new abbreviation table
(defvar my-abbrev-table (make-abbrev-table))
Define a function
(defun my-insert-equation ()
(insert "\\begin{equation}\n\n")
(insert "\\end{equation}\n")
(forward-line -2))
Then add this function to you abbreviation table
(define-abbrev my-abbrev-table "/eqn" "" 'my-insert-equation t)
Make this your local abbrev table
(setq local-abbrev-table my-abbrev-table)
The above can all go in its own .el file.
Then add to your tex-mode-hook a call to load that .el file. You should be good to go from there.
If you make sure that your function returns t, then you can control whether the expansion control character will also be used as input text.
Compare the following two:
(defun my-insert-equation ()
(insert "\\begin{equation}\n\n")
(insert "\\end{equation}\n")
(forward-line -2)
t)
(defun my-insert-junk ()
(insert "this is just junk")
t)
Now add the further line
(put 'my-insert-equation 'no-self-insert t)
Create the following two keys:
(define-abbrev my-abbrev-table "/eqn" "" 'my-insert-equation t)
(define-abbrev my-abbrev-table "/junk" "" 'my-insert-junk t)
Then by typing
/ e q n .
emacs will expand this to
\begin{equation}
[]
\end{equation}
where [] represents the position of the cursor. Notice how the period, ., does not show up.
However by typing
/ j u n k .
emacs will expand this to
this is just junk.[]
Notice how the punctuation used to trigger the expansion is included in the expansion.
IMPORTANT POINT
Regarding the above abbreviations, I forgot that I've modified my syntax table.
Abbreviations work only on word characters. To get the above to work, you'll have to modify the syntax table as follows
(modify-syntax-entry ?/ "w" tex-mode-syntax-table)
But this isn't really necessary to do if you define your abbreviation with the usual word characters. By making / a word character I create a little inconvenience when moving forward or backward over file paths, but that's just about the only time this modification creates headaches (and not much of one at that). By adopting this syntax, I'm confident that my abbreviation won't be something I might actually want to type in without expansion.
Nevertheless,
(define-abbrev my-abbrev-table "eqn" "" 'my-insert-equation t)
(define-abbrev my-abbrev-table "junk" "" 'my-insert-junk t)
would be perfectly good abbreviations. In case you really just wanted, for example, junk to be input as just junk and not expanded by the next non-word character, then you could type
j u n k \c-q <non-word character>
and emacs will not expand the word. But, I'm too stupid to recognize the difference when in the heat of the moment creating a document.
Incidentally, if all your abbreviation is going to do is expand into another string, (like in the case of /junk) then there's no need to create a function corresponding to this abbreviation. Instead you can just define it as
(define-abbrev my-abbrev-table "/junk" "This is just junk. Plain and simple" nil t)
\begin{equation}|\end{equation}with a single keystroke combination, with the cursor (which I represented by|) in the middle. – egreg Jul 12 '14 at 14:17C-c C-e equation RET(the environment name can be autocompleted withTAB). – giordano Jul 12 '14 at 14:35