TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


For one project, I store all my header .tex/.sty files in ../../../Templates, and all the files need to be at a particular relative directly location so using this relative hierarchy enforces that rule.

In order to speed up compilation, I created a pre compiled .fmt file. Now to use this, I can either:

  1. Add to the command line:

    -fmt ../../../Templates/MyPreamble
  2. Add the following line as the the first line in my .tex file:

    %& ../../../Templates/MyPreamble

and both methods work fine.


What I would like to do is to to have the first line in the .tex file as


and the content of the MySetup.tex invoke the .fmt file with something such as:

%& ../../../Templates/MyPreamble

Is there anyway to do this?


I am open to any other suggestions as well, but here is my reasons for this:

  1. I used the first method and adjusted the pdflatex command in TeXShop to have that directive. However, when I am working on some other project (ex, an TeX.SE answer) I do not want that pre-compiled format, so need a way to disable it. Hence decided not to use this method.

  2. I already have ALL file individual files set up to \input the MySetup.tex file on the very first line. If I can just change that one file, then I can easily switch between using the pre-compiled format or not, by just changing the MySetup.tex file. And yes I could use a shell script to update all the files, to add this first comment line, but would prefer to not to do that.

share|improve this question
It might be easier to set up two different compile actions in TeXShop (if it supports it), so you can use the normal pdflatex route for TeX.SE answers etc, and your own mypreamble route for everything else (though you would have to remember to press the right one). Alternatively, you could set up the compile action to be a script that checks based on the location of the document (or the first line of the file say) which command line to invoke. – cyberSingularity Nov 8 '12 at 23:42
@cyberSingularity: Yeah thought of that, but need to also do it for TeXworks. Since it seems that what I want can not easily be done, it seems that I need to go down that route. – Peter Grill Nov 9 '12 at 0:10
up vote 4 down vote accepted

You have a slight problem in that the syntax


requires \input to be a macro with one argument which requires the format with that definition to have been loaded, so you can't use it to input a file that will load the format.

What you can do (which is what my ancient pre-latex2e) mylatex.ltx does, is redefine things so that you can have a standard latex preamble which will be read as normal but your custom format skips to \begin{document} to a custom command or comment depending on you needs.

If you want to keep with your existing file structure with \input then in the format file just define


which will mean that if using latex your first line of


will input foo.tex but if using your custom format then foo.tex won't be loaded but \input will be (re)defined to its normal latex definition so the rest of the file will work as normal.

If you do almost any tex operation it is too late to switch formats so the format specification has to be on the commandline or the magic first line comment.

share|improve this answer
@egreg er the def should be there but it was supposed to be defining input, will fix thanks:-) – David Carlisle Nov 8 '12 at 23:40
Summary: I can't do what I want to do!! – Peter Grill Nov 9 '12 at 0:14

Your Answer


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.