Write your first latex text

Build your first latex text. This article is applicable to Xiaobai who has installed latex but doesn't know where to start. The code is very simple and helpful to understand tex basic format.

The original is the latex English tutorial written by Jim Hefferon to Xiaobai, which is translated from https://ctan.org/pkg/first-latex-doc

Step 1: get the software

LATEX is the way we use the TEX program suite. Therefore, if you do not already have the suite, you must download it. If your computer system is Windows, Download MiKTEX. If you have Unix like systems such as GNU/Linux, Download TEX Live. For Macintosh, get MacTEX, a live version of TEX with some Mac specific plug-ins.

Step 2: use the editor

We don't use a word processor to write LATEX. Word processor combines many tasks that must be done to generate documents, such as entering and moving text, formatting it into paragraphs, generating PDF files and so on. In the TEX based system, these works are completed separately.

Instead, we use an editor to write LATEX, a program designed to move text in computer files. There are many editors, including some specially used for writing LATEX, but our document below is very small, so any editor can be used. Just a few names: on Windows, you can use Notepad, while on Unix like systems or Mac, you can use Emacs.

Step 3: write the first document

With the editor selected, you can write the first document. Create a new directory called latex first (your system may use the term "folder"). Open a terminal window and in that window, switch to that directory (you may use commandcd latex first). Next, launch your editor. Open the new file latex first in the latex first directory tex. Enter the following text and write it line by line (there is no space in the left margin).

 1 \documentclass{article}
 2 \usepackage{geometry}
 3 \usepackage{fancyhdr}
 4 \usepackage{amsmath ,amsthm ,amssymb}
 5 \usepackage{graphicx}
 6 \usepackage{hyperref}
 7 
 8 \begin{document}
 9 Hello  world!
10 \end{document}

Save the file. Return to your terminal window and enter this command: pdflatex latex first

If this works, you should see about 40 lines of text, similar to the following:

This is pdfTeXk , Version 3.1415926 -1.40.9 (Web2C 7.5.7)%&-line parsing enabled.entering extended mode .......Output written on latex -first.pdf (1 page , 6195 bytes ).Transcript written on latex -first.log.

If there are errors, check that you have entered these lines accurately. Some seemingly small typing changes can make a big difference to the results, including making the document inoperable. To make sure there are no typing differences, you can get a known good LATEX first Tex copy; Refer to the source [4] of this document. If your run ends with a question mark, you can Enter "x" and press "Enter" to exit. LATEX error messages can be difficult to understand. If you know an experienced person, it's certainly good. If not, I'm lucky to put the error message into the search engine.

Step 4: write a second document

The first document is short, so there are fewer errors. But we have seen some basic knowledge. The file you typed is a mixture of text and commands. LATEX commands, such as \ begin{document}, start with a backslash, and sometimes the parameters are contained in braces (or, as we'll see below, sometimes square brackets).

The document we make starts with the margins and fonts specified in the classarticle. We have made minor changes to the behavior by introducing some packages (such as graphicx), which will allow us to include graphics files.

Next, we will make a longer and more complex document. Start the same way: create a new directory called latex second, open a terminal window, and then switch to the new directory. Then go back to your editor window and open a new file latex second in the latex second directory tex.

 1 \documentclass{article}
 2 \usepackage{geometry}
 3 \usepackage{fancyhdr}
 4 \usepackage{amsmath ,amsthm ,amssymb}
 5 \usepackage{graphicx}
 6 \usepackage{hyperref}
 7 \usepackage{lipsum}
 8 
 9 \begin{document}
10 This is some  preamble  text  that  you  enter  yourself.
11 
12 Below is a command  that  will  automatically  generate  seven  paragraphsof text  that is  commonly  used  for  examples  in this  field.
13 
14 \lipsum [1-7]
15 \end{document}

If you've used a word processor, you'll notice the difference between this tool and LATEX. The word processor moves the text as you type. Using LATEX, you can describe what you want, and then it will find the best way. For example, we will tell LATEX to make a section, and the system will deal with font changes, vertical spacing, etc.

 

Step 5: write a section

\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}
This is some  preamble  text  that  you  enter  yourself.

\section{Text  for the  first  section}
\lipsum [1]

\subsection{Text  for a subsection  of the  first  section}
\lipsum [2-3]
\label{labelone}

\subsection{Another  subsection  of the  first  section}
\lipsum [4-5]
\label{labeltwo}

\section{The  second  section}
\lipsum [6]

Refer  again to \ref{labelone}.
Note  also  the  discussion  on page \pageref{labeltwo}

\subsection{Title of the  first  subsection  of the  second  section}
\lipsum [7]
\end{document}

 

Note that the numbering of sections and subsections is done automatically. How to change their appearance is beyond the scope of this document, but the point is that they will be generated for you.

Run pdflatex LATEX second and view the PDF file. Notice that the references we just entered don't work -- they appear as question marks. When LATEX runs, it saves the label to a file. When you run a file with the first label, it has not been saved. When you run pdflatex LATEX second for the second time, the question mark disappears.

 

Keywords: Latex

Added by validkeys on Wed, 26 Jan 2022 13:36:28 +0200