diff --git a/README.md b/README.md
index 42f1eef..3b323f8 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,8 @@ Visual Studio Code extension for interacting with [TeXpresso](https://github.com
![ezgif-6-3b2ad402f4](https://github.com/DominikPeters/texpresso-vscode/assets/3543224/0ff5cf57-5a2e-48cd-9e5f-633a5ed44411)
+After installing the extension, you need to configure the path to the TeXpresso binary in the settings.
+
To use this extension, open the `.tex` document you wish to edit, then open the command pallete (Ctrl + Shift + P), and select `TeXpresso: Start Document`. A separate window will open showing the compiled preview. The preview immediately updates when you edit the file in VS Code, and using SyncTeX the preview automatically jumps to the current code position (and vice versa for clicks in the preview window). Buttons at the top of the editor are provided to switch pages, and a compile log for seeing compilation errors can be found by using the Output panel.
## Features
@@ -28,6 +30,7 @@ TeXpresso must be installed, and must be callable at the path provided in the `t
This extension contributes the following settings:
* `texpresso.command`: The path to the texpresso binary.
+* `texpresso.useWSL`: Controls whether to run TeXpresso within Windows Subsystem for Linux (WSL).
* `texpresso.syncTeXForwardOnSelection`: Controls whether the preview should be updated when the selection in the editor changes.
* `texpresso.useEditorTheme`: Controls whether the preview should use the same color theme as the editor.
@@ -43,6 +46,10 @@ Loses connection if the filename of the main document is changed.
## Release Notes
+### 1.4.0
+
+Add support for executing TeXpresso on WSL (Windows Subsystem for Linux).
+
### 1.3.0
Add a button for toggling automatic SyncTeX forward when the selection changes.
diff --git a/package.json b/package.json
index c642345..657a35a 100644
--- a/package.json
+++ b/package.json
@@ -94,18 +94,23 @@
"properties": {
"texpresso.command": {
"type": "string",
- "default": "/Users/dominik/GitHub/texpresso/build/texpresso",
+ "default": "texpresso",
"description": "Path to the texpresso binary"
},
+ "texpresso.useWSL": {
+ "type": "boolean",
+ "default": false,
+ "description": "Specifies whether texpresso should be run in WSL (Windows Subsystem for Linux)"
+ },
"texpresso.syncTeXForwardOnSelection": {
"type": "boolean",
"default": true,
- "description": "Controls whether the preview should be updated when the selection in the editor changes (SyncTeX forward)"
+ "description": "Specifies whether the preview should be updated when the selection in the editor changes (SyncTeX forward)"
},
"texpresso.useEditorTheme": {
"type": "boolean",
"default": false,
- "description": "Controls whether the preview should use the same color theme as the editor (if activated), or the default theme (otherwise)"
+ "description": "Specifies whether the preview should use the same color theme as the editor (if activated), or the default theme (otherwise)"
}
}
},
diff --git a/src/extension.ts b/src/extension.ts
index d5dbebf..f461585 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
-import { ChildProcess, spawn } from 'child_process';
+import { ChildProcess, spawn, execSync } from 'child_process';
import * as tmp from 'tmp';
import * as fs from 'fs';
@@ -22,6 +22,8 @@ export function activate(context: vscode.ExtensionContext) {
let providedOutput = "";
let outputChanged = true;
+ const useWSL = vscode.workspace.getConfiguration('texpresso').get('useWSL') as boolean;
+
let activeEditor: vscode.TextEditor | undefined;
function startDocumentFromEditor(editor: vscode.TextEditor | undefined) {
@@ -49,21 +51,38 @@ export function activate(context: vscode.ExtensionContext) {
const command = vscode.workspace.getConfiguration('texpresso').get('command') as string;
// Check if command exists
try {
- fs.accessSync(command, fs.constants.X_OK);
+ if (!useWSL) {
+ fs.accessSync(command, fs.constants.X_OK);
+ } else {
+ fs.accessSync('wsl', fs.constants.X_OK);
+ execSync(`wsl -e test -x ${command}`);
+ }
} catch (error) {
+ let message = `TeXpresso command '${command}' does not exist or is not executable. Please check the 'texpresso.command' setting.`;
+ if (process.platform === 'win32') {
+ message = `TeXpresso command '${command}' does not exist or is not executable. Please check the 'texpresso.command' and 'texpresso.wsl' settings.`;
+ if (useWSL) {
+ message = `TeXpresso command '${command}' is not executable, or the 'wsl' command is not available. Please check the 'texpresso.command' and 'texpresso.wsl' settings.`;
+ }
+ }
vscode.window.showErrorMessage(
- `TeXpresso command '${command}' does not exist or is not executable. Please check the 'texpresso.command' setting.`,
+ message,
'Open Settings'
).then(value => {
if (value === 'Open Settings') {
- vscode.commands.executeCommand('workbench.action.openSettings', 'texpresso.command');
+ vscode.commands.executeCommand('workbench.action.openSettings', 'texpresso.');
}
});
return;
}
// react to messages from texpresso
- texpresso = spawn(command, ['-json', filePath]);
+ if (!useWSL) {
+ texpresso = spawn(command, ['-json', filePath]);
+ } else {
+ filePath = execSync(`wsl wslpath "${filePath}"`).toString().trim();
+ texpresso = spawn('wsl', ['-e', command, '-json', filePath]);
+ }
if (texpresso && texpresso.stdout) {
texpresso.stdout.on('data', data => {
const message = JSON.parse(data.toString());