|
| 1 | +# LaTeX in Gitpod |
| 2 | + |
| 3 | +This tutorial will demonstrate how to configure Gitpod to work with [LaTeX](https://www.latex-project.org/) files. You can find a complete [example repository](https://github.com/ptrottier/latex) at the end. |
| 4 | + |
| 5 | +## Installing LaTeX |
| 6 | + |
| 7 | +First, you will probably want to install LaTeX in Gitpod. To do this, add a new file to your repository called [.gitpod.Dockerfile](https://www.gitpod.io/docs/config-docker/), and add the following content to it: |
| 8 | + |
| 9 | +```Dockerfile |
| 10 | +FROM gitpod/workspace-full |
| 11 | + |
| 12 | +# Install LaTeX |
| 13 | +RUN sudo apt-get -q update && \ |
| 14 | + sudo apt-get install -yq texlive-full && \ |
| 15 | + sudo rm -rf /var/lib/apt/lists/* |
| 16 | +``` |
| 17 | + |
| 18 | +Next, create a file called [.gitpod.yml](https://www.gitpod.io/docs/config-gitpod-file/) and add the following to it: |
| 19 | + |
| 20 | +```YAML |
| 21 | +image: |
| 22 | + file: .gitpod.Dockerfile |
| 23 | +``` |
| 24 | +
|
| 25 | +Now commit both files into source control, and push them to your GitHub or GitLab repository. |
| 26 | +
|
| 27 | +This will be your base configuration for LaTeX in Gitpod — from now on, every time you create a new Gitpod workspace for your repository, it will be configured as specified in your `.gitpod.yml` and `.gitpod.Dockerfile`. |
| 28 | + |
| 29 | +## Automatically compiling LaTeX files on save |
| 30 | + |
| 31 | +One way to achieve this is to install `inotify-tools` by modifying your earlier `.gitpod.Dockerfile` like so: |
| 32 | + |
| 33 | +```Dockerfile |
| 34 | +FROM gitpod/workspace-full |
| 35 | +
|
| 36 | +# Install LaTeX |
| 37 | +RUN sudo apt-get -q update && \ |
| 38 | + sudo apt-get install -yq texlive-full inotify-tools && \ |
| 39 | + sudo rm -rf /var/lib/apt/lists/* |
| 40 | +``` |
| 41 | + |
| 42 | +Next, modify your `.gitpod.yml` like so: |
| 43 | + |
| 44 | +```YAML |
| 45 | +image: |
| 46 | + file: .gitpod.Dockerfile |
| 47 | +
|
| 48 | +tasks: |
| 49 | + - name: LaTeX auto-rebuild |
| 50 | + command: > |
| 51 | + while find . -name '*.tex' | xargs inotifywait -qqre modify .; do \ |
| 52 | + latexmk -pdf ; \ |
| 53 | + done |
| 54 | + - name: Terminal |
| 55 | +``` |
| 56 | + |
| 57 | +This will start a watcher process that automatically recompiles your `*.tex` files when they are changed. Note: The watcher process will start in a separate Terminal on every workspace start. |
| 58 | + |
| 59 | +## VSCode Extensions |
| 60 | + |
| 61 | +### TexLab |
| 62 | + |
| 63 | +This extension provides rich editing support for the LaTeX typesetting system powered by the [TexLab](https://github.com/latex-lsp/texlab-vscode) language server. |
| 64 | + |
| 65 | +To install it in Gitpod, simply download the corresponding `*.vsix` file [Open VSX](https://open-vsx.org/), and then drag-and-drop it into Gitpod's Extensions view (which can be found in the left vertical menu bar). |
| 66 | + |
| 67 | +This will automatically append something like this to your `.gitpod.yml` file: |
| 68 | + |
| 69 | +```yml |
| 70 | +vscode: |
| 71 | + extensions: |
| 72 | + - [email protected]:/Vq+k9Ug/81LYWajjTgMpA== |
| 73 | +``` |
| 74 | + |
| 75 | +(Note: You can also append these lines yourself if you don't want to download & re-upload the `*.vsix` file.) |
| 76 | + |
| 77 | +### LaTeX Workshop |
| 78 | + |
| 79 | +Another great LaTeX extension is [LaTeX Workshop](https://github.com/James-Yu/LaTeX-Workshop): |
| 80 | + |
| 81 | +> Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more. |
| 82 | + |
| 83 | +It is also available [on Open VSX](https://open-vsx.org/extension/James-Yu/latex-workshop). |
| 84 | + |
| 85 | +### LaTeX Snippets |
| 86 | + |
| 87 | +There is also [LaTeX Snippets](https://github.com/JeffersonQin/VSCode-LaTeX-Snippets): |
| 88 | + |
| 89 | +> This extension includes a variety of snippets for LaTeX including making environments and plotting images for functions, etc. |
| 90 | + |
| 91 | +## Try it! |
| 92 | + |
| 93 | +To see a complete minimal example repository with a Gitpod configuration for LaTeX, including most of the tools we've covered, see [ptrottier/latex](https://github.com/ptrottier/latex). You can try it in your browser: |
| 94 | + |
| 95 | +[](https://gitpod.io/#https://github.com/ptrottier/latex) |
0 commit comments