Installing Latex and Compiling a Latex Docuent in Linux
Posted on In QALatex is a popular document preparation system that is widely used for creating scientific and technical documents. Compiling Latex documents on Linux is a straightforward process that requires only a few Latex packages and a set of commands. By following the steps outlined in this post, you can easily compile Latex documents on your Linux system and customize the compilation process to suit your specific needs.
Table of Contents
Installing Latex Packages
In Linux, the packages needed for compiling Latex documents can be easily installed by running the following command as root:
# yum install texlive* dvipdfmx
or
$ apt-get install texlive-full
This command installs a comprehensive set of Latex packages and the dvipdfmx tool that is required for converting the DVI output of Latex to PDF format.
Compiling a Latex Document
Once you have installed the required packages, you can compile a Latex document by executing the following commands in the terminal:
$ latex doc
$ bibtex doc
$ latex doc
$ latex doc
$ dvips doc.dvi
$ ps2pdf doc.ps
In the above example, “doc” is the name of the Latex document that you want to compile. The latex command generates a DVI file from the Latex source code, while bibtex is used to generate a bibliography file if you are using any references. After running latex again, the document is processed once more to get the correct cross-references and page numbers. Finally, dvips generates a PostScript file, which is then converted to PDF format using ps2pdf.
Once the compilation process is complete, you should be able to find the generated PDF file in the same directory as the Latex source code.
Using a Makefile for Automatic Compilation
If you frequently compile Latex documents, you can simplify the process by using a Makefile. A Makefile is a script that automates the compilation process by specifying the dependencies between the different files.
A simple Makefile for automatically compiling a Latex document can be found from this post:
filename=MAIN_LATEX_FILE_NAME_WITHOUT_.tex
pdf: ps
ps2pdf ${filename}.ps
pdf-print: ps
ps2pdf -dColorConversionStrategy=/LeaveColorUnchanged -dPDFSETTINGS=/printer ${filename}.ps
text: html
html2text -width 100 -style pretty ${filename}/${filename}.html | sed -n '/./,$$p' | head -n-2 >${filename}.txt
html:
@#latex2html -split +0 -info "" -no_navigation ${filename}
htlatex ${filename}
ps: dvi
dvips -t letter ${filename}.dvi
dvi:
latex ${filename}
bibtex ${filename}||true
latex ${filename}
latex ${filename}
read:
evince ${filename}.pdf &
aread:
acroread ${filename}.pdf
clean:
rm -f ${filename}.{ps,pdf,log,aux,out,dvi,bbl,blg}
The Makefile specifies the dependencies between the Latex source code, the bibliography file, and the generated PDF file. By running the make command in the terminal, you can automatically compile the Latex document without having to execute the individual commands manually.
Customizing ps2pdf Options
By default, the ps2pdf command used in the compilation process generates a PDF file with default options. However, you can customize the options used by ps2pdf by specifying additional arguments.
For example, to generate a PDF file with higher-quality images, you can use the following command:
$ ps2pdf -dPDFSETTINGS=/prepress doc.ps
This command generates a PDF file with higher resolution images and other settings suitable for prepross use.