mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-04 07:07:54 +03:00
Initial commit
This commit is contained in:
parent
03c108503a
commit
c9c05ea024
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
out
|
||||
node_modules
|
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
|
||||
"preLaunchTask": "npm"
|
||||
},
|
||||
{
|
||||
"name": "Launch Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
|
||||
"preLaunchTask": "npm"
|
||||
}
|
||||
]
|
||||
}
|
10
.vscode/settings.json
vendored
Normal file
10
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
|
||||
}
|
30
.vscode/tasks.json
vendored
Normal file
30
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// Available variables which can be used inside of strings.
|
||||
// ${workspaceRoot}: the root folder of the team
|
||||
// ${file}: the current opened file
|
||||
// ${fileBasename}: the current opened file's basename
|
||||
// ${fileDirname}: the current opened file's dirname
|
||||
// ${fileExtname}: the current opened file's extension
|
||||
// ${cwd}: the current working directory of the spawned process
|
||||
|
||||
// A task runner that calls a custom npm script that compiles the extension.
|
||||
{
|
||||
"version": "0.1.0",
|
||||
|
||||
// we want to run npm
|
||||
"command": "npm",
|
||||
|
||||
// the command is a shell script
|
||||
"isShellCommand": true,
|
||||
|
||||
// show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
|
||||
// we run the custom script "compile" as defined in package.json
|
||||
"args": ["run", "compile", "--loglevel", "silent"],
|
||||
|
||||
// The tsc compiler is started in watching mode
|
||||
"isWatching": true,
|
||||
|
||||
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
|
||||
"problemMatcher": "$tsc-watch"
|
||||
}
|
9
.vscodeignore
Normal file
9
.vscodeignore
Normal file
@ -0,0 +1,9 @@
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
out/test/**
|
||||
test/**
|
||||
src/**
|
||||
**/*.map
|
||||
.gitignore
|
||||
tsconfig.json
|
||||
vsc-extension-quickstart.md
|
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Change Log
|
||||
All notable changes to the "latex-workshop" extension will be documented in this file.
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [Unreleased]
|
||||
- Initial release
|
59
README.md
Normal file
59
README.md
Normal file
@ -0,0 +1,59 @@
|
||||
# Visual Studio Code LaTeX Workshop Extension
|
||||
|
||||
LaTeX Workshop is an extension for Visual Studio Code, aiming to provide all-in-one features and utilities for latex typesetting with Visual Studio Code.
|
||||
|
||||
## Features
|
||||
|
||||
-
|
||||
|
||||
## Requirements
|
||||
|
||||
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
|
||||
|
||||
## Extension Settings
|
||||
|
||||
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
|
||||
|
||||
For example:
|
||||
|
||||
This extension contributes the following settings:
|
||||
|
||||
* `myExtension.enable`: enable/disable this extension
|
||||
* `myExtension.thing`: set to `blah` to do something
|
||||
|
||||
## Known Issues
|
||||
|
||||
Calling out known issues can help limit users opening duplicate issues against your extension.
|
||||
|
||||
## Release Notes
|
||||
|
||||
Users appreciate release notes as you update your extension.
|
||||
|
||||
### 1.0.0
|
||||
|
||||
Initial release of ...
|
||||
|
||||
### 1.0.1
|
||||
|
||||
Fixed issue #.
|
||||
|
||||
### 1.1.0
|
||||
|
||||
Added features X, Y, and Z.
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------
|
||||
|
||||
## Working with Markdown
|
||||
|
||||
**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
|
||||
|
||||
* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
|
||||
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
|
||||
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets
|
||||
|
||||
### For more information
|
||||
|
||||
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
|
||||
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
|
||||
|
||||
**Enjoy!**
|
36
package.json
Normal file
36
package.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "latex-workshop",
|
||||
"displayName": "LaTeX Workshop",
|
||||
"description": "AIO LaTeX extension to preview, compile, hint, and more.",
|
||||
"version": "0.0.1",
|
||||
"publisher": "jamesyu",
|
||||
"engines": {
|
||||
"vscode": "^1.5.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:latex-workshop.compile"
|
||||
],
|
||||
"main": "./out/src/extension",
|
||||
"contributes": {
|
||||
"commands": [{
|
||||
"command": "latex-workshop.compile",
|
||||
"title": "LaTeX Workshop: Compile LaTeX"
|
||||
}]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"test": "node ./node_modules/vscode/bin/test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.0.3",
|
||||
"vscode": "^1.0.0",
|
||||
"mocha": "^2.3.3",
|
||||
"@types/node": "^6.0.40",
|
||||
"@types/mocha": "^2.2.32"
|
||||
}
|
||||
}
|
86
src/extension.ts
Normal file
86
src/extension.ts
Normal file
@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
var output_channel;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
console.log('LaTeX Workshop activated.');
|
||||
output_channel = vscode.window.createOutputChannel('LaTeX Workshop');
|
||||
|
||||
// Code heavily borrowed from LaTeXCompile extension
|
||||
let compile_func = vscode.commands.registerCommand('latex-workshop.compile', compile);
|
||||
|
||||
context.subscriptions.push(compile_func);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() {
|
||||
}
|
||||
|
||||
function compile() {
|
||||
// Settings
|
||||
var compiler = 'pdflatex',
|
||||
args = '-halt-on-error -file-line-error',
|
||||
cmds = ['%compiler% %args% %document%',
|
||||
'bibtex %document%',
|
||||
'%compiler% %args% %document%',
|
||||
'%compiler% %args% %document%'];
|
||||
|
||||
var exec = require('child_process').exec;
|
||||
vscode.workspace.saveAll();
|
||||
|
||||
// Develop file name relatex variables
|
||||
var file_full_path = vscode.window.activeTextEditor.document.fileName;
|
||||
var file_path = (file_full_path.match(/(.*)[\/\\]/)[1] || '') + '/';
|
||||
var file_name_ext = file_full_path.replace(/^.*[\\\/]/, '');
|
||||
var file_name = file_name_ext.split('.')[0];
|
||||
var file_ext = file_name_ext.split('.')[1];
|
||||
var file_output = file_path + file_name + '.pdf';
|
||||
|
||||
if (file_ext != 'tex') {
|
||||
vscode.window.showErrorMessage('You can only compile LaTeX from a .tex file.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Change working directory for console commands
|
||||
var cmd_change_dir = ((process.platform == "win32")?'cd /d ':'cd ') + '"' + file_path + '" && '
|
||||
|
||||
// Create compilation commands and sequence
|
||||
var compile_error = false;
|
||||
function compile_cmd(cmds, idx) {
|
||||
// Create compilation command
|
||||
var cmd = cmds[idx];
|
||||
cmd = replace_all(cmd, '%compiler%', compiler);
|
||||
cmd = replace_all(cmd, '%args%', args);
|
||||
cmd = replace_all(cmd, '%document%', '"' + file_name + '"');
|
||||
vscode.window.setStatusBarMessage('LaTeX compilation step ' + String(idx + 1) + ': ' + cmd, 3000);
|
||||
|
||||
// Execute the command, set its callback to the next command
|
||||
var out = exec(cmd_change_dir + cmd, function(){
|
||||
// More commands to come
|
||||
if ((idx < cmds.length - 1) && !compile_error)
|
||||
compile_cmd(cmds, idx + 1);
|
||||
// Just finished the last one
|
||||
else if (idx >= cmds.length - 1)
|
||||
vscode.window.setStatusBarMessage('LaTeX compiled.', 3000);
|
||||
});
|
||||
|
||||
// Detect if error occurs
|
||||
out.stdout.on('data', function(data){
|
||||
output_channel.append(data);
|
||||
if (String(data).toLowerCase().indexOf('error') <= 0 || compile_error)
|
||||
return;
|
||||
compile_error = true;
|
||||
output_channel.show();
|
||||
vscode.window.showErrorMessage('An error occurs when compiling LaTeX. See compilation log for details.');
|
||||
})
|
||||
}
|
||||
output_channel.clear();
|
||||
compile_cmd(cmds, 0)
|
||||
}
|
||||
|
||||
function replace_all(str, from, to) {
|
||||
return str.split(from).join(to);
|
||||
}
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "."
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user