Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've written a makefile for my current project which produces all deliverables (executable, written in C, and report, written in LaTeX). I have a directory structure whereby the Makefile and outputs (pdf and executable) sit in the parent directory, and source code sits in a Code/ directory, and the LaTeX sits in a /Report directory, similar to:

Directory Structure Diagram

At present the Makefile (in the Project directory) has to cd into the Report directory before running LaTeX, a bit like the following:

Report: $(CODEFILES) $(TEXFILES) Report/Build
    cd Report/; \
    $(TEX) $(TEXARGS) Report.tex

Is there any way to tell LaTeX run as if it were in another directory, or have I done this in the best possible way? It just seems a bit of a fudge, and I'm always keen to learn of cleaner solutions!

Thanks.

Edited to update diagram, and to mention that the real problem is because Report.tex includes subfiles, preventing me from doing latex Report/Report.tex

share|improve this question
    
Let me see if I've gotten this straight: you want (via a makefile) to execute a command from the Project directory and (ideally) this would compile a document that is in Project/Report with the output pdf in Project whilst all ancillary files go in Project/Build (possibly the log stays in Project/Report). Is that right? –  Loop Space Nov 29 '10 at 10:30
    
Not that I know of. I don't see the problem with your example, but maybe you would be happier with a recursive make? –  Charles Stewart Nov 29 '10 at 10:31
    
@Andrew Stacey That's it. I'm not so fussed about the pdf being put in the /Report/Build directory with everything else (which is put there using the -build-directory=Build/ argument), as I can copy that relatively cleanly. –  Edd Nov 29 '10 at 10:35
1  
Have a look at tex.stackexchange.com/q/4602/86 as I think that the basic question there might be quite close to yours. –  Loop Space Nov 29 '10 at 11:05
2  
There is nothing wrong with changing the directory (most Makefiles do this), but you should always use cd ... && ..., otherwise you run into trouble if the cd fails. To place the ouput files somewhere else, use the --output-directory command line option. –  Philipp Nov 29 '10 at 13:32

2 Answers 2

up vote 7 down vote accepted

(Added comment as answer)

There is nothing wrong with changing the directory (most Makefiles do this), but you should always use cd ... && ..., otherwise you run into trouble if the cd fails. To place the ouput files somewhere else, use the --output-directory command line option.

share|improve this answer
    
I'm using the --output-directory flags to get the output into the Build directory already; this is being accepted for effectively confirming that there's no cleaner way to do it, and for the advice about using the cd ... && ... form. –  Edd Nov 30 '10 at 10:19

I see the trouble as you trying to beat TeX into submission by explicitly handing it your path to the input files, but trying to run it from one directory back. That is, although you cd into Project/Report, you're trying to get your output into Project.

TeX hates this and you can make it work, but you'll never be able to do it cleanly.

Example: Since until very recently, I've had a "core" directory that I used for all of my documentation (across multiple GitHub repositories). I had to use "\input{../core/trmsdocumentation.tex}" because I couldn't get it to search that path and "\include" caused all sorts of issues with aux files, etc. If I had an error in a file in core, I was screwed. Nothing could report it correctly and the debug always pointed to the line that called the macro in the offending file. Not. Helpful.

The best way out of this problem is to put your documentation tree inside your TEXMF path in your texmf.cnf file, probably using the TEXMFHOME tree. Mine reads:

TEXMFHOME = $HOME/src/tex/texmf-trms

If you have many projects and only want to activate what you're working on, make a batchfile that executes a path command before launching your editor.

Yours might read:

TEXMFHOME = /Project/texmf-project

You could CD to Project and then run latex texmf-project/local/Report/Report.tex from your Project directory and it would run fine, no matter the sub-directories within the local directory (local is a TDS thing, which I'll explain). You could also just set TEXMFHOME to your Project directory, but that would mean all of your source would be searched as well. This isn't a problem, but here again you're abusing the spirit of TeX, and TeX has a way of making you pay.

Instead, you will be even more pleased with yourself if you spend some time reading about the TDS: TeX Directory Structure. In short, if you set up your own local files using the TDS structure, in time, you'll find yourself putting your own general purpose macros into common directories that all of your projects can access. You can then keep those files in a source repository that gets updated at its own speed, thereby giving you source control over your common TeX work as well. These common files would be under a separate "TEXMFHOME" TDS path and your current projects might be under the aforementioned other "TEXMFHOME" TDS that is within your project.

Example for TEXMFHOME:

TEXMFHOME=/Projects/myproject/texmf-myproject;/Projects/texmf-common

NOTE 1: If you're using MikTeX, they have a facility to add "local TEXTREE" or something like that. If you add your source tree, you should be able to cleanly do what you want

NOTE 2: Your mileage may vary with your distribution. Notice that your project is first and your common files second. Your project overrides your common files, in case you want to make a local modification.

As I mentioned, using TDS like it was meant to be, you might make your documentation in /Projects/texmf-project/local/Report. local is reserved for this purpose and you can put it anywhere in the tree to put your own work into.

I know I'm not directly answering the question in the way that you asked it, but in a way, I'm doing something better. I'm telling you to grow up, accept the way that TeX wants you to do it, stop trying to cowboy it and instead to reap the benefits of the hard work that others put into making it work the way that you're currently trying to fight. :)

Food for thought.

If this is unclear, let me know and I'll try to clear it up. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.