Devilius Devilius - 9 months ago 63
LaTeX Question

Where can I add my own autocompletion snippets in the atom editor?

I am using atom as my main editor for .tex documents. A feature which the bracket-matcher package gives that I really like is that it automatically inserts a closing }, any time I enter an opening {. I would like to add a similar feature for $, as I often end up using mathmode in latex. Where would I be able to add this? I do not want to add it in a snippet, where I would have to press tab for another $ to appear. I would simply like for a second closing $ to be automatically added (after my cursor) whenever I do open one. If this can be done with a setting that makes it enabled only on .tex files, that would be great.


Since a standard snippet won't trigger on a single key-press, you will have to solve this programmatically. You will have to edit the following two files.

i. Init Script ( or init.js):

atom.commands.add 'atom-text-editor', 'custom:insert-dollar-pair', ->
  snippetBody = '\$ $1 \$$0'
  atom.packages.activePackages.snippets?.mainModule?.insert snippetBody

ii. Keymap (keymap.cson or keymap.json):

'atom-text-editor[data-grammar="text tex latex"]':
  '\$': 'unset!'
  '\$': 'custom:insert-dollar-pair'

PS: I think you don't even have to escape the dollar-sign, but it makes for good visual separation.