add latex displaymath snippet
MODIFY
data/commands.json
data/commands.json
"snippet":"begin{${1:env}}\n\t$2\n\\\\end{${1:env}}",
"detail":"begin a new environment"
},
- "inlinemath":{
+ "latexinlinemath":{
"command":"(",
"snippet":"(${1}\\)${0}",
"detail":"inline math \\( ... \\)"
},
+ "latexdisplaymath":{
+ "command":"[",
+ "snippet":"[${1}\\]${0}",
+ "detail":"display math \\[ ... \\]"
+ },
"title":{
"command":"title",
"snippet":"title{${1:text}}"

MODIFY
src/main.ts
src/main.ts
@@ -209,7 +209,7 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider('latex', new DocSymbolProvider(extension)))
context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(new ProjectSymbolProvider(extension)))
context.subscriptions.push(vscode.languages.registerCompletionItemProvider('tex', extension.completer, '\\', '{'))
- context.subscriptions.push(vscode.languages.registerCompletionItemProvider('latex', extension.completer, '\\', '{', ',', '('))
+ context.subscriptions.push(vscode.languages.registerCompletionItemProvider('latex', extension.completer, '\\', '{', ',', '(', '['))
context.subscriptions.push(vscode.languages.registerCodeActionsProvider('latex', extension.codeActions))
context.subscriptions.push(vscode.window.registerTreeDataProvider('latex-outline', extension.nodeProvider))

MODIFY
src/providers/completion.ts
src/providers/completion.ts
@@ -48,15 +48,23 @@ export class Completer implements vscode.CompletionItemProvider {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, _token: vscode.CancellationToken) : Promise<vscode.CompletionItem[]> {
return new Promise((resolve, _reject) => {
- if (document.lineAt(position.line).text[position.character - 1] === '(') {
+ const invokeChar = document.lineAt(position.line).text[position.character - 1]
+ if (['(', '['].indexOf(invokeChar) > -1) {
if (position.character > 1 && document.lineAt(position.line).text[position.character - 2] === '\\') {
- const inlineMath = new vscode.CompletionItem('\\(', vscode.CompletionItemKind.Function)
- inlineMath.insertText = new vscode.SnippetString('${1}\\)${0}')
- inlineMath.detail = 'inline math \\( ... \\)'
+ let mathSnippet
+ if (invokeChar === '(') {
+ mathSnippet = new vscode.CompletionItem('\\(', vscode.CompletionItemKind.Function)
+ mathSnippet.insertText = new vscode.SnippetString('${1}\\)${0}')
+ mathSnippet.detail = 'inline math \\( ... \\)'
+ } else {
+ mathSnippet = new vscode.CompletionItem('\\[', vscode.CompletionItemKind.Function)
+ mathSnippet.insertText = new vscode.SnippetString('${1}\\]${0}')
+ mathSnippet.detail = 'display math \\[ ... \\]'
+ }
if (vscode.workspace.getConfiguration('editor', document.uri).get('autoClosingBrackets')) {
- inlineMath.range = new vscode.Range(position, position.translate(0, 1))
+ mathSnippet.range = new vscode.Range(position, position.translate(0, 1))
}
- resolve([inlineMath])
+ resolve([mathSnippet])
return
} else {
resolve()

add latex displaymath snippet