DEV Community

latexteada
latexteada

Posted on

Halt! do not just scribble: Document structure

Do you remember? In our kick-off we just note down some instructions in our editor, it is something awful because we are here to learn, not just to make a note of something. We are going to grasp what we did, so we are here again to face that problem and I am going to cue you in the LaTeX world

About the commands

All the LaTeX commands (either created by you or the default ones) begin with a backslash \
Thedocument Can you notice that? \documentclass, \begin, \end are LaTeX (default) commands, it means, those have a set function.

Arguments in commands

An argument is an instruction that you can add to modify the behavior of some command. The arguments are denoted by curly braces { } or by squared parentheses [ ], for example, in the last image in \begin we have some curly braces and inside them, we have the word document it indicates that you are going to start the document

  • Curly braces { } means that the argument is obligatory, without that argument the command will not know what to do
  • Square braces [ ] means that the argument is optional, the command can work without it.

Try it by yourself, delete {document} and watch that you are going to have an error, or the document will not compile

Backslash commands and document structure

Backslash commands

Where can we find the backslash command?

  • Commands that indicate an environment, such as \begin{document}
  • We put double backslash \\ to end that line and start a new one
  • Commands that are the name of some signs, for example \LaTeX
  • To put special characters
  • To create spaces in certain environments

In those kinds of backslash commands it is extremely important to put the backslash command before them, if not, the desire action will not take place
Try it by yourself

  1. Delete the backslash and space which is after \LaTeX, and compile the document, you will notice that there is no space between those words
  2. Delete the backslash in \LaTeX, and compile again, did you notice how we do not have the pretty letters

Document structure

A LaTeX document has 2 parts

  1. Preamble
  2. Document body

The preamble

It is the space from the command \documentclass to \begin{document} preamble
There you are going to call and declare all the things you are going to use in the document like Packages, instructions, commands, modifiers, etc. We are going to use them in some post

It is important that you do not start writing your document here, because, if you put something here either you will have an error or it will be ignored and you are not going to see it in your document when you compile it

The body

It is the space from the command \begin{document} to \end{document} body Here you must write your entire document, you can evoke the instructions or everything you called in the preamble. Everything you write here is going to be shown when you compile the document.

The correct place to create or modify commands is the preamble, yes you can do it here (in the body) it will be the same, but it is easier to find it if you already know where it is, and also it is a good practice because if someone checks your document he will notice what you have declared or modified before starting

  • In some posts we are going to learn an instruction, the \usepackage instruction this can be only declared in the preamble because, as the name indicates, this is going to import a package with some functionalities or commands. This is an example of why you need to declare all the functionalities or things that you are going to use in the preamble, if we would not declare this in the preamble and we use the functionality of some package, we are going to have an error, even if that is written correctly

The end of the document

If we put something after \end{document} it will be ignored by the compiler, so, do not put anything of your document after it

Thanks, that is all, if you have any doubts please write them and I am going to answer that, thank you

Follow me on Twitter @latexteada

Top comments (0)