LaTeX snippets

29 views
Skip to first unread message

madsdk

unread,
Mar 19, 2010, 4:24:00 AM3/19/10
to smart-snippet and YASnippet
I have been using yasnippet for a long time now and in that time I
have been building a library of useful LaTeX and Python snippets. I
would like to share those snippets with other yasnippet users, so: Who
do I have to contact if I want to be a contributor to the project? I
realize that I could just send all my snippets to this mailinglist,
but that is a bit tedious - especially when I make changes to the
snippets etc.

B.t.w., thanks for a great Emacs plugin - I love yasnippet :-)

Best regards,
Mads Kristensen

João Távora

unread,
Mar 19, 2010, 7:22:13 AM3/19/10
to smart-...@googlegroups.com
Hi,


First and foremost, thank you for using YASnippet and for offering help. I'm the current maintainer of the YASnippet project btw

YASnippet already has two snippet collections, and replacing/redoing them is not planned in the future. Therefore your collection of LaTeX and Python snippets is better stored in a GitHub some other project hosting site. Then post the link here! That is a contribution in itself.

You can always send in patches fixing the original snippet collection under http://yasnippet.googlecode.com/svn/trunk/snippets. This was set up when the project started a few years ago. It's not great maybe but we try to limit breaking backward compatibility, for people who might already be used to it.

On the other hand, the collection under http://yasnippet.googlecode.com/svn/trunk/extras/imported is a *new* collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.

See http://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.html#importing-textmate-snippets and mail me for any questions.

Thanks,
João

> --
> You received this message because you are subscribed to the Google Groups "smart-snippet and YASnippet" group.
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to smart-snippe...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/smart-snippet?hl=en.
>

madsdk

unread,
Mar 19, 2010, 10:00:29 AM3/19/10
to smart-snippet and YASnippet
Hello again,

I have just created a GitHub project for my LaTeX snippets. I may
create a similar project for my Python snippets at some point in
time...

If you are interested you can find the snippets here:
http://github.com/madsdk/yasnippets-latex/

They are all fairly simple, but I expect that I will be refining them
over the next couple of months, since I will be working with LaTeX
constantly for some time to come :-)

Best regards,
Mads

On Mar 19, 12:22 pm, João Távora <joaotav...@gmail.com> wrote:
> Hi,
>
> First and foremost, thank you for using YASnippet and for offering help. I'm the current maintainer of the YASnippet project btw
>
> YASnippet already has two snippet collections, and replacing/redoing them is not planned in the future. Therefore your collection of LaTeX and Python snippets is better stored in a GitHub  some other project hosting site. Then post the link here! That is a contribution in itself.
>

> You can always send in patches fixing the original snippet collection underhttp://yasnippet.googlecode.com/svn/trunk/snippets. This was set up when the project started a few years ago. It's not great maybe but we try to limit breaking backward compatibility, for people who might already be used to it.
>
> On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedis a *new* collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...and mail me for any questions.

Jim Burton

unread,
Mar 19, 2010, 12:54:30 PM3/19/10
to smart-snippet and YASnippet
On Mar 19, 2:00 pm, madsdk <mad...@gmail.com> wrote:
> Hello again,
>
> I have just created a GitHub project for my LaTeX snippets. I may
> create a similar project for my Python snippets at some point in
> time...
>
> If you are interested you can find the snippets here:http://github.com/madsdk/yasnippets-latex/
>
> They are all fairly simple, but I expect that I will be refining them
> over the next couple of months, since I will be working with LaTeX
> constantly for some time to come :-)
>

Thanks for this Mads. I think that most of your snippets are somewhat
similar to the ones in .../imported/ -- they are for individual macros
and environments. It's just my opinion, but I think you will be *much*
better served by mastering LaTeX-mode/AUCTeX/RefTeX and the built-in
keybindings. E.g. you have several snippets for chapter/section/
subsection etc -- you can already access these by typing C-s,
including the automagic label. Similarly, to add an item inside an
enumerate/itemize etc, it's C-j. There are a couple of exceptions to
this, like your figure environment -- this is where yasnippet is handy
for latexers IMHO -- boilerplate that combines several macros/
environments etc. Other than that, discover the power that's already
there in the various modes rather than reinventing the wheel,
especially if you expect to be editing a lot of LaTeX in emacs. These
kind of oneliner snippets come from a much more limited environment
(Textmate), and emacs already does it better.

Regards,

Jim

> Best regards,
> Mads
>
> On Mar 19, 12:22 pm, João Távora <joaotav...@gmail.com> wrote:
>
> > Hi,
>
> > First and foremost, thank you for using YASnippet and for offering help. I'm the current maintainer of the YASnippet project btw
>
> > YASnippet already has two snippet collections, and replacing/redoing them is not planned in the future. Therefore your collection of LaTeX and Python snippets is better stored in a GitHub  some other project hosting site. Then post the link here! That is a contribution in itself.
>
> > You can always send in patches fixing the original snippet collection underhttp://yasnippet.googlecode.com/svn/trunk/snippets. This was set up when the project started a few years ago. It's not great maybe but we try to limit breaking backward compatibility, for people who might already be used to it.
>

> > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa *new* collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...mail me for any questions.

Jim Burton

unread,
Mar 19, 2010, 12:59:13 PM3/19/10
to smart-snippet and YASnippet

I just realised I'm assuming in the above that you *are* using AUCTeX?
If not, stop what you're doing and check it out :-)

Jim


>
> Regards,
>
> Jim
>
> > Best regards,
> > Mads
>
> > On Mar 19, 12:22 pm, João Távora <joaotav...@gmail.com> wrote:
>
> > > Hi,
>
> > > First and foremost, thank you for using YASnippet and for offering help. I'm the current maintainer of the YASnippet project btw
>
> > > YASnippet already has two snippet collections, and replacing/redoing them is not planned in the future. Therefore your collection of LaTeX and Python snippets is better stored in a GitHub  some other project hosting site. Then post the link here! That is a contribution in itself.
>
> > > You can always send in patches fixing the original snippet collection underhttp://yasnippet.googlecode.com/svn/trunk/snippets. This was set up when the project started a few years ago. It's not great maybe but we try to limit breaking backward compatibility, for people who might already be used to it.
>

> > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new* collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...me for any questions.

madsdk

unread,
Mar 19, 2010, 2:19:41 PM3/19/10
to smart-snippet and YASnippet
Hi Jim,

I have been using Emacs/AucTeX/RefTeX for many many years now, so I
know all the keybindings and other magic - and I absolutely could not
live without it :-) The thing is, that after using TextMate for some
time too, I find that snippets are just that much more convenient than
the keybindings in auctex.

For example, I find it much easier to write 'sub + [Tab]' than to
press [Ctrl]+c, [Ctrl]+s and then choose subsection. The same goes for
all the environments, I known that I can press [Ctrl]+c, [Ctrl]+e and
then choose from a large list of environments, but I find it much
easier to e.g., type 'fig + [Tab]' to create a figure.

I know my snippets only offer the same (or rather a subset of the)
features that are already offered by auctex, but I find them to be
useful anyway :-)

Best regards,
Mads

> > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new* collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...me for any questions.

Jim Burton

unread,
Mar 19, 2010, 3:44:08 PM3/19/10
to smart-snippet and YASnippet
On Mar 19, 6:19 pm, madsdk <mad...@gmail.com> wrote:
> Hi Jim,
>
> I have been using Emacs/AucTeX/RefTeX for many many years now, so I
> know all the keybindings and other magic - and I absolutely could not
> live without it :-) The thing is, that after using TextMate for some
> time too, I find that snippets are just that much more convenient than
> the keybindings in auctex.
>

I honestly find that quite amazing :-)

> For example, I find it much easier to write 'sub + [Tab]' than to
> press [Ctrl]+c, [Ctrl]+s and then choose subsection. The same goes for
> all the environments, I known that I can press [Ctrl]+c, [Ctrl]+e and
> then choose from a large list of environments, but I find it much
> easier to e.g., type 'fig + [Tab]' to create a figure.
>

Because the figure environment always needs some boilerplate, I'd
agree with you on this one. In most other situations you're
reinventing the wheel though and it would take a lot of work to make
your wheel as functional as the existing ones. To pick a random
example, take \section etc. If you highlight some text and type C-c C-
s, not only is the selected text the default title and used for the
label, AUCTeX scans the document and checks that the label doesn't
clash, making it unique if necessary. When I say "scans the document"
I mean scans the current buffer, the master file and any other files
the master file includes with \include etc...very handy if you're
working on a book or thesis with hundreds of labels spread across
dozens of chapters. I can't see anyone providing that as a snippet,
and even if they did, why not use what's there?

On the subject of labels, your equation environment doesn't have one
-- the only reason to use equation over equation* or \[ \] is to
refer back to it via the label -- if you insert your own label you
have to think of a unique name for it...do you really find this more
convenient than having AUCTeX do it for you (after scanning your
entire document for a unique label)?

> I know my snippets only offer the same (or rather a subset of the)
> features that are already offered by auctex, but I find them to be
> useful anyway :-)
>

Glad to hear it :-) I mean that sincerely BTW -- it goes without
saying that everyone knows what's productive for them and if you've
been using these tools for years then you obviously know what suits
you. What's more, yasnippet is brilliant for boilerplate.

Jim

> > > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new*collection of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...for any questions.

madsdk

unread,
Mar 19, 2010, 4:48:37 PM3/19/10
to smart-snippet and YASnippet

You are so right - the label generation/checking in auctex is very
nice to have... I wonder if I could call that functionality from my
yasnippet snippets ;-)

Best regards,
Mads

> > > > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new*coll...of snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...any questions.

Jim Burton

unread,
Mar 19, 2010, 5:45:43 PM3/19/10
to smart-snippet and YASnippet
On Mar 19, 8:48 pm, madsdk <mad...@gmail.com> wrote:
[snip]

>
> > Because the figure environment always needs some boilerplate, I'd
> > agree with you on this one. In most other situations you're
> > reinventing the wheel though and it would take a lot of work to make
> > your wheel as functional as the existing ones. To pick a random
> > example, take \section etc. If you highlight some text and type C-c C-
> > s, not only is the selected text the default title and used for the
> > label, AUCTeX scans the document and checks that the label doesn't
> > clash, making it unique if necessary. When I say "scans the document"
> > I mean scans the current buffer, the master file and any other files
> > the master file includes with \include etc...very handy if you're
> > working on a book or thesis with hundreds of labels spread across
> > dozens of chapters. I can't see anyone providing that as a snippet,
> > and even if they did, why not use what's there?
>
> You are so right - the label generation/checking in auctex is very
> nice to have... I wonder if I could call that functionality from my
> yasnippet snippets ;-)
>

I think you could -- out of curiosity I had a look at the AUCTeX
source and I think you want

(LaTeX-label name)

I tried

${1:$$(LaTeX-label yas/text)}

but that doesn't work because the elisp in fields with transformations
is run every time you edit the field -- you want to run it once when
you leave the field...

> > > > > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new*coll...snippets, meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > > > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...questions.

madsdk

unread,
Mar 20, 2010, 5:26:40 PM3/20/10
to smart-snippet and YASnippet
The answer to the label question was on the webpage all along :-)
http://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.html#choosing-fields-value-from-a-list-and-other-tricks

So a section snippet could look like so:

\section{${1:name}}
\label{${2:"waiting for reftex-label call..."$(unless yas/modified-p
(reftex-label nil 'dont-insert))}}
$0

That way reftex-label is called whenever a label is needed.

Best regards,
Mads

> > > > > > > On the other hand, the collection underhttp://yasnippet.googlecode.com/svn/trunk/extras/importedisa*new*coll..., meant to be a direct translation of TextMate snippets and commands. The idea is that TextMate-Emacs switchers can keep the same snippets and functionality across editors. It is still incomplete and buggy, a lot of effort is needed is this step, and your help would be hugely appreciated, especially if you know the snippet syntax well and some emacs-lisp.
>
> > > > > > > Seehttp://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm....

Jim Burton

unread,
Mar 22, 2010, 7:58:18 AM3/22/10
to smart-snippet and YASnippet
On Mar 20, 9:26 pm, madsdk <mad...@gmail.com> wrote:
> The answer to the label question was on the webpage all along :-)http://yasnippet.googlecode.com/svn/trunk/doc/snippet-development.htm...
>
Well spotted!

Jim

Reply all
Reply to author
Forward
0 new messages