Skip to content

Instantly share code, notes, and snippets.

@sampolgar
Created December 16, 2023 01:44
Show Gist options
  • Select an option

  • Save sampolgar/6fe6351ea505e06bf56d5d9a58344d60 to your computer and use it in GitHub Desktop.

Select an option

Save sampolgar/6fe6351ea505e06bf56d5d9a58344d60 to your computer and use it in GitHub Desktop.
Overleaf + Git integration
https://www.reddit.com/r/LaTeX/comments/mac1rf/vscodelatex_workshopoverleafbuiltin_git_is_a/
Edit: To those who want to know how I set it up, this is what I did (I hope I didn't miss out on anything).
I use a MacBook so I installed git and mactex-no-gui via brew. The latter takes quite a lot of time so brew (heh) some coffee.
So the way I remember doing it was cloning one of my Overleaf projects via the terminal. I then installed the Latex Workshop and Git extensions in VSCode and opened the cloned repo in VSCode as a folder.
After making changes, committing stuff, and pushing, the Git extension prompts for the Overleaf username and password. I think it caches the credentials (I believe the git credential helper is activated by default for me) because it has never asked me for the credentials ever again. Now all I need to do is keep editing and pushing commits and it immediately reflects online on Overleaf!
Note: Remember to use the built-in Git clone option on Overleaf and not the GitHub option. The GitHub option essentially creates a mirror repo on GitHub and you must manually sync changes between the repo and overleaf.
I then edited my configs. I basically hacked together stuff I found online. To somewhat match Overleaf's keyboard shortcuts for bold font and italics, I added this code to my VSCode's keybindings.json file:
// Place your key bindings in this file to override the defaults
[
{
"key": "cmd+shift+B",
"command": "editor.action.insertSnippet",
"when": "editorHasSelection && resourceExtname == .tex",
"args": {
"snippet": "\\textbf{${TM_SELECTED_TEXT}}$0"
}
},
{
"key": "cmd+shift+I",
"command": "editor.action.insertSnippet",
"when": "editorHasSelection && resourceExtname == .tex",
"args": {
"snippet": "\\textit{${TM_SELECTED_TEXT}}$0"
}
},
{
"key": "cmd+shift+B",
"command": "editor.action.insertSnippet",
"when": "!editorHasSelection && resourceExtname == .tex",
"args": {
"snippet": "\\textbf{$0}"
}
},
{
"key": "cmd+shift+I",
"command": "editor.action.insertSnippet",
"when": "!editorHasSelection && resourceExtname == .tex",
"args": {
"snippet": "\\textit{$0}"
}
},
]
I also added the following to my user settings .json file in VSCode (Preferences: Configure Language Specific Settings). By default latexmk utilizes pdftex. I wanted lualatex so I overrode the settings here and added settings for XeTeX. I also like rebuilding documents when I save a file so I added the onSave option that you can see right at the end.
{
"workbench.colorTheme": "Default Light+",
"[latex]": {
"editor.wordWrap" : "on",
"editor.formatOnPaste": false,
"editor.suggestSelection": "recentlyUsedByPrefix"
},
"latex-workshop.view.pdf.viewer": "tab",
"editor.minimap.enabled": false,
"latex-workshop.latex.recipes": [
{
"name": "lulatexmk πŸ”ƒ",
"tools": [
"lualatexmk"
]
},
{
"name": "latexmk πŸ”ƒ",
"tools": [
"latexmk"
]
},
{
"name": "xelatexmk πŸ”ƒ",
"tools": [
"xelatexmk"
]
},
{
"name": "platexmk πŸ”ƒ",
"tools": [
"platexmk"
]
},
{
"name": "pdflatex ➞ bibtex ➞ pdflatex`Γ—2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex ➞ biber ➞ xelatex",
"tools": [
"xelatex",
"biber",
"xelatex"
]
}
],
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-file-line-error",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "platexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "xelatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-file-line-error",
"-xelatex",
"-outdir=%OUTDIR%",
"-interaction=nonstopmode",
"-halt-on-error",
"%DOC%"
],
"env": {}
},
{
"name": "lualatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-file-line-error",
"-lualatex",
"-outdir=%OUTDIR%",
"-interaction=nonstopmode",
"-halt-on-error",
"%DOC%"
],
"env": {}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-halt-on-error",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-halt-on-error",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
],
"env": {}
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOCFILE%"
],
"env": {}
}
],
"latex-workshop.latex.autoBuild.run": "onSave"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment