How to write LaTeX documents with Visual Studio Code on Mac

How to write LaTeX documents with Visual Studio Code on Mac

8 min read

I recall being in my third year of engineering school when my favorite teacher recommended LaTeX for our coursework. At that time, none of us had heard about it, and as our research began, many students quickly frowned upon the idea of writing code to create a PDF file. The memory of how everyone suddenly became a staunch supporter of Word, simply because they were reluctant to try something new, is still vivid in my mind.

Of course, being the nerd I was, and with the suggestion coming from my favorite teacher whom I greatly admired, I felt compelled to give LaTeX a try! I mean, having explored the world of coding since my teenage years, the idea of saying I created a PDF using code was kind of fascinating to me.

Welcome to the nerd zone my friend gif

The Goods

Soon enough, everything changed for the better. The more I worked with LaTeX, the more I appreciated its precision and flexibility. Unlike the usual word processors, LaTeX offered me complete control over the document layout and formatting. The way it handled complex mathematical equations and references was nothing short of a revelation. It was like discovering a secret language that transformed my academic writing into a work of art.

The Bads

Writing LaTeX on Windows used to be a challenging endeavor. The main issue was the absence of an integrated, user-friendly environment. Available LaTeX editors were often either too simplistic, lacking crucial functionality, or overly complex with intimidating learning curves. The integration with Windows systems was not seamless, typically necessitating extra steps for setting up compilers and viewing PDF outputs. The lack of real-time previews was a significant hurdle, forcing users to compile repeatedly to check for errors or formatting issues.

After many years, now deeply immersed in my Cybersecurity MSc, I've reached the pivotal moment of writing my thesis, and my preference for using LaTeX hasn't waned. As a Mac user and a seasoned coder, my approach to problem-solving has evolved, always seeking more efficient and effective methods. This quest for optimization has led me to rediscover LaTeX in a new light. With my accumulated experience and a different computing environment, it was time to find a better way to harness the power of LaTeX. And here we are, at the cusp of a new journey! Let's embark on setting up LaTeX in Visual Studio Code (VSCode), merging the sophistication of LaTeX with the streamlined efficiency of one of the most versatile code editors available today.

โผปDownload and Install MacTex

This is a very straightforward procedure, you just download and install the MacTeX.pkg from here, this might take some time as it is a big one...

patience gif

Once it is downloaded, just fire up the installation and follow the instructions, you don't have to customize anything.

โผปInstall and Configure LateX Workshop in VsCode

Here you might want to put on some gloves cause it's time to get your hands dirty!

Open up your VsCode ( I assume you have it installed already ) and press โŒ˜ + โ‡ง + X. Now you have your extensions opened up. Search for Latex Workshop, the one we want is from James Yu.

Configure Latex Workspace

Press โŒ˜ + โ‡ง + P and type workspace and choose Preferences: open workspace settings (JSON) or if you don't work with workspaces go to user settings. I like working with workspaces cause I keep extensions from getting entangled with each other. Now copy and paste the following snippet into your JSON file (inside the brackets {}).

"latex-workshop.latex.tools": [
	{
		"name": "latexmk",
		"command": "latexmk",
		"args": [
			"-synctex=1",
			"-interaction=nonstopmode",
			"-file-line-error",
			"-pdf",
			"-outdir=%OUTDIR%",
			"%DOC%"
		],
		"env": {}
	},
	{
		"name": "xelatex",
		"command": "xelatex",
		"args": [
			"-synctex=1",
			"-interaction=nonstopmode",
			"-file-line-error",
			"%DOC%"
		],
		"env": {}
	},
	{
		"name": "pdflatex",
		"command": "pdflatex",
		"args": [
			"-synctex=1",
			"-interaction=nonstopmode",
			"-file-line-error",
			"%DOC%"
		],
		"env": {}
	},
	{
		"name": "bibtex",
		"command": "bibtex",
		"args": [
			"%DOCFILE%"
		],
		"env": {}
	}
],
"latex-workshop.latex.recipes": [
	{
		"name": "pdfLaTeX",
		"tools": [
			"pdflatex"
		]
	},
	{
		"name": "latexmk ๐Ÿ”ƒ",
		"tools": [
			"latexmk"
		]
	},
	{
		"name": "xelatex",
		"tools": [
			"xelatex"
		]
	},
	{
		"name": "pdflatex โžž bibtex โžž pdflatex`ร—2",
		"tools": [
			"pdflatex",
			"bibtex",
			"pdflatex",
			"pdflatex"
		]
	},
	{
		"name": "xelatex โžž bibtex โžž xelatex`ร—2",
		"tools": [
			"xelatex",
			"bibtex",
			"xelatex",
			"xelatex"
		]
	}
]

Install Latex Helper Extensions

  1. LaTeX by Mathematic Inc: Latex language support for Visual Studio Code
  2. LaTeX Snippets: Useful Snippets for Latex
  3. Github Copilot: AI Pair programmer. Very helpful extension because it suggests new lines of code, like list items, it completes figures, mathematical equations, and many more.

Add Latex to your ZSH Path

If you followed my instructions to the letter you should have this folder /usr/local/texlive/2023/bin/universal-darwin you can just:

    ls /usr/local/texlive/2023/bin/universal-darwin

You should see a list of LaTeX-related files. If so, you're ready to add LaTeX to your ZSH path. Edit your .zshrc file by opening it in a text editor (here, we use my beloved nano):

    nano ~/.zshrc
    # include this line 
    export PATH="/usr/local/texlive/2023/bin/universal-darwin:$PATH"

now finish up by running source ~/.zshrc. And you are ready to go! Now, LaTeX commands are available system-wide, streamlining your workflow and making LaTeX usage in any project much more convenient.

This step is very crucial because otherwise, your VsCode might not be able to find the files it needs to compile the latex project.

Create Your First LaTex Project with VsCode

Create a new folder that will include all your LaTeX projects, I named mine... ๐Ÿฅ๐Ÿฅ๐Ÿฅ Latex. I am a simple man. Then inside the folder create a new folder named Test. Now load the Test folder to your VsCode workspace or whatever and create a new file named text.tex. Here is a starting snippet:

\documentclass{article}

\begin{document}
    This is a \TeX file made by \LaTeX.
    \begin{itemize}
        \item I kinda 
        \item Like creating
        \item PDFs like that
    \end{itemize}

    % Add first newtons law (sum of forces = 0)
    \begin{equation}
        \sum F = 0
    \end{equation}

    % Github Copilot wrote the above ;) 

\end{document}

And the final result! ๐Ÿช„

my image saved on sudorealm.com

Tadaaaa! Working like a charm, and every time I save the .tex file the pdf gets generated immediately! How cool is that? You can look in the mirror and feel like an actual academic now!

It's leviOsa not leviosA gif

โผป Conclusion

Why is it cool to have this installation combination in your system?

  1. Efficiency and Productivity: VSCode enhances LaTeX's typesetting power, offering a streamlined workflow. Its integrated environment allows you to write, compile, and preview documents in one place, boosting productivity and reducing the hassle of switching apps.
  2. Advanced Editing Features: With features like syntax highlighting, auto-completion, and error detection, VSCode elevates the LaTeX editing experience. These tools simplify writing and debugging, making it more efficient and less prone to errors.
  3. Customization and Flexibility: VSCode's extensibility, with add-ons like GitHub Copilot or Grammarly, enriches LaTeX writing. It allows for a customized setup, perfect for handling complex documents in various academic and technical domains.

Keep an eye out for more posts centered around LaTeX, as I'm currently in the thick of writing my thesis. I'm confident that this journey with the incredible LaTeX and VSCode combination will uncover many exciting insights and tricks, which I can't wait to share with you.

๐Ÿš€ Spread the Love & Support the Realm

Hey there, fellow Realmer! If this guide illuminated a new path in your coder/hacker journey, your support would mean a lot. Every bit of magic helps.

Spread the Love

๐Ÿ‘‘ Crown & Share: If you found value in this post, please give it a crown and share it with your fellow coder/hacker enthusiasts. Spreading knowledge is what Sudorealm is all about! Fun fact the Author with the most crowns inside a realm will be crowned as the Realm King! ๐Ÿคด

๐Ÿ†‡ X Shoutout: Feeling extra grateful or have some cool feedback? Drop me a shoutout on Twitter โ€“ I'd love to hear from you! d3adR1nger on X

๐Ÿ’ฌ Join our Discord Server: Join the Sudorealm Discord Server connect with fellow enthusiasts and chat about everything that fascinates you! From new blog post suggestions to seeking support on tricky tutorials. Come, share your ideas, and let's grow together! ๐Ÿš€๐ŸŒ

Support the Realm

๐Ÿ› Affiliate Treasures Below: Dive into the depths below the post to uncover some affiliate products I've curated just for you. It's a great way to support the realm and discover some nerdy treasures.

โ˜•๏ธ Coffee Driven Development: Love what you're reading? Fuel my passion for coding with a delicious cup of coffee! Every sip powers up another line of code and helps bring more exciting content your way. Support my caffeine-fueled coding adventures and let's brew up something amazing together! โ˜•๐Ÿ‘จโ€๐Ÿ’ป Join the journey and BuyMeACoffee

d3ad R1nger buymeacoffee

Thanks for being a part of our realm. Every bit of support propels our community to new horizons. Until next time, keep exploring!

Affiliate Links

Check out what d3ad R1nger suggests for How to write LaTeX documents with Visual Studio Code on Mac!

  • Zombie Rubber Ducky affiliate image
    Nerdom

    Zombie Rubber Ducky

    You can talk to it forever... It will never die... cause it is already dead!

  • NXET Headphone Stand affiliate image
    Office

    NXET Headphone Stand

    Universal Aluminum Holder Showing Display Hanger

  • GUNNAR - Premium Gaming and Computer Glasses affiliate image
    Coding

    GUNNAR - Premium Gaming and Computer Glasses

    Blue light blocking computer and gaming glasses

Related Posts

Thirsty for more? Check out Sudorealm-related posts!

Ready to Forge an Alliance
๐Ÿค

Join our alliance and play a pivotal role in the evolution of our digital realm! By aligning with our pricing model, you're not just accessing premium features; you're becoming an integral part of our journey. As an ally, your support propels us forward, ensuring we continue to innovate and thrive.

Lifetime membership

As valued allies, exclusive content awaits you ๐Ÿ‘€. Unlock a suite of premium features and gain early access to ally-only enhancements in our realm. With our month-by-month commitment, you're always privy to our most coveted updates!

What's included

  • Premium Content Access
  • Ally resources + Unique Ally Badge
  • Access to Affiliate store front ๐Ÿค‘ (๐Ÿ”ฎ)
  • More to come...

It's like buying a pint ๐Ÿบ. But less!

โ‚ฌ1.99 EUR

Forge Alliance

Invoices and receipts available for easy company reimbursement

Subscribe to our newsletter.

๐Ÿ‘‹ Hey there, Realmer! Fancy getting a byte of nerdy knowledge straight to your inbox? Subscribe to our Sudorealm newsletter and don't miss a single trick from our growing community of curious minds! Ready to level up your knowledge game? Join us in the Realm today!

Be one of the privileged few
Think of it as your VIP pass into the Realm where you'll get first dibs on new features, insider updates, and more.
No spam
And, worry not, we promise not to spam โ€“ just top-tier, brain-tickling content.