sanjib-sen / WebLaTex

A complete alternative for Overleaf with VSCode + Web + Git Integration + Copilot + Grammar & Spell Checker + Live Collaboration Support. Based on GitHub Codespace and Dev container.
https://github.com/sanjib-sen/weblatex/generate
MIT License
1.04k stars 295 forks source link

Sync and View with external Viewer #24

Open MightyMirko opened 10 months ago

MightyMirko commented 10 months ago

Hello,

is there a way to sync and view with, lets say, sumatraPDF in windows?

sanjib-sen commented 10 months ago

@MightyMirko Do you want to use the local VSCode instead of GitHub codespace? In that case sure.

Add this to .vscode/settings.json file:

"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.synctex.command": "C:/Users/<UserName>/AppData/Local/SumatraPDF/SumatraPDF.exe",
  "latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "-reuse-instance",
    "-inverse-search",
    "\"C:\\Users\\<Username>\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"C:\\Users\\<U>\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
    "%PDF%"
  ],

In settings.txt of SumatraPDF, set

InverseSearchCmdLine = "C:\Users\<Username>\AppData\Local\Programs\Microsoft VS Code\Code.exe" "C:\Users\<Username>\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js" --ms-enable-electron-run-as-node -r -g "%f:%l"
EnableTeXEnhancements = true

Reference: https://github.com/James-Yu/LaTeX-Workshop/wiki/View#sumatrapdf

MightyMirko commented 10 months ago

I am using it in a docker on wsl2 environment.

Instead of path to c i have to assign path to mnt/c?

MightyMirko commented 10 months ago
{
    "name": "latex-docker-workspace",
    "image": "your-docker-image:latest",
    "remoteUser": "root",
    "hostRequirements": {
        "storage": "32gb"
    },
    "remoteEnv": {
        "user": "your-username",
        "sumatraPath": "/mnt/c/Program Files/SumatraPDF/SumatraPDF.exe",
        "vscodePath": "/mnt/c/Users/${user}/AppData/Local/Programs/Microsoft VS Code/Code.exe",
        "vscodeCliPath": "/mnt/c/Users/${user}/AppData/Local/Programs/Microsoft VS Code/resources/app/out/cli.js"
    },
    "features": {},
    "customizations": {
        "vscode": {
            "settings": {
                "latex-workshop.view.pdf.viewer": "external",
                "latex-workshop.view.pdf.external.synctex.command": "${sumatraPath}",
                "latex-workshop.view.pdf.external.synctex.args": [
                    "-forward-search",
                    "%TEX%",
                    "%LINE%",
                    "-reuse-instance",
                    "-inverse-search",
                    "\"${vscodePath}\" \"${vscodeCliPath}\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
                    "%PDF%"
                ]
            },
            "extensions": [
                "James-Yu.latex-workshop"
                // Add other extensions if needed
            ]
        }
    }
}

This works in one direction for now