Skip to content

Instantly share code, notes, and snippets.

@Joao-Peterson
Created October 20, 2022 07:50
Show Gist options
  • Save Joao-Peterson/e8a480bd6c56a4b3b7bacfc1745da4c1 to your computer and use it in GitHub Desktop.
Save Joao-Peterson/e8a480bd6c56a4b3b7bacfc1745da4c1 to your computer and use it in GitHub Desktop.
Latex/Synctex forward/reverse search between vscode and Okular

On vscode you can setup a build task like this:

vscode -> okular

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "isBackground": true,
            "promptOnClose": false,
            "command": "make SYNC_LINE=${lineNumber} SYNC_FILE=${relativeFile}",
            "problemMatcher": [],
            "presentation": {
                "echo": true,
                "reveal": "silent",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": false,
                "clear": false
            },
            "group": {
                "kind": "build",
                "isDefault": true,
            }
        }
    ],
}

And a Makefile like this:

TEX_CC=lualatex
TEX_FLAGS=--shell-escape --interaction=batchmode --halt-on-error --synctex=-1
####################################################################################
SYNC_LINE = 1
SYNC_FILE = main.tex
####################################################################################

.PHONY : main.aux

quick : main.aux

main.aux : main.tex sync
	$(TEX_CC) $(TEX_FLAGS) $<

sync :
	okular --unique --noraise main.pdf#src:$(SYNC_LINE)$(SYNC_FILE)

Now every time you press ctrl+shift+b vscode will invoke make, compile the project and then sync to okular

okular -> vscode

From okular go to: Settings -> Configure Okular -> Editor, select:

Editor:  Custom Text Editor
Command: code --goto %f:%l

Now everytime you go to a line, press shift+leftMouse, okular will sync to vscode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment