1

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.

Devilius
  • 311
  • 1
  • 3
  • 12

1 Answers1

2

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 (init.coffee 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.

idleberg
  • 12,634
  • 7
  • 43
  • 70
  • Yeah, that's the way I currently have it, and although it is faster than just having to type a $ manually at the end every time, I wish there was a way for the program to automatically add it any time I type in a $. – Devilius Sep 16 '16 at 13:30
  • 1
    Please see my revised answer – idleberg Sep 16 '16 at 14:03
  • When adding those lines to the keymap, I get the following error : `Duplicate key '$'`. Any idea on how to solve it ? **EDIT** : I removed `'\$': 'unset!'` and it seems to work as I wish. – Sileo Apr 27 '20 at 15:21