# How to generate a tex document from the shell after installing MacTex?

I am a new MacOS user, and have downloaded and installed MacTex on my machine. How do I use it to convert .tex files to a pdf? I know in Windows I could use pdflatex and MikTex right after installation.

I want to go to my terminal and simply enter: pdflatex file.tex and get the output I expect, like I did in Windows.

When I run pdflatex file.tex when I am in the directory with file.tex in my bash shell, I get -bash: pdflatex: command not found. How do I compile latex documents on the Mac?

Any advice you have would be appreciated.

• Do you know how to open a command window and navigate to the directory that contains file.tex?
– Mico
Sep 2 '20 at 3:54
• yes I can do that @Mico Sep 2 '20 at 4:01

Let's assume that you've opened a terminal window and navigated (say, via suitable cd statements) to the directory that contains file.tex. To make pdflatex compile this document, you just need to type

pdflatex file


at the prompt.

In the following screenshot, I first ran cat file.tex to show its contents:

\documentclass{article}
\begin{document}
Hello World.
\end{document}


I then ran pdflatex file; happily, no warning or error messages were issued. Finally, I ran ls -l file.* to show that in addition to the .tex file, there are three other files in the directory: file.aux, file.log, and -- probably most importantly to you -- file.pdf.

• Incidentally, this answer assumes that you downloaded and installed MacTeX from its main repository at tug.org/mactex. If you used some other installation method -- say, homebrew -- instead, you may have to adjust the PATH and other environment variables by hand.
– Mico
Sep 2 '20 at 5:12