<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>writing on Daan Geijs</title>
    <link>https://www.daangeijs.nl/tags/writing/</link>
    <description>Recent content in writing on Daan Geijs</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 10 Sep 2024 12:48:00 +0100</lastBuildDate><atom:link href="https://www.daangeijs.nl/tags/writing/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>LaTeX in Visual Studio Code (VSCode) on macOS</title>
      <link>https://www.daangeijs.nl/posts/latex-vscode/</link>
      <pubDate>Tue, 10 Sep 2024 12:48:00 +0100</pubDate>
      
      <guid>https://www.daangeijs.nl/posts/latex-vscode/</guid>
      <description>When writing my thesis, I found Overleaf to be a bit too minimalistic for managing a large project such as a PhD Thesis. Installing LaTeX in Visual Studio Code (VSCode) really helped me to work in a modern, customizable text editor. In this post, we&amp;rsquo;ll go through the process of installing LaTeX on macOS using Homebrew, configuring VSCode with LaTeX Workshop, and syncing with Overleaf for collaborative writing and reviewing. Please note that the LaTeX installation can take a while, since updating and downloading packages can be time-consuming.</description>
      <content:encoded><![CDATA[<p>When writing my thesis, I found Overleaf to be a bit too minimalistic for managing a large project such as a PhD Thesis. Installing LaTeX in Visual Studio Code (VSCode) really helped me to work in a modern, customizable text editor. In this post, we&rsquo;ll go through the process of installing LaTeX on macOS using Homebrew, configuring VSCode with LaTeX Workshop, and syncing with Overleaf for collaborative writing and reviewing. Please note that the LaTeX installation can take a while, since updating and downloading packages can be time-consuming.</p>
<h2 id="step-1-install-homebrew-if-not-already-installed">Step 1: Install Homebrew (if not already installed)</h2>
<p>First, if you don&rsquo;t have Homebrew installed, open your terminal and enter the following command:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">/bin/bash -c <span class="s2">&#34;</span><span class="k">$(</span>curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh<span class="k">)</span><span class="s2">&#34;</span>
</span></span></code></pre></div><p>This will install Homebrew, a package manager for macOS, making it easy to install LaTeX and other software.</p>
<h2 id="step-2-install-latex-via-homebrew">Step 2: Install LaTeX via Homebrew</h2>
<p>Once Homebrew is installed, you can install LaTeX by running the following command in your terminal:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">brew install --cask mactex-no-gui
</span></span></code></pre></div><p>This command installs the <strong>MacTeX-no-GUI</strong> version, which includes the full LaTeX environment without any graphical applications (such as TeXShop). The download and installation can take a while to start, so be patient—it may seem like nothing is happening initially, but it will eventually begin downloading.</p>
<p>After installation, update LaTeX packages to ensure you have the latest versions. You will need to restart your terminal before running the following commands:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo tlmgr update --self
</span></span><span class="line"><span class="cl">sudo tlmgr update --all
</span></span></code></pre></div><p>This ensures your LaTeX environment is fully up to date. If you encounter any issues during the installation or update process, check the terminal output for error messages and try to resolve them accordingly. For me, it helped to run <code>eval &quot;$(/usr/libexec/path_helper)&quot;</code> and restart my terminal.</p>
<h2 id="step-3-install-vscode">Step 3: Install VSCode</h2>
<p>If you haven&rsquo;t installed Visual Studio Code yet, you can download and install it from the <a href="https://code.visualstudio.com/">official VSCode website</a>.</p>
<p>Once installed, open VSCode and prepare to add the necessary extensions for LaTeX.</p>
<h2 id="step-4-install-the-latex-workshop-extension">Step 4: Install the LaTeX Workshop Extension</h2>
<p>VSCode doesn&rsquo;t natively support LaTeX, so we need to install an extension called <strong>LaTeX Workshop</strong>. This extension provides LaTeX syntax highlighting, compilation, previews, and other useful features.</p>
<p>To install it:</p>
<ol>
<li>Open <strong>VSCode</strong>.</li>
<li>Go to the <strong>Extensions</strong> view by clicking on the Extensions icon on the sidebar or pressing <code>Cmd</code> + <code>Shift</code> + <code>X</code>.</li>
<li>Search for <strong>LaTeX Workshop</strong>.</li>
<li>Click <strong>Install</strong>.</li>
</ol>
<p>Once installed, LaTeX Workshop will automatically manage compiling your LaTeX files and displaying previews.</p>
<h3 id="configuring-latex-workshop">Configuring LaTeX Workshop:</h3>
<p>You can customize LaTeX Workshop by going to the settings (open <code>Cmd</code> + <code>,</code>) and searching for <strong>LaTeX Workshop</strong>. You’ll find options for how you want your documents to compile, preview behavior, and more. For now, you can leave the default settings as they are.</p>
<h2 id="step-5-enable-word-wrap-in-vscode">Step 5: Enable Word Wrap in VSCode</h2>
<p>LaTeX files can often contain long lines of text, and horizontal scrolling is inconvenient. To make your experience smoother, enable <strong>word wrap</strong> in VSCode so that long lines break automatically within the window.</p>
<h3 id="to-enable-word-wrap-globally">To enable word wrap globally:</h3>
<ol>
<li>Open VSCode settings (<code>Cmd</code> + <code>,</code>).</li>
<li>Search for <strong>word wrap</strong>.</li>
<li>Set <strong>Editor: Word Wrap</strong> to <code>on</code>.</li>
</ol>
<p>Alternatively, you can set word wrap for individual sessions by using the keyboard shortcut <code>Alt</code> + <code>Z</code>.</p>
<p>Another way to enable word wrap is by using the <strong>Command Palette</strong>:</p>
<ol>
<li>Open the Command Palette by pressing <code>Cmd</code> + <code>Shift</code> + <code>P</code>.</li>
<li>Type <strong>Word Wrap</strong> and select <strong>View: Toggle Word Wrap</strong>.</li>
</ol>
<p>This ensures that lines automatically break without requiring horizontal scrolling.</p>
<h2 id="step-6-syncing-vscode-with-overleaf-for-collaboration-and-reviews">Step 6: Syncing VSCode with Overleaf for Collaboration and Reviews</h2>
<p>While VSCode offers a great environment for writing and compiling LaTeX documents, Overleaf is fantastic for collaboration, reviewing, and sharing with others. You can leverage both platforms by syncing your project between Overleaf and VSCode.</p>
<h3 id="setting-up-overleaf-for-git-synchronization">Setting up Overleaf for Git Synchronization</h3>
<ol>
<li>
<p><strong>Create or Open a Project on Overleaf</strong>:
Start by either creating a new project on Overleaf or selecting an existing project that you want to sync with.</p>
</li>
<li>
<p><strong>Enable Git on Overleaf</strong>:
Overleaf allows you to connect your project to a private Git repository. To do this:</p>
<ul>
<li>Open your Overleaf project.</li>
<li>Go to the <strong>Menu</strong> (top left).</li>
<li>Scroll down to <strong>GitHub</strong>.</li>
<li>Follow the instructions to allow Overleaf to create a private Git repository for your project.</li>
</ul>
</li>
<li>
<p><strong>Clone the Repository in VSCode</strong>:
Once Overleaf creates the repository, you can clone it to your local machine:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git clone &lt;your-overleaf-git-url&gt;
</span></span></code></pre></div><p>After cloning, you can open the project in VSCode.</p>
</li>
<li>
<p><strong>Add a .gitignore file</strong>:
Add a <code>.gitignore</code> file to your project to exclude unnecessary LaTeX-generated files (like <code>.aux</code>, <code>.log</code>, etc.). A nice <code>.gitignore</code> template for LaTeX projects can be found <a href="https://github.com/github/gitignore/blob/main/TeX.gitignore">here</a>.</p>
</li>
<li>
<p><strong>Working in VSCode</strong>:
You can now work on your LaTeX document in VSCode, take advantage of the full LaTeX Workshop experience, and perform heavy-duty tasks like editing large files or compiling complex documents.</p>
</li>
<li>
<p><strong>Syncing with Overleaf</strong>:
If you want to review or share a version, simply push your changes back to the Overleaf repository:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git push origin main
</span></span></code></pre></div><p>Overleaf will not automatically update with the latest version, for this you will have to manually pull the changes from GitHub in Overleaf.</p>
<p>To do this:</p>
<ul>
<li>Open your Overleaf project.</li>
<li>Go to the <strong>Menu</strong> (top left).</li>
<li>Scroll down to <strong>GitHub</strong>.</li>
<li>Press the button to <strong>Pull changes from GitHub</strong>.</li>
</ul>
<p>Make sure to resolve any conflicts that may arise during the pull process. The best way is to make sure everything is pushed to GitHub before pulling in Overleaf.</p>
</li>
<li>
<p><strong>Collaborate and Review on Overleaf</strong>:
Once your collaborators or reviewers have made changes on Overleaf, you can pull those changes back into your local repository:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git pull origin main
</span></span></code></pre></div><p>This way, you can synchronize changes between Overleaf and VSCode seamlessly, using Overleaf for easy collaboration and VSCode for more ease of work.</p>
</li>
</ol>
<h2 id="step-7-compile-and-preview">Step 7: Compile and Preview</h2>
<p>Here is a quick preview of how it looks when you have set everything up. You can see the LaTeX code on the left and the preview on the right. By default, auto-compilation is enabled, which means the preview will update automatically when you save the file (or have autosave enabled). I recommend enabling autosave on all your projects. In this case, I switched my theme to a light theme because the dark-themed editor created too much contrast compared to the preview.</p>
<p><img loading="lazy" src="/posts/latex-vscode/image.png" type="" alt="alt text"  /></p>
<p>With LaTeX installed via Homebrew and configured in VSCode using the LaTeX Workshop extension, you now have a powerful setup for writing LaTeX documents. Additionally, by syncing your project with Overleaf, you can easily collaborate with others, review changes, and keep everything in sync using Git. The installation and setup may take some time, especially when using the <code>brew</code> command, but once it&rsquo;s complete, you’ll have a smooth and customizable LaTeX environment.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
