How To Build a .tex File to .pdf on Linux

Most of the guides I came across were just wildly all over the place, so I figured a short and simple guide that gets right to the point would be useful. Here’s how to set up Fedora 15 to build (compile might be another word) a .tex file into a .pdf file from the command line. It can be applied to other Linux distributions as well. There are GUIs to help with this, but it’s best to start with the basics. So, fire up a terminal and let’s get started.

Step 1: Install the TexLive Package

The first thing we need to do is install the texlive package.

su -c 'yum install -y texlive'

Depending on your distribution, you may also need to install the texlive-latex-extras package.

Step 2: Prepare a .tex Document

Next, we’ll create a “hello world” type .tex file. Fire up your favorite text editor and copy/paste the following (I enjoy using vim since I can stay in the command line while building the LaTeX file). When you’re finished, save the file (I’ve saved it as “hello.tex”).





Step 3: Build the .tex Document Into a PDF File

Finally, we’ll build (compile) the .tex source into a pretty PDF document using the command below:

pdflatex hello.tex

You’ll see something similar to this:

[[email protected] hello_world]$ pdflatex hello.tex
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 %&-line parsing enabled.
entering extended mode
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, basque, bulgarian, coptic, welsh, czech, slovak, german, ng
erman, danish, esperanto, spanish, catalan, galician, estonian, farsi, finnish,
 french, greek, monogreek, ancientgreek, croatian, hungarian, interlingua, ibyc
us, indonesian, icelandic, italian, latin, mongolian, dutch, norsk, polish, por
tuguese, pinyin, romanian, russian, slovenian, uppersorbian, serbian, swedish,
turkish, ukenglish, ukrainian, loaded.
Document Class: book 2005/09/16 v1.4f Standard LaTeX document class
No file hello.aux.
Chapter 1.
[1{/usr/share/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] (./hello.aux) )</u
Output written on hello.pdf (2 pages, 22507 bytes).
Transcript written on hello.log.
[[email protected] hello_world]$

Notice the text “Output written on hello.pdf (2 pages, 22507 bytes).”. That means it worked.

Step 4: View the New PDF File

Now, all you need to do is view the generated PDF document. Run the following command:

evince hello.pdf

Note, if you’re like me, you constantly flip between the source and the pdf. If that’s the case, evince will automatically update the pdf every time you re-build using pdflatex. Simply add “&” on the end of the command above:

evince hello.pdf &

This is what you should be seeing when completed:

Alternative: Rubber

I’d like to make a special note about the ‘rubber’ utility. It can take a lot of the guess work out of building LaTeX files and I strongly recommend using it over pdftex or pdflatex as mentioned above. You can install and run the ‘rubber’ utility with the following commands:

su -c 'yum install -y rubber'
rubber --pdf hello.tex


I hope this helps you get started moving quickly in the right direction. Comments and feedback are welcome.

A few difficulties I had when doing this for the first time were:

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 1 Comment So Far

  • Joseph
    May 18th, 2015 at 3:13 pm

    This is a great tutorial, Derek! It helped me a lot! Thank you for posting it.

Share your thoughts, leave a comment!