Skip to content

Commit

Permalink
WSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikPeters committed Aug 18, 2024
1 parent 61e519f commit 6af6e5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>), 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
Expand All @@ -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.

Expand All @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
},
Expand Down
29 changes: 24 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 6af6e5f

Please sign in to comment.