Create beautiful PDF files with LaTeX

Introduction: Use the LaTeX markup language to write documents.

The number of words in this article: 6084, the reading time is about 7 minutes

Use the LaTeX markup language to write documents.

The LaTeX file preparation system has an interesting history. In 1968, programmer Don Knuth wrote his first book, “The Art of Computer Programming,” in an old-fashioned way of typography. By the time he published his second edition in 1976, the publisher had turned to modern phototypesetting techniques.

Knuth wasn’t happy with the look of the new version. He approached the problem from a programmer’s point of view and decided to create his own word processing system so that his future books could be formatted in the same format and have the same look. So Don Knuth wrote the first version of TeX in 1978.

A few years later, Leslie Lamport created a set of macro definitions to make it easier for authors to write complex documents. Lamport’s macro-definition extension, LaTeX, effectively extends TeX to easily create a variety of documents. For example, many academic organizations use LaTeX to publish journals and proceedings.

Writing documents with LaTeX

The basics of LaTeX can be easily grasped by writing a few short essays. Let’s start with Opensource.com
? opensource.com
The introduction page borrows the following to create an example:


  1. $ cat about.tex

  2. \documentclass{article}

  3. \begin{document}

  4. Opensource.com is a premier, daily publication focused on

  5. open source and Linux tutorials, stories, and resources.

  6. We're a diverse and inviting group, made up of staff

  7. editors, Correspondents, contributors, and readers. We

  8. value differences in skills, talents, backgrounds, and

  9. experiences. There are a few different ways to get involved

  10. as a reader or a writer.

  11. \end{document}

Like other document formatters, LaTeX groups words together into paragraphs. This means you can add new text in the middle of paragraphs without worrying about jagged paragraphs in the final document. LaTeX will create perfectly aligned paragraphs as long as you don’t add blank lines to paragraphs. When it finds a blank line, LaTeX opens a new paragraph.

LaTeX requires some control statements that define the document. Any LaTeX document should begin with a “document class” declaration. LaTeX supports a variety of documents, including letters, books, and articles. For example, I use \documentclass{article} to set the category to “article”.

Use \begin{document} and \end{document} declarations to define the beginning and end of text. LaTeX will complain if you add text before \begin{document} . Text after \end{document} is ignored.

Use LaTeX’s latex command to process documents:


  1. $ latex about.tex

  2. This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=latex)

  3. restricted \write18 enabled.

  4. entering extended mode

  5. (./about.tex

  6. LaTeX2e <2020-10-01> patch level 4

  7. (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls

  8. Document Class: article 2020/04/10 v1.4m Standard LaTeX document class

  9. (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))

  10. (/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)

  11. No file about.aux.

  12. [1] (./about.aux) )

  13. Output written on about.dvi (1 page, 736 bytes).

  14. Transcript written on about.log.

LaTeX will output a lot of text so you can tell what it’s doing. If your document contains errors, LaTeX will complain and tell you what it can do. In most cases, you can force quit LaTeX by typing exit when prompted.

If a document is successfully generated with LaTeX, a file with a .dvi suffix will be generated. DVI stands for “Device Independent” because you can use different tools to generate other formats. For example, the dvipdf program can convert DVI files to PDF files.


LaTeX output

add list

LaTeX supports two kinds of lists: an “enumerated” list that starts with a number, and an “item-by-item” or “bullet” list. Add a short enumeration list after the second paragraph that people can participate in Opensource.com
? Opensource.com
The way:


  1. \begin{enumerate}

  2. \item Be a writer

  3. \item Be a reader

  4. \end{enumerate}

Similar to adding \begin and \end declarations to the document definition, you also need to add \begin and \end declarations before and after the list. In the list, each item starts with the \item command. When you process the document in LaTeX and convert it to PDF, you will see the list as a list of numbers:

LaTeX output

You can also nest lists within lists. This is an elegant feature if you need to add options to each entry in the list. For example, you can create
? Opensource.com
There are a few different resources for people who become authors in . Embedded lists use separate \begin and \end declarations. I’ve added blank lines to the example for convenience, but LaTeX ignores these blank lines:


  1. \begin{enumerate}

  2. \item Be a writer

  3. \begin{itemize}

  4. \item Resources for writers

  5. \item Contributor Club

  6. \item Correspondent Program

  7. \end{itemize}

  8. \item Be a reader

  9. \end{enumerate}

As a nested list, the new list is embedded in item number 1 because you added the list between the original \item declarations. You can make a nested list of items number 2 by adding a new list before the \end{enumerate} statement.

LaTeX output

Chapters and Subsections

You can break lengthy articles into chapters to make them easier to read. Section headings are added within curly braces using the \section{...} statement. For example, you could add a title at the top of your document titled “About Opensource.com
? Opensource.com
” new chapter:


  1. $ head about.tex

  2. \documentclass{article}

  3. \begin{document}

  4. \section{About Opensource.com}

  5. Opensource.com is a premier, daily publication focused on

  6. open source and Linux tutorials, stories, and resources.

  7. We're a diverse and inviting group, made up of staff

  8. editors, Correspondents, contributors, and readers. We

The article document class adds numbers to each major chapter and makes the font larger to stand out.

LaTeX output

You can use the \subsection{...} command to organize documents. Just like the \section{...} command, enter the subtitle name in curly brackets.


  1. $ head about.tex

  2. \documentclass{article}

  3. \begin{document}

  4. \section{About Opensource.com}

  5. Opensource.com is a premier, daily publication focused on

  6. open source and Linux tutorials, stories, and resources.

  7. \subsection{Welcome to the Opensource.com community}

LaTeX output

title and author

Scientific articles for publication require a title, author, and publication date. LaTeX provides a way to add this information by inserting commands, and then use a separate \maketitle command to generate the title of the article.

Use “About Us” as the title of the article, and the author is ” Opensource.com
? Opensource.com
Editors”, published on “July 10, 2022”. You must insert these after \begin{document} and before the content of the article.


  1. \title{About Us}

  2. \author{Opensource.com Editors}

  3. \date{July 10, 2022}

  4. \maketitle

LaTeX will add the title, author and date to the top of the article when you are generating the document:

LaTeX output

Emphasize

Scientific and other technical articles often highlight terms and phrases. LaTeX provides several font effects that can be used in technical documents, including emphasized text (usually in italics), bold text, and small caps.

Put the phrases “staff editors, Correspondents, contributors, and readers” in italicized text, and put the specific words “reader” and “writer” in emphasized text after the paragraph. You can also bold “skills, talents, backgrounds, and experiences”. While this is not the correct way to style it, you can use small caps to type “Linux”.


  1. $ head -20 about.tex

  2. \documentclass{article}

  3. \begin{document}

  4. \title{About Us}

  5. \author{Opensource.com Editors}

  6. \date{July 10, 2022}

  7. \maketitle

  8. \section{About Opensource.com}

  9. Opensource.com is a premier, daily publication focused on

  10. open source and \textsc{Linux} tutorials, stories, and resources.

  11. \subsection{Welcome to the Opensource.com community}

  12. We're a diverse and inviting group, made up of \textit{staff

  13. editors, Correspondents, contributors, and readers}. We

  14. value differences in \textbf{skills, talents, backgrounds, and

  15. experiences}. There are a few different ways to get involved

  16. as a \emph{reader} or a \emph{writer}.

This example shows how to apply different styles of text. When you need emphasis, use the \emph{...} command, enclosing the subject of emphasis in curly braces. To display text in italics, bold, or small caps, use variations of the \text command: \textit{...} for italics, \textbf{...} for bold, and \ textsc{...} for small caps. LaTeX supports many other ways to style text that will help you write scientific and technical articles.

LaTeX output

Using LaTeX

I just covered a few ways to write scientific and technical articles using LaTeX. You can also add footnotes in LaTeX, typesetting mathematical formulas and equations, depending on your needs. You can also learn about other ways to write scientific and technical articles with LaTeX by reading the articles in .

The text and pictures in this article are from Linux China

loading.gif

This article is reprinted from https://www.techug.com/post/create-beautiful-pdf-files-with-latexb6ae023296e52b5f2098/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment