brief into to latex

In this short article, I will give a brief introduction to the grammar of LaTeX.

1. Structure of .tex file

1.1 Basic elements


documentclass[opt,opt]{class}. uesd at the very beginning of a document. where opt can be:

  • Font Size:10pt/11pt/12pt etc.
  • Papar Size:leterpaper/a4paper etc.
  • Use two columns:twocolumn.
  • Set margins for two-sided:twoside.

and class can be:

  • book/report/article/letter/slides

input{inputfile.tex} used to include the file specifying ducument layout, which is optional.

author{text}, title{text}, date{text} are used to declare proprieties of this file.

begin{document} and end{document} used to start contents and end the document

section{text} used to begin a new section. And subsection{text} to create sub-section.

  • some other strucures:part{text},chapter{text}
  • in section*{title}, to not number a particular item—these items will also not appear in the table of contents.

1.2 key elements


begin{tabbing} and end{tabbing} used to start tabbing and end the tabbing

  • hspace{l} Horizontal space of length l (Ex:l=20pt or l=3cm). And vspace{l} where v means vertical.

  • use = to set tab stop, and kill at the end of the line.
    • Ex: hspace{3cm} = hspace{4cm} = kill
  • > used to go to tab stop (set once, and go many times), and \ is used to separate lines(end this line, and may create a new line).

begin{tabular}[position]{cols} and end{tabular}

  • the cols is decided by your need, it can be l c r or l c c c c r and l | c | r means that inserts a vertical line between columns.
  • hline Horizontal line between rows. cline{x-y} means horizontal line across columns x through y. And x and y are numbers.

2. Text and symbols

2.1 Text


{bf text} or textbf{text}bolden the font. {it text} to Italic.

href{mailto:website}{text},use href in you text:

  • Ex: href{mailto:https://www.google.com}{google.com}

hfill Horizontal space betwwen the two blocks

parabox[position]{length}{text} to put something into the one kind of box.

2.2 Symbols


For inline math, use(..) or $ $.
With the limits of the display in website, more details find at offical document of LaTeX

3. Some other important things you should also know:

  • The test environment in this passage is MacTex.
  • To use LateX in Sublime Text, you can find steps of configuration at here.
  • To use Chinese characters in your LaTeX, you can use xelatex Engine. Adding %!TEX program = xelatex at the beginning of your LaTeX code.
  • To install more available package:tlmgr install <package> in your terminal