# Textmate 2 and Latex

How can I set the main file in Textmate 2 in order to make it compile my complete dissertation and not the file I am editing?

You need to tell your Latex editor where the main file of your dissertation is placed, in regard to the document you are editing. To define it, add this command to the header of the .tex file that you are editing:

``````%!TEX root = ../Main.tex
``````

Just edit the path to your main file (in this example "../Main.tex") from the file you are editing. I usually have a file "main.tex" as master document and I link the chapters or sections of the document which are placed in sub-folder.

To try it out, open the menu Bundles -> Latex -> Project Management -> Open Master File With this line in the head the main.tex file will open. Then you can compile it directly from the included .tex file with Bundles -> Latex -> Typeset and View

• This is robust and nice, but you have to add the header line to all .tex files in the project. With Pontus's solution you only have to add the line once per project. Jul 20, 2016 at 13:20

To set the master file on a project basis, put

``````TM_LATEX_MASTER = "/path/to/main.tex"
``````

in a file called `.tm_properties` in your project root.

As an alternative, have a look at the Subfiles and Standalone packages.

Alternatively to the above suggested way, you could set a TextMate Variable that should be called TM_LATEX_MASTER and point it to your main latex document (copy the path into the variable value field next to the variable name).

The place where you can set TextMate's variables is under TextMate's Preferences (cmd+,) and go to the "Variables" section.

• The problem with this is that you would have to change this variable whenever you want to compile a different LaTeX document. So Pontus's solution might be better for most people. Jul 20, 2016 at 13:19