Getting started with LaTeX: code input methods and basic syntax

Explain clearly the composition of LaTeX source files: document type declaration, introductory area and body, as well as the writing method of commands, environment, parameters and comments. It also provides common misunderstandings, the basis for choosing the input method and the steps to get started, which is suitable for readers who are new to LaTeX.

Key points of this article

  • The LaTeX source file is plain text. Commands and environments are used to describe the content and structure, and then the PDF is generated by the typesetting program.
  • Commands start with a backslash, arguments are enclosed in curly braces, and optional arguments are enclosed in square brackets.
  • The environment is wrapped in pairs \begin{name} and \end{name}, and the two names must be exactly the same.
  • A single line break in the source code will be treated as a space, and only a blank line will start a new paragraph.
  • Special characters such as percent signs, pound signs, and dollar signs must be escaped with backslashes before they can be displayed literally.

When many people open the LaTeX source code for the first time, they will see a string of words starting with a backslash and pairs of curly braces, and they don't know what each of them is responsible for. This article is written for readers who are new to LaTeX and want to figure out how to write code first. We will not talk about its development history, but only about input methods and basic grammar.

After reading this article, you should be able to understand the structure of a simple LaTeX source file, distinguish commands, environments and parameters, and determine which input method is suitable for your document this time. The examples in the article can be copied and typed in the plain text.

What is LaTeX code? One sentence conclusion

LaTeX code is a plain text typesetting description: you use commands and environments to write the content and structure, and the typesetting program generates PDF according to rules. You do not have to directly adjust the position of each line of text.

your situationRecommended practicesreason
Writing a thesis or dissertation requires lots of formulas, numbers, and referencesUse LaTeX source code and apply document type templateFormulas, numbers and references are processed uniformly by the program, and are updated as a whole after modification.
Only write a few pages of instructions or meeting materials, with few formatting requirementsEdit with Word or MarkdownGet started quickly, what you see is what you get, no need to remember commands
I already have a LaTeX source code compressed package and want to translate it into other languages.Upload the source code package on omnidoc.top and choose bilingual comparison or translation onlySupports LaTeX source code packages, the translation retains formulas and structures, but still requires manual verification
I want to see the results while writing in the browser and transfer them to and from Word.Use the UniDoc web editor (app.unidoc.top)Supports round-trip conversion between Word and LaTeX, suitable for cross-format collaboration
Need to change PDF text, sign, fill in forms or do OCRDownload the desktop client (download.omnidoc.top)The desktop PDF editor includes paragraph text modification, signature, form filling, blackout, page manipulation, OCR and export functions

Composition of source files: declaration, introduction area and body

A LaTeX source file is usually divided into three parts, and if you understand this division, the later syntax can be easily relocated.

document type declaration

The document type is declared at the beginning of the file with \documentclass{article}, and there are also report (reports) and book (books). This line determines the default style for headings, chapters, margins, and so on.

introduction area

The introduction area refers to the part before \begin{document}. Here are the full-text settings, such as loading the feature pack with \usepackage{...} and defining the title and author with \title{...} and \author{...}. The contents of the introduction area do not appear directly on the page.

text area

Between \begin{document} and \end{document} is the text. Paragraphs, chapters, lists and formulas are all written here. In the source file, the content after \end{document} is ignored.

# basic syntax: commands, environment, parameters and comments

There are not many grammatical elements in LaTeX, but there are strict requirements for each writing method.

Command: start with a backslash

The command consists of a backslash plus a name, such as \section{引言} for a chapter title and \textbf{重点} for bold. The command name consists of only letters and ends when a space or non-alphabetic character is encountered.

-{} in curly braces is a required parameter, and an error is usually reported if it is missing. -Square brackets [] are optional parameters that can be omitted, such as \usepackage[utf8]{inputenc}. -the space immediately following the command is usually ignored. If you need to keep it, write it differently or use \ (backslash plus space).

Environment: begin and end appear in pairs

The environment is used to wrap a structured piece of content, written as \begin{名称} and \end{名称}. The common ones are itemize (unordered list), enumerate (ordered list), table (table) and equation (formula). The two names must be exactly the same, and omission or misspelling will cause compilation to fail.

comments and special characters

After the percent sign %, the contents of the same line are comments, do not participate in typesetting, suitable for writing notes. If you need to display the percent sign itself, write it as \%. Characters such as pound sign, dollar sign, and sign, underscore and curly braces also need to be escaped with a backslash.

# Common misunderstandings and easy to confuse

- commands are confused with the environment. \textbf is a command with only one parameter; itemize is an environment and needs to be wrapped in begin and end. The judgment is based on whether there are pairs of \begin and \end. - thought that if you enter the car, you can change the paragraph. A single line break in the source code will be treated as a space. To segment, you need to leave a whole line between the two paragraphs. - thought that multiple spaces would become multiple whitespace. consecutive spaces will be merged into one, and for extra white space, a special spacing command is required. - compiling once is thought to be complete. the numbers of directories, cross-references and references sometimes have to be compiled twice before they are updated. When the results are incorrect, compile several times and then check again. - it can be displayed by writing it directly in Chinese. * UTF-8 encoding is required in Chinese, and the Chinese language support feature package (such as ctex) is loaded. In the absence of these settings, the Chinese may appear blank or report an error.

# Core comparison

TypesBasic writing methodActionCommon examples
Command\命令名{参数}To perform an action or mark.\textbf{加粗},\section{标题}
Environment\begin{名称} is paired with \end{名称}Wrap a structured piece of contentitemize,table,equation
Inline formula$...$Embed the formula in a line of text$E=mc^2$
AnnotationContent after %Write notes and do not participate in typesetting% 待补充数据
Escape characterSpecial characters are preceded by \Display special symbols literally\%,\$

# how to use it

  1. Create a new plain text file with the extension .tex, write the document type declaration first, and then write the \begin{document} and \end{document} framework.

two. Load the required function package with\usepackage in the introduction area; when it comes to Chinese, make sure that the file is encoded as UTF-8.

  1. Write paragraphs in the body area with a blank line between paragraphs; use the context when you need a list, table, or formula, and check to see if \begin and \end are paired one by one.
  2. To see the effect in a browser or to convert to and from Word files, you can open the UniDoc Web Page Editor (app.unidoc.top), which supports round-trip conversion between Word and LaTeX.
  3. When you have a complete LaTeX source code package, you can upload it in omnidoc.top, choose bilingual control or translation only, and check the formula, number and terminology paragraph by paragraph after downloading the result. Both the translation and OCR results require manual checking of important content.

# which method is suitable for you?

If your documents are based on formulas, chapter numbers and references, and need to be revised for a long time, the structured writing of the LaTeX source code is easier. If it's just a short document, a simple format, or team members are used to collaborating with Word, it takes less time to use Word or Markdown directly. Two ways can also work together: first complete the conversion between Word and LaTeX in UniDoc, and then decide which format to use for final delivery.

# frequently asked questions (FAQ)

1. Do I need to remember many commands in LaTeX code?

You don't have to write it down all at once. In the entry stage, you can complete most of the documents by mastering the common commands of document structure, chapters, bold, lists, formulas, and tables. Other commands can be checked when needed.

2. Where do I start when compiling an error?

First look at the line that appears early in the error message, which usually points to the first real problem. The common reasons are that the curly braces are not matched, the environment name is misspelled or omitted \end, and the Chinese feature pack is not loaded. Fix it one by one and then recompile.

3. Can the translated LaTeX source code be used directly?

The translated source code needs to be recompiled and checked for normal formulas, chart numbers, cross-references, and references. Machine translation may change the terminology. Before formal submission or delivery, it is recommended to check paragraph by paragraph by someone who is familiar with the professional content.

4. What should be paid attention to in Chinese documents?

Make sure that the source file is saved in UTF-8 encoding and load the Chinese support package in the introduction area. If the Chinese display is blank, first check whether the coding and function package are set correctly, and then check whether there are unclosed curly braces in the text.

# Summary

The key to getting started with LaTeX is to distinguish between the document type declaration, the introduction area and the text, and to master the writing of commands, environment, parameters and comments. By aligning begin with end, pairing curly braces, and escaping special characters, you can avoid most beginner errors. Following the steps in this article to practice a few short documents, and then choosing LaTeX, Word, or Markdown based on the content, is more effective than pursuing complex typesetting in the first place.

Open OmniDoc to edit, convert or translate your LaTeX document

Updated 2026-11-11