Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs + latex + yasnippet: Why are newlines inserted after a snippet?

Tags:

emacs

latex

Everytime I insert a snippet (with yasnippet) in a .tex document, I obtain a newline after the snippet. This is quite annoying for small snippets that are typically used in text style. How can I avoid that?

I read a bit about the problem (http://code.google.com/p/yasnippet/issues/detail?id=115 or http://yasnippet.googlecode.com/svn/trunk/doc/faq.html) but couldn't find a solution. Reproduce it as follows (I work with Aquamacs 2.3a on Mac OS X 10.6.8 with yasnippet version 0.6.1c):

  1. Define ~/Library/Preferences/Aquamacs Emacs/Preferences.el to be: (require 'yasnippet) (yas/initialize) (yas/load-directory "~/Library/Preferences/Aquamacs Emacs/plugins/yasnippet-0.6.1c/snippets")

  2. define the following snippet (call it "bm.yasnippet" [bm = boldmath]; the star * symbolizes where the cursor ends -- note that there is no newline after the snippet)

    # name: \bm{}{}
    # key: bm
    # --
    \bm{$1}*
    
  3. restart Aquamacs and open a .tex file and type in bm + Tab [this should insert the snippet]

  4. A newline is added after the snippet. This is quite inconvenient since \bm{foo} is typically used in text style, so for example in "The vector \bm{x} is not the null vector". A typical cause of this is that the snippet ends with a newline which is then inserted, too. However, I specifically obtain this behavior even the snippet does not end with a newline.

like image 592
Marius Hofert Avatar asked Oct 01 '11 10:10

Marius Hofert


2 Answers

I can't repro it with plain Emacs. In fact, I had this exact issue, but my problem is I had require-final-newline set to t. So Emacs was adding a newline at the end of my template.

My setup is a little more complicated but the solution for you is probably to set mode-require-final-newline to nil and restart Emacs.

To verify this is the problem, open up the template and check for the final newline.

like image 143
event_jr Avatar answered Oct 18 '22 23:10

event_jr


Thanks to the answers in Temporarly disable adding of newlines in Emacs, I'm using a function to only temporarily disable the adding of final newlines in the current buffer:

(defun disable-final-newline ()
    (interactive)
    (set (make-local-variable 'require-final-newline) nil))
like image 38
hupf Avatar answered Oct 18 '22 22:10

hupf