How can I convert a .tex file to a PDF via the command line?

Is there a package that contains a TeX to PDF converter/renderer available on Ubuntu 12.04? If not, can you recommend a tool for me to download from elsewhere that can do this that is simple to install?

151 2 2 silver badges 10 10 bronze badges asked Jul 22, 2012 at 10:57 743 1 1 gold badge 5 5 silver badges 5 5 bronze badges

Welcome Triss, I investigated this a while back and I'm not sure there is a way via the command line. I use Lyx. You might find some useful information here though latex2rtf.sourceforge.net/

Commented Jul 22, 2012 at 11:05 @StephenMyall: Lyx is not a command line utility. Commented Jul 23, 2012 at 6:40

Im aware of that and thats why I commented rather than answer your question. I wanted to let you know that I had looked for a command line utility before for this type of conversion with no luck. I hope you have better luck.

Commented Jul 23, 2012 at 6:46

5 Answers 5

At the command line, first install the texlive package if it isn't already installed:

sudo apt-get install texlive 

Then use the pdflatex utility to convert the file like this:

pdftex /path/to/myfile.tex 

The path /path/to/myfile.tex is, of course, an example path. You would put the path to your own file on your system.

Notice that although the utility is called pdflatex you execute it with the command pdftex (without the la).

There are several settings that you can read about in the help for pdflatex:

pdflatex --help 

The setting I use the most is the one to generate the pdf in a different directory:

pdflatex --output-directory=../otherdir /path/to/myfile.tex 

The pdflatex utility is also interactive, so that if you forget to supply necessary information it will prompt you to enter it before converting the file.

383 3 3 silver badges 20 20 bronze badges answered Jun 5, 2014 at 17:43 monotasker monotasker 3,675 1 1 gold badge 18 18 silver badges 16 16 bronze badges

pdftex and pdflatex don't seem to be the same thing. pdflatex supports LaTeX but pdftex doesn't (tex.stackexchange.com/a/258622)

Commented Oct 24, 2017 at 19:01

I support @bmaupin's comment. TeX and LaTeX are not the same. If you force me to answer I had to make an educated guess that LaTeX is a 'superset' of TeX. Once aware it's trivial to switch between an e.g. wrongly pdftex file.tex to pdflatex but for the uninitiated it might be confusing as you casually switch from the former to the latter in your answer.

Commented Aug 27, 2020 at 17:45 Upvoted. I added a few extras to install in my new answer here, too. Commented Jun 17, 2023 at 17:07

Big update: you may need to use pdflatex instead of pdftex . I've described the differences now in my answer.

Commented Jun 17, 2023 at 18:23

As far as I know, you won't find a single standalone binary that will do this for you. The typical utility is called pdflatex and is part of the TeX Live package. It's in the repositories, so simply opening the terminal and typing the below will install pdflatex and lots of other essential TeX stuff:

sudo apt-get install texlive 
answered Jul 22, 2012 at 11:05 141k 36 36 gold badges 311 311 silver badges 315 315 bronze badges

For people who see this QnA, do visit tex.stackexchange.com and a sample pdf question tex.stackexchange.com/questions/149649/…

Commented Dec 12, 2013 at 17:11

The difficulty with this answer is that it doesn't actually tell the asker how to use the pdflatex utility to make the conversion on the command line. Since that was the question, this doesn't provide a full answer. (Some of us may be able to just read man pages, but for command-line novices who might read this some more explanation is important.)

Commented Jun 5, 2014 at 17:46 You may also need sudo apt install texinfo . I did. Commented Oct 28, 2016 at 11:41

Install texlive and all the extras: how to convert a .tex file to a PDF (TeX to PDF, and LaTeX to PDF)

Tested on Ubuntu 22.04.2.

In addition to the main texlive program, there are some extras and extra fonts and things you might want too. So, I've gathered the commands from this tutorial (Linux Hint: How Do I Convert a .tex Latex File to PDF in Linux?) and placed them all below:

1. Install texlive

sudo apt update # (copy and paste and run this whole block of lines at once) sudo apt install -y \ texlive \ texinfo \ texlive-fonts-recommended \ texlive-fonts-extra \ texlive-latex-extra 

2. Use it: produce file.pdf from file.tex

# 1: for a plain TeX format .tex file pdftex my_TeX_file.tex # 2: for a LaTeX format .tex file pdflatex my_LaTeX_file.tex 

From man pdftex (emphasis added):

The typical use of pdfTeX is with a pregenerated formats for which PDF output has been enabled. The pdftex command uses the equivalent of the plain TeX format, and the pdflatex command uses the equivalent of the LaTeX format.

More details, and ! Undefined control sequence. errors

Notice that you may need to use pdflatex above, not pdftex . That's because pdftex is for plain TeX format, whereas pdflatex is for LaTeX format. pdftex is more limited and doesn't process LaTeX packages at all, resulting in bad results. See here: TEX Stack Exchange: "Undefined control sequence" at beginning of any simple document.

If your .tex document has any \documentclass<> or \usepackage<> calls at all, for instance, then it is LaTeX format, and you'll have to use a tool such as latex , pdflatex , xelatex , or lualatex instead of pdftex . pdflatex works very well for me.

The errors I see when I mistakenly try to process a LaTeX format document using pdftex look like this, for instance:

makani$ pdftex documentation/control/aero/aero_spec.tex This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdftex) restricted \write18 enabled. entering extended mode (./documentation/control/aero/aero_spec.tex ! Undefined control sequence. l.1 \documentclass [11pt] ? ! Undefined control sequence. l.2 \usepackage ? ! Undefined control sequence. l.3 \geometry ? ! Undefined control sequence. l.4 \usepackage ? ! Undefined control sequence. l.5 \usepackage ? 

To find the solution at the link above, I used this Google search: pdftex Undefined control sequence.

Full demo

Here's a full demo of an online LaTeX .tex file you can process. It works very well.

We will convert this LaTeX file to a PDF: https://github.com/google/makani/blob/master/documentation/control/aero/aero_spec.tex. This is from the Google "Makani" kite/tethered aircraft wind power generation project.

# download this LaTeX file wget https://raw.githubusercontent.com/google/makani/master/documentation/control/aero/aero_spec.tex # convert it to a PDF pdflatex aero_spec.tex 

Now, manually open up aero_spec.pdf in your favorite PDF viewer, such as Foxit Reader, which allows you to highlight, underline, write notes, etc, in the PDF.

Here's what the generated PDF looks like: