(Vim+latex) How to compile a single tex file in a project directory using \ll

I am using Vim+latex. In my project directory, I have another separate tex file (for example a tikz/PGF file to draw a figure). When I input \ll, instead of compiling my current file, the system compiles the project file. Is it possible to tell the system to compile my current file?

Thanks a lot!

-
– cmhughes Aug 21 '12 at 22:58
Dear cmhughes, I read this before. It is about how to set up main file. I have done that. My problem is to compile a separate file instead of the main file. Thanks a lot! :-) – Anand Aug 22 '12 at 7:21

This might be considered a workaround by some, but I think it will work for your purposes. From the LaTeX-Suite Reference:

Each time LaTeX-Suite opens a new LaTeX file, it will try to see if it is part of a multiple file project by searching upwards (to the root of the file-system) from the current file's directory to see if it finds a file of the form *.latexmain. If such a file is found, then it is considered that the current file is part of a larger project.

What this means is that you can have multiple `*.latexmain` files per project, provided they are at different directory levels.

So let's call your main document `mydoc.tex` and the separate file `myfig.tex`. If you set up the directory structure as follows:

``````project-dir/
mydoc.tex
mydoc.latexmain
myfig/
myfig.tex
myfig.latexmain
myfiles/
ch01.tex
ch02.tex
``````

everything should work as you wish. If `myfig.tex` is the active buffer and you press `\ll`, LaTeX-Suite will find `myfig.latexmain` and compile `myfig.tex`. If `mydoc.tex` is the active buffer, `mydoc.latexmain` will be found and the document will be compiled. If anything in `myfiles/` is the active buffer, LaTeX-Suite will find no `*.latexmain` files in the current directory and will traverse up one level. It will then find `mydoc.latexmain` and compile the document as desired.

The only other change will be in the files containing the source of your document text. I assume that you are using

``````\includegraphics{myfig}
``````

to include the compiled output of the figure file in your document. You'll need to change this to a relative path now that the files are in different directories. If the graphic is included from the `project-dir/` level, use

``````\includegraphics{myfig/myfig}
``````

or, if the graphic is included from the `myfiles/` level, use

``````\includegraphics{../myfig/myfig}
``````

to include the compiled output.

This approach can be extended to multiple figure files as well: just introduce another directory for each figure such that the appropriate `*.latexmain` is always found first during the upward traversal of the directory tree.

All that said, if you need to do this for many figure files, the directory structure may get overly complex fast. It may be better to take a look at TikZ's externalization methods (Ch. 50 of the current `pgf` manual).

-