DEV Community

latexteada
latexteada

Posted on

LaTeX: The include Command

Hello, how are you? :)

In this post I talk about

  • The \include command

Introduction

The last posts of this blog have been about Macros we have checked some variants of macros and we have seen that these are declared in the preamble of our document, so, if we want to declare a new macros we must go to the preamble, declare them there and then go back to our document, everything is fine.

But what happens if we need to declare the same macros in another document, and in another and so on, it will be a headache because we need to declare them in each document that we create. There must be an easy way to do it, and this is the main topic, or purpose, of this post is to teach you a very useful instruction, the \include command

The include command

Here we are going to use this command to include the macros and other environments that we will see in the following posts, but this command has another functionalities, which are not related with this topic

  • This command is declared in the preamble

As its name suggest it includes the content of other .tex (The extension of the LaTeX document) document into our current document, the command is simple

\include{pathOfFile/nameOfFile}
Enter fullscreen mode Exit fullscreen mode

Including a file with include

Do not forget to add the extension of the file, in this case, it is .tex If you do not add it you will get an error

We have seen that the command to include a file is \include{} but we need to give the pathOfFile it is the location of our file that we want to import to our current file, and there are three possibilities

  • File in the same location where we are working We just need to put the name of the file
\include{myFile.tex}
Enter fullscreen mode Exit fullscreen mode
  • File in the same location but inside another folder We need to put the route to the file, indicating the name of the folder in the path.

Let's suppose my folder's name is myFolder

\include{myFolder/myFile.tex}
Enter fullscreen mode Exit fullscreen mode

If it is inside multiple folders we just put the name of all the folders where it is and then the name of the file

\include{myFolder/.../myFile.tex}
Enter fullscreen mode Exit fullscreen mode

Where the ... is the short for all the folders, but you must put the name of all the folders

  • File in a different location Here we need to put the specific route where the file is. In the last point we see that to go deeper we need to put the name of the folders, now to go backward we need to use ..
\include{../myFolder/myFile.tex}
Enter fullscreen mode Exit fullscreen mode

This is all for today, thanks

Do not forget to follow me on twitter @latexteada

Greetings :)

Top comments (0)