85 lines
3.8 KiB
TypeScript
85 lines
3.8 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import * as child_process from 'child_process';
|
|
import documentclass_symbols from '../dictionary/documentclass_symbols';
|
|
import { window } from 'vscode';
|
|
|
|
export default {
|
|
// pdflatex -synctex=1 -interaction=nonstopmode -output-directory="$FILEDIRNAME" "$FILE" > ~/.vscode/.pdflatex_log
|
|
|
|
latex_pdflatex: function latex_pdflatex(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void {
|
|
var document: vscode.TextDocument = textEditor.document;
|
|
var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/'));
|
|
var outputChannel: vscode.OutputChannel = this.outputChannel;
|
|
|
|
outputChannel.clear(); // clear the outputChannel to only show the last output
|
|
document.save(); // save the document before compile
|
|
child_process.exec(
|
|
"pdflatex -synctex=1 -interaction=nonstopmode -output-directory=\"" + fileDir + "\" \"" + document.fileName + "\"",
|
|
{ cwd: fileDir }, // set the working directory
|
|
(error: Error, stdout: string, stderr: string) => {
|
|
if (error) {
|
|
vscode.window.showErrorMessage("pdflatex Failed: see output.");
|
|
outputChannel.show();
|
|
outputChannel.appendLine("pdflatex Failed: " + error.message);
|
|
outputChannel.append(stdout + "\n" + stderr);
|
|
} else {
|
|
vscode.window.setStatusBarMessage("pdflatex succeeded: see output", 5000);
|
|
outputChannel.appendLine("pdflatex succeeded: created file " + document.fileName.replace('.tex', '.pdf'));
|
|
}
|
|
}
|
|
);
|
|
},
|
|
latex_makeindex: function latex_makeindex(textEditor: vscode.TextEditor, textEditorEdit: vscode.TextEditorEdit): void {
|
|
var document: vscode.TextDocument = textEditor.document;
|
|
var fileDir: string = document.fileName.substring(0, document.fileName.lastIndexOf('/'));
|
|
var outputChannel: vscode.OutputChannel = this.outputChannel;
|
|
|
|
textEditor.document.save(); // save the document before makeindex
|
|
child_process.exec(
|
|
"makeindex " + document.fileName.substring(document.fileName.lastIndexOf('/') + 1, document.fileName.lastIndexOf('.')),
|
|
{ cwd: fileDir }, // set the working directory
|
|
(error: Error, stdout: string, stderr: string) => {
|
|
if (error) {
|
|
vscode.window.showErrorMessage("makeindex Failed: see output.");
|
|
outputChannel.show();
|
|
outputChannel.appendLine("makeindex Failed: " + error.message);
|
|
outputChannel.append(stdout + "\n" + stderr);
|
|
} else {
|
|
vscode.window.setStatusBarMessage("makeindex succeeded", 5000);
|
|
outputChannel.appendLine("makeindex succeeded: created *.ind file\n" + stdout);
|
|
}
|
|
}
|
|
);
|
|
},
|
|
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);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|