Skip to content

Instantly share code, notes, and snippets.

@ihincks
Last active February 20, 2020 11:42
Show Gist options
  • Save ihincks/3440dd1a6929785ab21111b51c75dc9d to your computer and use it in GitHub Desktop.
Save ihincks/3440dd1a6929785ab21111b51c75dc9d to your computer and use it in GitHub Desktop.
Some Latex shortcuts for Atom
# mimics the ctrl+shift+m behaviour in texmaker
atom.commands.add 'atom-text-editor',
'custom:insert-inline-latex-eqn': ->
return unless editor = atom.workspace.getActiveTextEditor()
selection = editor.getLastSelection()
selection.insertText("$#{selection.getText()}$")
if not editor.getSelectedText()
editor.moveLeft()
# puts selected text in a new align environment
atom.commands.add 'atom-text-editor',
'custom:insert-latex-align': ->
editor = atom.workspace.getActiveTextEditor()
if not editor.getSelectedText()
editor.insertText('\\begin{align}\n')
editor.insertText(editor.getTabText())
editor.insertText('\n\\end{align}')
else
selection = editor.getLastSelection()
selection.insertText("\n\\begin{align}\n#{editor.getTabText()}#{selection.getText()}\n\\end{align}\n")
editor.moveLeft(13)
# inserts \textbf{}, and puts selected text in there if it exists
atom.commands.add 'atom-text-editor',
'latex:toggle-bold', ->
return unless editor = atom.workspace.getActiveTextEditor()
selection = editor.getLastSelection()
selection.insertText("\\textbf{#{selection.getText()}}")
if not editor.getSelectedText()
editor.moveLeft()
# inserts \textit{}, and puts selected text in there if it exists
atom.commands.add 'atom-text-editor',
'latex:toggle-italic', ->
return unless editor = atom.workspace.getActiveTextEditor()
selection = editor.getLastSelection()
selection.insertText("\\textit{#{selection.getText()}}")
if not editor.getSelectedText()
editor.moveLeft()
'atom-text-editor':
'ctrl-shift-m': 'custom:insert-inline-latex-eqn'
'ctrl-shift-e': 'custom:insert-latex-align'
'ctrl-b': 'latex:toggle-bold'
'ctrl-i': 'latex:toggle-italic'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment