Icon for parent category 'Writing'

Basic Syntax II

Continuing on last chapter, I’ll discuss some more general syntax. These will become more and more important as you get deeper into working with LaTeX.

Environments

The commands from the previous chapter applied to short bits of text, maybe even single words. Often, however, you want a certain typesetting or command sequence applied to a big chunk of content.

That’s when we use an environment. Environments need to be opened and closed, using:

1\begin{environmentName}
2    ... text and commands ...
3\end{environmentName}

For example, lists are environments, as well as tables and figures.

Switch Variation

Most commands with a single required argument have an alternative syntax, called the switch. Why? Because it can be easier to use or type. Such a syntax doesn’t need its required arguments stated right after it, but rather applies the command to the whole block or environment that it’s in.

The two commands below are identical.

1{ \switchCommand text }
2
3\command{text}

When possible, I provide the switch alternative as well, whenever a new command is introduced in this course.

1Some \emph{emphasized text}.
2
3{Some \em emphasized text}
Code left > output right
Code left > output right

Star Variation

Most commands also have a star variation. This simply means you append an asterisk (*) to the command name.

1\command*[optionalArgument]{requiredArgument}

This usually tweaks the behaviour of the command slightly. In certain use cases, the default command is very annoying, but the star version is exactly what you need.

1\section{I am a section}
2\section*{Me too!}
3\section{And three make a crowd.}
Code left > output right
Code left > output right

Comments

Comments are the only thing that doesn’t use the regular command syntax. But that’s only logical—comments are not interpreted and not used in the final document, so the computer doesn’t need to see them. Comments are only there for you to tell yourself what certain parts of the code do. To help remind yourself, or clarify what that code you wrote 6 months ago did.

Single line comments are created with % comment.

1This is %an inline comment 
2cool!
Code left > output right
Code left > output right
Remark

LaTeX is case-sensitive and all commands are lowercase. Only symbols or special packages might start with a capital letter. So, did a mysterious error occur? Then an uppercase letter might have accidentally slipped in.

Support me and this website!

Want to support me?

Buy one of my projects. You get something nice, I get something nice.

Donate through a popular platform using the link below.

Simply giving feedback or spreading the word is also worth a lot.