3 ms·
Anyone seriously considering Emacs for LaTeX editing should also take a look at the yasnippet package. The customizable autocompletion shortcuts make it really
by mih 12y ago
Anyone seriously considering Emacs for LaTeX editing should also take a look at the yasnippet package. The customizable autocompletion shortcuts make it really easy to insert commands using just keywords. In my case this has proved to be very helpful especially when inserting figures or inline equations. I can create a snippet so that when I type fig+<tab> it inserts a \begin{figure}.. \end{figure}float and positions the cursor at the proper field saving me a lot of keystrokes.
- josteink 12y agoI've stopped using yasnippet because I find it too resource-intensive. It's especially noticeable on emacs-startup, even of good machines, and I've found myself not using it very often. So I decided that it wasn't worth the time. Just as a FYI to people on weaker hardware.
- agumonkey 12y agoI never really investigated why, I think it's because I use melpa as my main package repository, but yasnippet loads lazily now. This is assuming the 'old' package didn't have this set up by default.
- pmoriarty 12y agoMy main gripe with yasnippet is that its feature list is pretty lackluster compared to some advanced vim snippet plugins like xptemplate.[1] xptemplate has a bazillion features, and yasnippet is primitive in comparison. Just a simple example is that in xptemplate (and probably any respectable snippet plugin in vim) you can type a part of a snippet name, hit TAB, and it will expand the snippet whose partial name you typed (assuming there's no exact match). In yasnippet, you have to type out the full snippet name before it can be expanded. This is pretty annoying, especially for long snippet names. There are tons of other examples of far more advanced functionality, such as a variety of snippet repetition and embedding features. This comparative lack of features in yasnippet is pretty surprising, because emacs extensions are usually very feature rich, and everyone seems to love yasnippet. But I think that's because most emacs users don't know what they're missing. And before someone says it, yes, I know yasnippet gives you the ability to embed eLisp code in it, so I could potentially write all the functionality I need myself. But that's really beside the point. I'm talking about built-in features, not the ability to code up the features myself. [1] https://github.com/drmingdrmer/xptemplate https://github.com/drmingdrmer/xptemplate
- tuhdo 12y ago> Just a simple example is that in xptemplate (and probably any respectable snippet plugin in vim) you can type a part of a snippet name, hit TAB, and it will expand the snippet whose partial name you typed (assuming there's no exact match). In yasnippet, you have to type out the full snippet name before it can be expanded. This is pretty annoying, especially for long snippet names. Yes, you can do that as well. See the list of expansion methods with screenshots inside: https://capitaomorte.github.io/yasnippet/snippet-expansion.html#sec-2-3 https://capitaomorte.github.io/yasnippet/snippet-expansion.h.... You may interest in minibuffer prompting. You already have a built-in template system in Emacs called Srecode that allows you to program your templates: http://cedet.sourceforge.net/srecode.shtml http://cedet.sourceforge.net/srecode.shtml According to the homepage, "the core template text is based loosely on Google ctemplate".
- pmoriarty 12y agoI was hoping someone would say that was possible. Thanks, I'll play around with the available yas-prompt-functions. As for SRecode, that looks interesting but its documentation is impenetrable. Someone seriously needs to write a bunch of tutorials for that thing. Otherwise, I can't really tell if it can do what xptemplate is capable of or not. I found some comments from SRecode's author suggesting that it's intended for different uses from yasnippet: "Thus, the audience for yasnippet and SRecode is quite different. Of course you could do yasnippet like things with SRecode if someone took the time to improve the field-editing feature in SRecode, but that has not been my focus."[1] [1] - http://emacs-fu.blogspot.com/2010/09/interview-with-eric-ludlam-cedet.html http://emacs-fu.blogspot.com/2010/09/interview-with-eric-lud...
- tuhdo 12y agoI agree Srecode needs to improve its documentation. It took me a while to learn to use it by reading the actual templates written that come with CEDET. I may write a tutorial for it at some point. But not now. You can have a look at a sample template: https://github.com/emacsmirror/cedet/blob/f72ebbc52785013280fddea8b6b1626ddd7ee6b4/etc/srecode/c.srt https://github.com/emacsmirror/cedet/blob/f72ebbc52785013280... . Srt file has syntax highlighting in Emacs.
- pXMzR2A 12y agoC-c C-e fig TAB RET C-c C-e means "give me a new environment"
- mih 12y agoSure Auctex does provides kb-shortcuts. But rather than using predefined keystrokes, I prefer to use my own. Besides, snippets can be used for commands/environments for which AucTex provides no shortcut or for things such as macros.
- tincholio 12y agoAUCTeX has the LaTeX-environment function (C-c C-e by default) that does even better than that (inserts the figure environment, offers to center, creates a label, a caption, etc.), and also handles all environments, plus there's no need to create the snippets.
- mih 12y agoI just used figure as an example. If there's no predefined keystroke or function available such as in the case of LaTeX macros that you tend to use frequently, snippets can be of use. Of course one can do without them, but they're definitely worth considering if you use emacs regularly.