WinEdt assign hotkey or icon to compile project

I have several files open in winedt that are all related in a sort of project. I have the main file that includes the other files.

Is there any way to set it up so when I compile any one of the files it compiles the main one instead(and saves the others)? I don't mind hard coding the file names if necessary.

I'd like to have a custom icon for this so that any time I'm working on a large multifile project I can modify the icon to compile the main file.

-
You need to set the "Main File" for the project under the Project menu. The currently set main file should be displayed in the status bar and compile be default. – Werner May 13 '12 at 3:14
@Werner I don't know what you mean by "compile be default". When I click the "compile" button it just compiles the current file. The project is set for my main file that I want to compile but I don't see where to compile it at. – Uiy May 13 '12 at 4:05
From this help file: "Note that your actual position was in the Introduction Chapter (`T0.tex`). So, how did WinEdt know to compile the main file `Thesis.tex` rather than the current chapter (which would fail to compile without a proper preamble present in the main file). This is because `Thesis.tex` is set as the main file...For your convenience the name of the currently set main file is displayed in the last panel of WinEdt's status line..." – Werner May 13 '12 at 4:38
@Werner Ok, the problem is that you must use `\include` for winedt to find the files then `build all`. The problem is I modified the include macro to use spaces(I build the file name in lua so I can simply do \incfile{"My spaced filename"}. Winedt doesn't like this. – Uiy May 13 '12 at 4:43
TeX and related tools really don't like spaces in file names. There is a strong presumption against using them. – Joseph Wright May 13 '12 at 8:07

WinEdt requires one to use `\include` for it to know the included files to the main target file. If you use spaces in your includes then it will break tex. A work around is to wrap include to insert `\space` for spaces:

Here is a lua function that will convert the filename to something tex will recognize properly:

``````function tex.ConvertToSpace(str)
str = string.gsub(str, " ", "\\space ")
tex.print('\\incfile{"'..str..'"}')
end
``````

And here is a modification of the `\include` command that will allow WinEdt to work properly:

``````\let\incfile\include
\renewcommand{\include}[1]{\directlua{tex.ConvertToSpace("#1")}}
``````

Simply call it like you would normally

``````\include{My filename with spaces}
``````
-