Initial commit
commit
de1806ab2d
@ -0,0 +1,3 @@
|
|||||||
|
.DS_Store
|
||||||
|
npm-debug.log
|
||||||
|
node_modules
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
## 0.1.0 - First Release
|
||||||
|
* Every feature added
|
||||||
|
* Every bug fixed
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) 2018 <Your name here>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
# latex-helper package
|
||||||
|
|
||||||
|
Extra LaTeX functionality in Atom
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
|
||||||
|
* (cmd-l ,) "latex-helper:mathify-comma-list"
|
||||||
|
Split a comma list, wrapping each element in $ $.
|
||||||
|
* (cmd-l m) "latex-helper:convert-to-display-math"
|
||||||
|
Wrap selected text in display math \[ \] tags,
|
||||||
|
removing all $ from the selection.
|
||||||
|
* (cmd-l a") "latex-helper:convert-to-abs"
|
||||||
|
Wrap selected text in a \abs{} tag, removing any |, \mid
|
||||||
|
commands from the selection. (Written for editing Beta.)
|
||||||
|
* (, ,): "latex-helper:insert-backslash-comma"
|
||||||
|
Inserts \, when user types ,,
|
||||||
|
|
||||||
|
|
||||||
|
Snippets:
|
||||||
|
|
||||||
|
* m -- \[ .. \]
|
||||||
|
* n -- $ .. $
|
||||||
|
* ba -- \begin{align} .. \end{align}
|
||||||
|
* bal -- \begin{aligned} .. \end{aligned}
|
||||||
|
* be -- \begin{equation} .. \end{equation}
|
||||||
|
* tabu -- Beta table template
|
||||||
|
* tikz -- \begin{tikzpicture} .. \end{tikzpicture}
|
||||||
|
* marginfigure -- \begin{marginfigure} .. \end{marginfigure}
|
||||||
|
* axis -- Std TikZ axis drawing commands
|
||||||
|
* theorem -- \begin{theorem} .. \end{theorem}
|
||||||
|
* remark -- \begin{remark} .. \end{remark}
|
||||||
|
* definition -- \begin{definition} .. \end{definition}
|
||||||
|
* figure -- \begin{figure} .. \end{figure}
|
||||||
|
* frac -- \frac{}{}
|
||||||
|
* sum -- \sum_{}^{}
|
||||||
|
* prod -- \prod_{}^{}
|
||||||
|
* matrix -- \begin{<b>matrix} .. \end{<b>matrix}
|
||||||
|
* binom -- \binom{}{}
|
||||||
|
* chap -- \chapter{}\label{chap:}
|
||||||
|
* s -- \section{}\label{sec:}
|
||||||
|
* ss -- \subsection{}\label{ssec:}
|
||||||
|
* partial -- \frac{\partial }{\partial }
|
||||||
|
* set -- \set{ \where }
|
||||||
|
* labelled -- \begin{labelled} \item[] \end{labelled}
|
||||||
|
* item -- \item[]
|
||||||
|
* node -- \node at () { $$ };
|
||||||
|
* big( -- \big( \big)
|
||||||
|
* Big( -- \Big( \Big)
|
||||||
|
* bigg( -- \bigg( \bigg)
|
||||||
|
* big[ -- \big[ \big]
|
||||||
|
* Big[ -- \Big[ \Big]
|
||||||
|
* bigg[ -- \bigg( \bigg]
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"atom-text-editor[data-grammar='text tex latex']": {
|
||||||
|
"cmd-l ,": "latex-helper:mathify-comma-list",
|
||||||
|
"cmd-l m": "latex-helper:convert-to-display-math",
|
||||||
|
"cmd-l a": "latex-helper:convert-to-abs",
|
||||||
|
", ,": "latex-helper:insert-backslash-comma"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
'use babel';
|
||||||
|
|
||||||
|
import { CompositeDisposable } from 'atom';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
|
||||||
|
subscriptions: null,
|
||||||
|
|
||||||
|
activate(state) {
|
||||||
|
|
||||||
|
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
|
||||||
|
this.subscriptions = new CompositeDisposable();
|
||||||
|
|
||||||
|
// Register command that toggles this view
|
||||||
|
this.subscriptions.add(atom.commands.add('atom-workspace', {
|
||||||
|
'latex-helper:convert-to-display-math': () => this.convertToDisplayMath(),
|
||||||
|
'latex-helper:convert-to-abs': () => this.convertToAbs(),
|
||||||
|
'latex-helper:mathify-comma-list': () => this.mathifyList(),
|
||||||
|
'latex-helper:insert-backslash-comma': () => this.insertBackslashComma(),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
deactivate() {
|
||||||
|
this.subscriptions.dispose();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
convertToDisplayMath() {
|
||||||
|
const editor = atom.workspace.getActiveTextEditor()
|
||||||
|
if (editor) {
|
||||||
|
const selection = editor.getSelectedText()
|
||||||
|
const strippedText = selection.replace(/\$/g, '')
|
||||||
|
editor.insertText("\\[\n" + strippedText.trim() + "\n\\]")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
convertToAbs() {
|
||||||
|
const editor = atom.workspace.getActiveTextEditor()
|
||||||
|
if (editor) {
|
||||||
|
const selection = editor.getSelectedText()
|
||||||
|
const strippedText = selection
|
||||||
|
.replace(/\\mid/g, '')
|
||||||
|
.replace(/\|/g,'')
|
||||||
|
.replace(/\\left/g,'')
|
||||||
|
.replace(/\\right/g,'')
|
||||||
|
editor.insertText("\\abs{" + strippedText.trim() + "}")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mathifyList() {
|
||||||
|
const editor = atom.workspace.getActiveTextEditor()
|
||||||
|
if (editor) {
|
||||||
|
const selection = editor.getSelectedText()
|
||||||
|
const items = selection.replace('$','').split(',').map((item) => item.trim())
|
||||||
|
editor.insertText("$" + items.join('$, $') + "$")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
insertBackslashComma() {
|
||||||
|
const editor = atom.workspace.getActiveTextEditor()
|
||||||
|
if (editor) {
|
||||||
|
editor.insertText('\\,')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"context-menu": {
|
||||||
|
"atom-text-editor": [
|
||||||
|
{
|
||||||
|
"label": "Toggle latex-helper",
|
||||||
|
"command": "latex-helper:toggle"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"menu": [
|
||||||
|
{
|
||||||
|
"label": "Packages",
|
||||||
|
"submenu": [
|
||||||
|
{
|
||||||
|
"label": "latex-helper",
|
||||||
|
"submenu": [
|
||||||
|
{
|
||||||
|
"label": "Toggle",
|
||||||
|
"command": "latex-helper:toggle"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "latex-helper",
|
||||||
|
"main": "./lib/latex-helper",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "A short description of your package",
|
||||||
|
"keywords": [
|
||||||
|
],
|
||||||
|
"activationCommands": {
|
||||||
|
"atom-workspace": [
|
||||||
|
"latex-helper:convert-to-display-math",
|
||||||
|
"latex-helper:insert-backslash-comma",
|
||||||
|
"latex-helper:mathify-comma-list",
|
||||||
|
"latex-helper:convert-to-abs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"repository": "https://github.com/atom/latex-helper",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"atom": ">=1.0.0 <2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,179 @@
|
|||||||
|
'.text.tex.latex':
|
||||||
|
'Insert display math':
|
||||||
|
'prefix': 'm'
|
||||||
|
'body': """
|
||||||
|
\\\\[
|
||||||
|
$1
|
||||||
|
\\\\]
|
||||||
|
$2
|
||||||
|
"""
|
||||||
|
'Insert inline math':
|
||||||
|
'prefix': 'n'
|
||||||
|
'body': '\$$1\$ $2'
|
||||||
|
'align environment':
|
||||||
|
'prefix': 'ba'
|
||||||
|
'body': """
|
||||||
|
\\\\begin{align${1:*}}
|
||||||
|
$2
|
||||||
|
\\\\end{align${1:*}}
|
||||||
|
$3
|
||||||
|
"""
|
||||||
|
'aligned environment':
|
||||||
|
'prefix': 'bal'
|
||||||
|
'body': """
|
||||||
|
\\\\begin{aligned}${1:[t]}
|
||||||
|
$2
|
||||||
|
\\\\end{aligned}
|
||||||
|
$3
|
||||||
|
"""
|
||||||
|
'Equations':
|
||||||
|
'prefix': 'be'
|
||||||
|
'body': """
|
||||||
|
\\\\begin{equation${1:*}}
|
||||||
|
$2
|
||||||
|
\\\\end{equation${1:*}}
|
||||||
|
$3
|
||||||
|
"""
|
||||||
|
'Tabu (beta)':
|
||||||
|
'prefix': 'tabu'
|
||||||
|
'body': """
|
||||||
|
\\\\begingroup
|
||||||
|
\\\\pretable
|
||||||
|
\\\\begin{tabu}{$1}
|
||||||
|
\\\\tablehead
|
||||||
|
$2
|
||||||
|
\\\\tablemain
|
||||||
|
$3
|
||||||
|
\\\\tablebottom
|
||||||
|
\\\\end{tabu}
|
||||||
|
\\\\endgroup
|
||||||
|
"""
|
||||||
|
'Insert TikZ picture:':
|
||||||
|
'prefix': 'tikz',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{tikzpicture}
|
||||||
|
$1
|
||||||
|
\\\\end{tikzpicture}
|
||||||
|
"""
|
||||||
|
'Insert marginfigure:':
|
||||||
|
'prefix': 'marginfigure',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{marginfigure}
|
||||||
|
$1
|
||||||
|
\\\\end{marginfigure}
|
||||||
|
"""
|
||||||
|
'Insert axis into TikZ picture':
|
||||||
|
'prefix': 'axis',
|
||||||
|
'body': """
|
||||||
|
\\\\draw[-stealth] (${1:-1},0) -- (${2:3},0) node[above] {$x$};
|
||||||
|
\\\\draw[-stealth] (0,${1:-1}) -- (${2:3},0) node[left] {$y$};
|
||||||
|
$3
|
||||||
|
"""
|
||||||
|
'LaTeX theorem':
|
||||||
|
'prefix': 'theorem',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{theorem}\\\\label{thm:$1}
|
||||||
|
$2
|
||||||
|
\\\\end{theorem}$3
|
||||||
|
"""
|
||||||
|
'LaTeX remark':
|
||||||
|
'prefix': 'remark',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{remark}\\\\label{remark:$1}
|
||||||
|
$2
|
||||||
|
\\\\end{remark}$3
|
||||||
|
"""
|
||||||
|
'LaTeX definition':
|
||||||
|
'prefix': 'definition',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{definition}\\\\label{def:$1}
|
||||||
|
$2
|
||||||
|
\\\\end{definition}
|
||||||
|
"""
|
||||||
|
'LaTeX figure':
|
||||||
|
'prefix': 'figure',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{figure}
|
||||||
|
\\\\includegraphics{$1}
|
||||||
|
\\\\caption{$2}\\\\label{fig:$3}
|
||||||
|
\\\\end{figure}$4
|
||||||
|
"""
|
||||||
|
'LaTeX table (beta)':
|
||||||
|
'prefix': 'table',
|
||||||
|
'body': """
|
||||||
|
\\\\begin{table}
|
||||||
|
\\\\pretable
|
||||||
|
\\\\caption{$1}\\\\label{table:$2}
|
||||||
|
\\\\begin{tabu}{$3}
|
||||||
|
\\\\tablehead
|
||||||
|
$4
|
||||||
|
\\\\tablemain
|
||||||
|
$5
|
||||||
|
\\\\tablebottom
|
||||||
|
\\\\end{tabu}
|
||||||
|
\\\\end{table}
|
||||||
|
"""
|
||||||
|
'LaTeX fraction':
|
||||||
|
'prefix': 'frac'
|
||||||
|
'body': '\\\\frac{$1}{$2}$3'
|
||||||
|
'LaTeX sum':
|
||||||
|
'prefix': 'sum'
|
||||||
|
'body': '\\\\sum_{${1:k=0}^{${2:\infty}} $3'
|
||||||
|
'LaTeX product':
|
||||||
|
'prefix': 'prod'
|
||||||
|
'body': '\\\\prod{${1:k=0}^{${2:\infty}} $3'
|
||||||
|
'LaTeX matrix':
|
||||||
|
'prefix': 'matrix'
|
||||||
|
'body': '\\\\begin{${1:b}matrix} $2 \\\\end{${1:b}matrix}'
|
||||||
|
'LaTeX binomial':
|
||||||
|
'prefix': 'binom'
|
||||||
|
'body': '\\\\binom{$1}{$2}$3'
|
||||||
|
'LaTeX chapter':
|
||||||
|
'prefix': 'chapt'
|
||||||
|
'body': '\\\\chapter{$1}\\\\label{chap:$1}$2'
|
||||||
|
'LaTeX section':
|
||||||
|
'prefix': 's'
|
||||||
|
'body': '\\\\section{$1}\\\\label{sec:$1}$2'
|
||||||
|
'LaTeX subsection':
|
||||||
|
'prefix': 'ss'
|
||||||
|
'body': '\\\\subsection{$1}\\\\label{subsec:$1}$2'
|
||||||
|
'LaTeX partial derivative':
|
||||||
|
'prefix': 'partial'
|
||||||
|
'body': '\\\\frac{\\\\partial $1}{\\\\partial $2}$3'
|
||||||
|
'LaTeX set builder (custom command)':
|
||||||
|
'prefix': 'set'
|
||||||
|
'body': '\\\\set{$1 \\\\where $2}$3'
|
||||||
|
'width=marginparwidth':
|
||||||
|
'prefix': 'ww'
|
||||||
|
'body': '[width=\\\\marginparwidth]'
|
||||||
|
'Labelled list (beta)':
|
||||||
|
'prefix': 'labelled',
|
||||||
|
'body':"""
|
||||||
|
\\\\begin{labelled}{${1:itlabel}}
|
||||||
|
\item[$2:] $3
|
||||||
|
\\\\end{labelled}
|
||||||
|
"""
|
||||||
|
'Insert item':
|
||||||
|
'prefix': 'item',
|
||||||
|
'body': '\\\\item[$1] $2'
|
||||||
|
'TikZ node':
|
||||||
|
'prefix': 'node',
|
||||||
|
'body': '\\\\node ${1:(name)} at ($2) { $$3$ };$4'
|
||||||
|
'Latex big ()':
|
||||||
|
'prefix': 'big(',
|
||||||
|
'body': '\\\\big( $1 \\\\big'
|
||||||
|
'Latex big []':
|
||||||
|
'prefix': 'big[',
|
||||||
|
'body': '\\\\big[ $1 \\\\big'
|
||||||
|
'Latex bigg ()':
|
||||||
|
'prefix': 'bigg(',
|
||||||
|
'body': '\\\\bigg( $1 \\\\bigg'
|
||||||
|
'Latex bigg []':
|
||||||
|
'prefix': 'bigg[',
|
||||||
|
'body': '\\\\bigg[ $1 \\\\bigg'
|
||||||
|
'Latex Big ()':
|
||||||
|
'prefix': 'Big(',
|
||||||
|
'body': '\\\\Big( $1 \\\\Big'
|
||||||
|
'Latex big []':
|
||||||
|
'prefix': 'Big[',
|
||||||
|
'body': '\\\\Big[ $1 \\\\Big'
|
||||||
@ -0,0 +1,73 @@
|
|||||||
|
'use babel';
|
||||||
|
|
||||||
|
import LatexHelper from '../lib/latex-helper';
|
||||||
|
|
||||||
|
// Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
|
||||||
|
//
|
||||||
|
// To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
|
||||||
|
// or `fdescribe`). Remove the `f` to unfocus the block.
|
||||||
|
|
||||||
|
describe('LatexHelper', () => {
|
||||||
|
let workspaceElement, activationPromise;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
workspaceElement = atom.views.getView(atom.workspace);
|
||||||
|
activationPromise = atom.packages.activatePackage('latex-helper');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the latex-helper:toggle event is triggered', () => {
|
||||||
|
it('hides and shows the modal panel', () => {
|
||||||
|
// Before the activation event the view is not on the DOM, and no panel
|
||||||
|
// has been created
|
||||||
|
expect(workspaceElement.querySelector('.latex-helper')).not.toExist();
|
||||||
|
|
||||||
|
// This is an activation event, triggering it will cause the package to be
|
||||||
|
// activated.
|
||||||
|
atom.commands.dispatch(workspaceElement, 'latex-helper:toggle');
|
||||||
|
|
||||||
|
waitsForPromise(() => {
|
||||||
|
return activationPromise;
|
||||||
|
});
|
||||||
|
|
||||||
|
runs(() => {
|
||||||
|
expect(workspaceElement.querySelector('.latex-helper')).toExist();
|
||||||
|
|
||||||
|
let latexHelperElement = workspaceElement.querySelector('.latex-helper');
|
||||||
|
expect(latexHelperElement).toExist();
|
||||||
|
|
||||||
|
let latexHelperPanel = atom.workspace.panelForItem(latexHelperElement);
|
||||||
|
expect(latexHelperPanel.isVisible()).toBe(true);
|
||||||
|
atom.commands.dispatch(workspaceElement, 'latex-helper:toggle');
|
||||||
|
expect(latexHelperPanel.isVisible()).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hides and shows the view', () => {
|
||||||
|
// This test shows you an integration test testing at the view level.
|
||||||
|
|
||||||
|
// Attaching the workspaceElement to the DOM is required to allow the
|
||||||
|
// `toBeVisible()` matchers to work. Anything testing visibility or focus
|
||||||
|
// requires that the workspaceElement is on the DOM. Tests that attach the
|
||||||
|
// workspaceElement to the DOM are generally slower than those off DOM.
|
||||||
|
jasmine.attachToDOM(workspaceElement);
|
||||||
|
|
||||||
|
expect(workspaceElement.querySelector('.latex-helper')).not.toExist();
|
||||||
|
|
||||||
|
// This is an activation event, triggering it causes the package to be
|
||||||
|
// activated.
|
||||||
|
atom.commands.dispatch(workspaceElement, 'latex-helper:toggle');
|
||||||
|
|
||||||
|
waitsForPromise(() => {
|
||||||
|
return activationPromise;
|
||||||
|
});
|
||||||
|
|
||||||
|
runs(() => {
|
||||||
|
// Now we can test for view visibility
|
||||||
|
let latexHelperElement = workspaceElement.querySelector('.latex-helper');
|
||||||
|
expect(latexHelperElement).toBeVisible();
|
||||||
|
atom.commands.dispatch(workspaceElement, 'latex-helper:toggle');
|
||||||
|
expect(latexHelperElement).not.toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue