add: configuration for compile and makeindex processes,
add: LaTeX root file configuration
This commit is contained in:
parent
eeea3268a0
commit
97c1c47e72
29
package.json
29
package.json
|
@ -50,7 +50,34 @@
|
||||||
"latex.shell": {
|
"latex.shell": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "\\bin\\bash",
|
"default": "\\bin\\bash",
|
||||||
"description": "The shell to be used for child processes like the compile commands pdflatex or cleanup commands."
|
"description": "The shell to be used for child processes like the compile command."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"title": "LaTeX compile process",
|
||||||
|
"properties": {
|
||||||
|
"latex.pdflatex": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"${fileDirname}\" \"${file}\"",
|
||||||
|
"description": "The compile command."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"title": "LaTeX make index process",
|
||||||
|
"properties": {
|
||||||
|
"latex.makeindex": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "makeindex ${fileBasenameNoExtension}",
|
||||||
|
"description": "The compile command."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"title": "LaTeX root file",
|
||||||
|
"properties": {
|
||||||
|
"latex.rootFile": {
|
||||||
|
"type": "string",
|
||||||
|
"default": null,
|
||||||
|
"description": "The root file for the compile process, if not set the current file will be used for the compile process. If there is a root file for the cimpilation this property must be specified or you allways have to compile with the root file as current opened file."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
117
src/commands.ts
117
src/commands.ts
|
@ -3,44 +3,44 @@ import * as child_process from 'child_process';
|
||||||
import documentclass_symbols from '../dictionary/documentclass_symbols';
|
import documentclass_symbols from '../dictionary/documentclass_symbols';
|
||||||
import { window, Range } from 'vscode';
|
import { window, Range } from 'vscode';
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// ${workspaceFolder} - the path of the workspace folder that contains the tasks.json file
|
${workspaceFolder} - the path of the workspace folder that contains the tasks.json file
|
||||||
// ${workspaceFolderBasename} - the name of the workspace folder that contains the tasks.json file without any slashes (/)
|
${workspaceFolderBasename} - the name of the workspace folder that contains the tasks.json file without any slashes (/)
|
||||||
// ${file} - the current opened file
|
${file} - the current opened file
|
||||||
// ${relativeFile} - the current opened file relative to the workspace folder containing the file
|
${relativeFile} - the current opened file relative to the workspace folder containing the file
|
||||||
// ${fileBasename} - the current opened file's basename
|
${fileBasename} - the current opened file's basename
|
||||||
// ${fileBasenameNoExtension} - the current opened file's basename without the extension
|
${fileBasenameNoExtension} - the current opened file's basename without the extension
|
||||||
// ${fileDirname} - the current opened file's dirname
|
${fileDirname} - the current opened file's dirname
|
||||||
// ${fileExtname} - the current opened file's extension
|
${fileExtname} - the current opened file's extension
|
||||||
// ${cwd} - the task runner's current working directory on startup
|
${cwd} - the task runner's current working directory on startup
|
||||||
// ${lineNumber} - the current selected line number in the active file
|
${lineNumber} - the current selected line number in the active file
|
||||||
// */
|
*/
|
||||||
// function commandVariableSubstitution(variable: string, document: vscode.TextDocument): string {
|
function commandVariableSubstitution(variable: string, fileName: string): string {
|
||||||
// switch (variable) {
|
switch (variable) {
|
||||||
// case "${workspaceFolder}":
|
case "${workspaceFolder}":
|
||||||
// throw new Error("[ commandVariableSubstitution ] Not Implemented.");
|
return vscode.workspace.rootPath;
|
||||||
// case "${workspaceFolderBasename}":
|
case "${workspaceFolderBasename}":
|
||||||
// throw new Error("[ commandVariableSubstitution ] Not Implemented.");
|
return vscode.workspace.rootPath; // TODO:
|
||||||
// case "${file}":
|
case "${file}":
|
||||||
// return document.fileName;
|
return fileName;
|
||||||
// case "${relativeFile}":
|
case "${relativeFile}":
|
||||||
// throw new Error("[ commandVariableSubstitution ] Not Implemented.");
|
throw new Error("[ commandVariableSubstitution ] Not Implemented.");
|
||||||
// case "${fileBasename}":
|
case "${fileBasename}":
|
||||||
// return document.fileName.substring(document.fileName.lastIndexOf('/') + 1);
|
return fileName.substring(fileName.lastIndexOf('/') + 1);
|
||||||
// case "${fileBasenameNoExtension}":
|
case "${fileBasenameNoExtension}":
|
||||||
// return document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.'));
|
return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
||||||
// case "${fileDirname}":
|
case "${fileDirname}":
|
||||||
// return document.fileName.substring(0, document.fileName.lastIndexOf('/'));
|
return fileName.substring(0, fileName.lastIndexOf('/'));
|
||||||
// case "${fileExtname}":
|
case "${fileExtname}":
|
||||||
// return document.fileName.substring(document.fileName.lastIndexOf('.') + 1);
|
return fileName.substring(fileName.lastIndexOf('.') + 1);
|
||||||
// case "${cwd}":
|
case "${cwd}":
|
||||||
// throw new Error("[ commandVariableSubstitution ] Not supported.");
|
return vscode.workspace.rootPath;
|
||||||
// case "${lineNumber}":
|
case "${lineNumber}":
|
||||||
// throw new Error("[ commandVariableSubstitution ] Not supported.");
|
throw new Error("[ commandVariableSubstitution ] Not supported.");
|
||||||
// default:
|
default:
|
||||||
// throw new Error("[ commandVariableSubstitution ] variable not found.");
|
throw new Error("[ commandVariableSubstitution ] variable not found.");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
var decorationOptions: vscode.DecorationRenderOptions = {
|
var decorationOptions: vscode.DecorationRenderOptions = {
|
||||||
borderRadius: "3px",
|
borderRadius: "3px",
|
||||||
|
@ -69,13 +69,15 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
var document: vscode.TextDocument = textEditor.document;
|
var document: vscode.TextDocument = textEditor.document;
|
||||||
var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/'));
|
var fileName: string = this.settings.rootFile || document.fileName;
|
||||||
|
var fileDir: string = fileName.substring(0, fileName.lastIndexOf('/'));
|
||||||
var outputChannel: vscode.OutputChannel = this.outputChannel;
|
var outputChannel: vscode.OutputChannel = this.outputChannel;
|
||||||
|
|
||||||
outputChannel.clear(); // clear the outputChannel to only show the last output
|
outputChannel.clear(); // clear the outputChannel to only show the last output
|
||||||
document.save(); // save the document before compile
|
document.save(); // save the document before compile
|
||||||
child_process.exec(
|
child_process.exec(
|
||||||
"pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"" + fileDir + "\" \"" + document.fileName + "\"",
|
// "pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"" + fileDir + "\" \"" + fileName + "\"",
|
||||||
|
this.settings.pdflatex.replace(/\$\{[A-Za-z]+\}/g,(str) => commandVariableSubstitution(str, fileName)),
|
||||||
{ cwd: fileDir }, // set the working directory
|
{ cwd: fileDir }, // set the working directory
|
||||||
(error: Error, stdout: string, stderr: string) => {
|
(error: Error, stdout: string, stderr: string) => {
|
||||||
var decorationRanges: vscode.Range[] = [];
|
var decorationRanges: vscode.Range[] = [];
|
||||||
|
@ -96,7 +98,7 @@ export default {
|
||||||
outputChannel.append(output);
|
outputChannel.append(output);
|
||||||
} else {
|
} else {
|
||||||
vscode.window.setStatusBarMessage("pdflatex succeeded: see output", 5000);
|
vscode.window.setStatusBarMessage("pdflatex succeeded: see output", 5000);
|
||||||
outputChannel.appendLine("pdflatex succeeded: created file " + document.fileName.replace('.tex', '.pdf'));
|
outputChannel.appendLine("pdflatex succeeded: created file " + fileName.replace('.tex', '.pdf'));
|
||||||
}
|
}
|
||||||
textEditor.setDecorations(LaTeX_error_decoration_type, decorationRanges);
|
textEditor.setDecorations(LaTeX_error_decoration_type, decorationRanges);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +111,8 @@ export default {
|
||||||
|
|
||||||
textEditor.document.save(); // save the document before makeindex
|
textEditor.document.save(); // save the document before makeindex
|
||||||
child_process.exec(
|
child_process.exec(
|
||||||
"makeindex " + document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')),
|
// "makeindex " + document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')),
|
||||||
|
this.settings.makeindex.replace(/\$\{[A-Za-z]+\}/g, (str) => commandVariableSubstitution(str, document.fileName)),
|
||||||
{ cwd: fileDir }, // set the working directory
|
{ cwd: fileDir }, // set the working directory
|
||||||
(error: Error, stdout: string, stderr: string) => {
|
(error: Error, stdout: string, stderr: string) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -123,35 +126,5 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
|
||||||
latex_cleanup: function latex_cleanup(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void {
|
|
||||||
var document: vscode.TextDocument = textEditor.document;
|
|
||||||
var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/'));
|
|
||||||
var fileName: string = document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.'));
|
|
||||||
var outputChannel: vscode.OutputChannel = this.outputChannel;
|
|
||||||
|
|
||||||
child_process.exec("\
|
|
||||||
for file in \"" + fileName + "\".*; do \
|
|
||||||
for end in \"aux\" \"idx\" \"ilg\" \"ind\" \"log\" \"out\" \"toc\" \"synctex.gz\"; do \
|
|
||||||
if [[ \"$file\" == *.\"$end\" ]]; then \
|
|
||||||
rm \"$file\"; \
|
|
||||||
echo removed: \"$file\"; \
|
|
||||||
fi; \
|
|
||||||
done; \
|
|
||||||
done;",
|
|
||||||
{ cwd: fileDir, shell: this.settings["latex.shell"] },
|
|
||||||
(error: Error, stdout: string, stderr: string) => {
|
|
||||||
if (error) {
|
|
||||||
vscode.window.showErrorMessage("cleanup Failed: see output.");
|
|
||||||
outputChannel.show();
|
|
||||||
outputChannel.appendLine("cleanup Failed: " + error.message);
|
|
||||||
outputChannel.append(stdout + "\n" + stderr);
|
|
||||||
} else {
|
|
||||||
vscode.window.setStatusBarMessage("cleanup succeeded", 5000);
|
|
||||||
outputChannel.appendLine('Directory "' + fileDir + '" cleaned');
|
|
||||||
outputChannel.append(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
// to be equal to the 'command' field in the package.json file
|
// to be equal to the 'command' field in the package.json file
|
||||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.pdflatex', Commands.latex_pdflatex, commands_this_context ));
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.pdflatex', Commands.latex_pdflatex, commands_this_context ));
|
||||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.makeindex', Commands.latex_makeindex, commands_this_context ));
|
context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.makeindex', Commands.latex_makeindex, commands_this_context ));
|
||||||
context.subscriptions.push(vscode.commands.registerTextEditorCommand( 'latex.cleanup', Commands.latex_cleanup, commands_this_context ));
|
|
||||||
|
|
||||||
// Register the Completion Item Provider
|
// Register the Completion Item Provider
|
||||||
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
|
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
|
||||||
|
|
Loading…
Reference in New Issue