A introduction to creating documents in LaTeX

Learn to typeset documents in the LaTeX text markup language.
553 readers like this.
A introduction to creating documents in LaTeX

Opensource.com

LaTeX (pronounced lay-tech) is a method of creating documents using plain text, stylized using markup tags, similar to HTML/CSS or Markdown. LaTeX is most commonly used to create documents for academia, such as academic journals. In LaTeX, the author doesn't stylize the document directly, like in a word processor such as Microsoft Word, LibreOffice Writer, or Apple Pages; instead they write code in plain text that must be compiled to produce a PDF document.

computer screen with LaTeX markup language

opensource.com

How to get started

To write in LaTeX, you'll need to install a LaTeX editor. I use a piece of free and open source software (FOSS) popular with academics called TexStudio, which runs on Windows, Unix/Linux, BSD, and Mac OS X. You'll also need to install a distribution of the Tex typesetting system. I am writing on MacOS, so I use a distribution called MacTex or BasicTex. For Windows you can use MiKTex, and Linux users should be able to find it in their repository.

Once you have downloaded TexStudio and a distribution of LaTeX, you should be ready to start typesetting your documents.

Create your first document

In this short tutorial, we'll create a simple article with a headline, a subhead, and two paragraphs.

After you launch TexStudio, save your new document. (I called mine helloworld.tex, since I'm writing this tutorial in the Hello, World! tradition from programming.) Next, you need to add some boilerplate code at the top of your .tex file that specifies the type and size of your document. This is similar to the boilerplate code used in HTML5 documents.

My code (below) sets the page size to A4 and the text size to 12pt. You can put this code into TexStudio and edit it with your own page size, font size, name, title, and other details:

\documentclass[a4paper,12pt]{article}
\begin{document}
\title{Hello World! My first LaTeX document}
\author{Aaron Cocker}
\date{\today}
\maketitle

content will go here 

\end{document}

Next, click on the large green arrow to compile the document. That's the middle button in the screenshot below.

compile button in TexStudio

opensource.com

If there are any errors, they'll appear in the dialog box at the bottom.

After you compile the document, you can see what it will look like by viewing a PDF within the program as a sort of WYSIWYG preview. Remember it must be recompiled whenever you make a change to the code, as you would when programming in C++, for example.

To view your document, click on Tools > Commands > View PDF, as shown in the screenshot below.

Menu to view a PDF

opensource.com

The PDF output will be shown on the right, like this:

Viewing the LaTeX code as PDF

opensource.com

Now you can add a paragraph. First give it a subhead by using the \section{} command. Type the subhead title between the curly braces of the command; I called my subhead Introduction.

\section{Introduction}

Now that you have labeled the paragraph with its subhead, it's time to write the paragraph. For this example, I used the Lipsum lorem ipsum generator. To create the paragraph, type the \paragraph{} command, then add your text underneath, NOT within, the curly braces, inserted between \maketitle and \end{document}.

This is what my paragraph code looks like:

\section{Introduction}

\paragraph{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas sollicitudin. 

\paragraph{}
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non elementum leo. Nullam molestie congue placerat. Phasellus tempor et libero maximus commodo.

Your document is now finished, so you can export and save it as a PDF file by using Save As (just as you would with most programs).

Here's what my finished document and the corresponding code look like:

The finished document with code and the PDF output side-by-side

opensource.com

All my code from this tutorial is available below:

\documentclass[a4paper,12pt]{article}
\begin{document}
\title{Hello World! My first LaTeX document}
\author{Aaron Cocker}
\date{\today}
\maketitle

\section{Introduction}

\paragraph{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas sollicitudin. 

\paragraph{}
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non elementum leo. Nullam molestie congue placerat. Phasellus tempor et libero maximus commodo.

\end{document}

Learn more

Among the thousands of excellent resources on writing in LaTeX are the guides produced by most universities, which are indexable and can be found on Google search. Princeton University offers a good extended tutorial, and for a deeper dive, the Princeton guide's creator, Donald Knuth, offers The TexBook, the ultimate guide to LaTeX.

User profile image.
Computer Science teacher in an FE college (16-19 years old) in the North of England, open source enthusiast, avid podcast listener and Linux user of over 7 years. I have an honours degree in Computing and a Postgraduate Certificate in Project Management.

6 Comments

LaTeX seems like an awful lot of typing when you first start, but once you see the results of what you can do with it, it's very impressive. It's especially good with creating tables, whether you want items centered, or right- or left-justified in columns. I used it for years for various forms I created, where you can create templates so you don't have to recreate preambles and table structures each time. I also found minipages a very handy thing to learn about.

If you talk to people about LaTeX you have to be prepared for a variety of pronunciations. It seems Europeans tend to say Lah-Tecccch, with sort of a guttural pronunciation of the Greek X at the end.

Your usage of the paragraph command is wrong. It is a section heading, so if you don't want a title for your paragraph just use a blank line to separate between them. :)

See here for more information: https://tex.stackexchange.com/a/130418/56242

It's a daft habit I have to make it easier to separate out my paragraphs in my own documents, but rightfully it shouldn't be in there, thank you :)

In reply to by Lazza (not verified)

For the last few years I have been using the LyX Gui. For simple to medimum documents I find it works just great. For the most part I do not have to edit any code, just type and format .

Even if you need to edit your code LyX is great: it provides you with the necessary tools, both to modify your Preamble and to add code to the document. I have a really complex document with a 100 lines preamble + 70 lines defining character styles (using XeTeX and a lot of OpenType tricks) + lots of code on the document, and everything run smoothly. LyX is great on every aspect :)

In reply to by patrickw99

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.