latex inline math completion
MODIFY
data/commands.json
data/commands.json
"snippet":"begin{${1:env}}\n\t$2\n\\\\end{${1:env}}",
"detail":"begin a new environment"
},
+ "inlinemath":{
+ "command":"(",
+ "snippet":"(${1}\\)${0}",
+ "detail":"inline math \\( ... \\)"
+ },
"title":{
"command":"title",
"snippet":"title{${1:text}}"
"pagebreak":{
"command":"pagebreak"
},
- " ":{
- "command":" Press ENTER to insert a new line.",
- "snippet":"\n"
- },
"noindent":{
"command":"noindent"
},

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,6 +48,21 @@ 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] === '(') {
+ 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 \\( ... \\)'
+ if (vscode.workspace.getConfiguration('editor', document.uri).get('autoClosingBrackets')) {
+ inlineMath.range = new vscode.Range(position, position.translate(0, 1))
+ }
+ resolve([inlineMath])
+ return
+ } else {
+ return
+ }
+ }
+
const line = document.lineAt(position.line).text.substr(0, position.character)
for (const type of ['citation', 'reference', 'environment', 'command']) {
const suggestions = this.completion(type, line)

latex inline math completion