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:
-
$ cat about.tex
-
\documentclass{article}
-
\begin{document}
-
Opensource.com is a premier, daily publication focused on
-
open source and Linux tutorials, stories, and resources.
-
We're a diverse and inviting group, made up of staff
-
editors, Correspondents, contributors, and readers. We
-
value differences in skills, talents, backgrounds, and
-
experiences. There are a few different ways to get involved
-
as a reader or a writer.
-
\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:
-
$ latex about.tex
-
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=latex)
-
restricted \write18 enabled.
-
entering extended mode
-
(./about.tex
-
LaTeX2e <2020-10-01> patch level 4
-
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
-
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
-
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
-
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
-
No file about.aux.
-
[1] (./about.aux) )
-
Output written on about.dvi (1 page, 736 bytes).
-
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:
-
\begin{enumerate}
-
\item Be a writer
-
\item Be a reader
-
\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:
-
\begin{enumerate}
-
\item Be a writer
-
\begin{itemize}
-
\item Resources for writers
-
\item Contributor Club
-
\item Correspondent Program
-
\end{itemize}
-
\item Be a reader
-
\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:
-
$ head about.tex
-
\documentclass{article}
-
\begin{document}
-
\section{About Opensource.com}
-
Opensource.com is a premier, daily publication focused on
-
open source and Linux tutorials, stories, and resources.
-
We're a diverse and inviting group, made up of staff
-
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.
-
$ head about.tex
-
\documentclass{article}
-
\begin{document}
-
\section{About Opensource.com}
-
Opensource.com is a premier, daily publication focused on
-
open source and Linux tutorials, stories, and resources.
-
\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.
-
\title{About Us}
-
\author{Opensource.com Editors}
-
\date{July 10, 2022}
-
\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”.
-
$ head -20 about.tex
-
\documentclass{article}
-
\begin{document}
-
\title{About Us}
-
\author{Opensource.com Editors}
-
\date{July 10, 2022}
-
\maketitle
-
\section{About Opensource.com}
-
Opensource.com is a premier, daily publication focused on
-
open source and \textsc{Linux} tutorials, stories, and resources.
-
\subsection{Welcome to the Opensource.com community}
-
We're a diverse and inviting group, made up of \textit{staff
-
editors, Correspondents, contributors, and readers}. We
-
value differences in \textbf{skills, talents, backgrounds, and
-
experiences}. There are a few different ways to get involved
-
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
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.