|
| 1 | +--- |
| 2 | +title: "All-platform Local LaTeX Solution" |
| 3 | +date: 2025-04-24T12:11:03+08:00 |
| 4 | +# weight: 1 |
| 5 | +# aliases: ["/first"] |
| 6 | +tags: ["LaTeX", "Academic"] |
| 7 | +author: "Square Zhong" |
| 8 | +# author: ["Me", "You"] # multiple authors |
| 9 | +showToc: true |
| 10 | +TocOpen: false |
| 11 | +draft: false |
| 12 | +hidemeta: false |
| 13 | +comments: false |
| 14 | +description: "Maybe Overleaf is better." |
| 15 | +canonicalURL: "https://canonical.url/to/page" |
| 16 | +disableHLJS: true # to disable highlightjs |
| 17 | +disableShare: false |
| 18 | +disableHLJS: false |
| 19 | +hideSummary: false |
| 20 | +searchHidden: false |
| 21 | +ShowReadingTime: true |
| 22 | +ShowBreadCrumbs: true |
| 23 | +ShowPostNavLinks: true |
| 24 | +ShowWordCount: true |
| 25 | +ShowRssButtonInSectionTermList: true |
| 26 | +UseHugoToc: true |
| 27 | +cover: |
| 28 | + image: "<image path/url>" # image path/url |
| 29 | + alt: "<alt text>" # alt text |
| 30 | + caption: "<text>" # display caption under cover |
| 31 | + relative: false # when using page bundles set this to true |
| 32 | + hidden: true # only hide on current single page |
| 33 | +editPost: |
| 34 | + URL: "https://github.com/squarezhong.github.io/content" |
| 35 | + Text: "Suggest Changes" # edit text |
| 36 | + appendFilePath: true # to append file path to Edit link |
| 37 | +--- |
| 38 | + |
| 39 | +**(MacTex/MiKTeX + VSCode + LaTeX Workshop)** |
| 40 | + |
| 41 | +All you need are MacTeX/MiKTeX and LaTex Workshop Extension. |
| 42 | + |
| 43 | +## Installation |
| 44 | + |
| 45 | +### 1. Install local LaTeX environment |
| 46 | + |
| 47 | +- macOS |
| 48 | + |
| 49 | + Install MacTeX, you can refer to this [link](http://www.tug.org/mactex/mactex-download.html), or if you are a homebrew (highly recommended) user, you can simply use `brew install mactex` to finish this. |
| 50 | + |
| 51 | + |
| 52 | +- Windows / Linux |
| 53 | + |
| 54 | + Refer to [miktex](https://miktex.org/download). |
| 55 | + |
| 56 | +### 2. Install **LaTeX Workshop** VS Code extension. |
| 57 | + |
| 58 | +- Configure the LaTeX Workshop. In fact this extension is **out-of-box**, but if you want better experience, you can add following code in `settings.json` ( press *command / ctrl + shift + P* then type “open” to search for “Preference: Open User Settings (JSON)” |
| 59 | + |
| 60 | +## Configuration |
| 61 | + |
| 62 | +- JSON Configuration for LaTeX Workshop |
| 63 | + |
| 64 | + ```json |
| 65 | + "latex-workshop.latex.tools": [ |
| 66 | + { |
| 67 | + "name": "latexmk", |
| 68 | + "command": "latexmk", |
| 69 | + "args": [ |
| 70 | + "-synctex=1", |
| 71 | + "-interaction=nonstopmode", |
| 72 | + "-file-line-error", |
| 73 | + "-pdf", |
| 74 | + "-shell-escape", |
| 75 | + "-outdir=%OUTDIR%", |
| 76 | + "%DOC%" |
| 77 | + ], |
| 78 | + "env": {} |
| 79 | + }, |
| 80 | + { |
| 81 | + "name": "xelatex", |
| 82 | + "command": "xelatex", |
| 83 | + "args": [ |
| 84 | + "-synctex=1", |
| 85 | + "-interaction=nonstopmode", |
| 86 | + "-file-line-error", |
| 87 | + "-shell-escape", |
| 88 | + "%DOC%" |
| 89 | + ], |
| 90 | + "env": {} |
| 91 | + }, |
| 92 | + { |
| 93 | + "name": "pdflatex", |
| 94 | + "command": "pdflatex", |
| 95 | + "args": [ |
| 96 | + "-synctex=1", |
| 97 | + "-interaction=nonstopmode", |
| 98 | + "-file-line-error", |
| 99 | + "-shell-escape", |
| 100 | + "%DOC%" |
| 101 | + ], |
| 102 | + "env": {} |
| 103 | + }, |
| 104 | + { |
| 105 | + "name": "bibtex", |
| 106 | + "command": "bibtex", |
| 107 | + "args": [ |
| 108 | + "%DOCFILE%" |
| 109 | + ], |
| 110 | + "env": {} |
| 111 | + } |
| 112 | + ], |
| 113 | + "latex-workshop.latex.recipes": [ |
| 114 | + { |
| 115 | + "name": "pdfLaTeX", |
| 116 | + "tools": [ |
| 117 | + "pdflatex" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "name": "latexmk", |
| 122 | + "tools": [ |
| 123 | + "latexmk" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "name": "xelatex", |
| 128 | + "tools": [ |
| 129 | + "xelatex" |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "name": "pdflatex ➞ bibtex ➞ pdflatex`x2", |
| 134 | + "tools": [ |
| 135 | + "pdflatex", |
| 136 | + "bibtex", |
| 137 | + "pdflatex", |
| 138 | + "pdflatex" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "name": "xelatex ➞ bibtex ➞ xelatex`x2", |
| 143 | + "tools": [ |
| 144 | + "xelatex", |
| 145 | + "bibtex", |
| 146 | + "xelatex", |
| 147 | + "xelatex" |
| 148 | + ] |
| 149 | + } |
| 150 | + ], |
| 151 | + "latex-workshop.latex.recipe.default": "xelatex", |
| 152 | + ``` |
| 153 | + |
| 154 | + **Remark:** |
| 155 | + |
| 156 | + 1. Remember to add “,” if you want to add other contents in the json file. |
| 157 | + 2. `"-shell-escape"` flag is prepared for the use of minted package. |
| 158 | + 3. To modify the default recipe, please use [`latex-workshop.latex.recipe.default`](https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexrecipedefault) . |
| 159 | + |
| 160 | +## Usage |
| 161 | + |
| 162 | +- Now you can open a “.tex” file then build and preview it. |
| 163 | + |
| 164 | + If you want to use external pdf viewer, search for “viewer” in extension settings, then choose “external”. |
| 165 | + |
| 166 | +- **Some useful shortcut:** |
| 167 | + |
| 168 | + *option + command + B*: Build the tex file |
| 169 | + |
| 170 | + *option + command + J*: Jump from the code to corresponding PDF part |
| 171 | + |
| 172 | + *command + mouse press*: Jump from the PDF to corresponding code part |
| 173 | + |
| 174 | + |
| 175 | +## Reference Link |
| 176 | + |
| 177 | +1. https://mathjiajia.github.io/vscode-and-latex/ |
| 178 | +2. [Visual Studio Code (*vscode*) 配置 LaTeX](https://zhuanlan.zhihu.com/p/166523064) |
| 179 | + |
| 180 | +## Troubleshooting |
| 181 | + |
| 182 | +1. Manually add texlive path if needed |
| 183 | + |
| 184 | + ```bash |
| 185 | + echo 'export PATH="/usr/local/texlive/2024/bin/universal-darwin:$PATH"' >> ~/.zshrc |
| 186 | + source ~/.zshrc |
| 187 | + ``` |
| 188 | + |
| 189 | + You don’t need to manually add path in config file. |
| 190 | + |
| 191 | + **Reboot** your mac if your LaTex Workshop still not work properly. |
0 commit comments