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

I have a file called main.tex, which looks like this:


I want to know if it is possible to have it take this file a.tex in argument, such that I could compile it in a manner that depending on the argument it gives a different output automatically.

Something like pdflatex main.tex < a.tex > a.pdf

share|improve this question
Does this help: tex.stackexchange.com/questions/24357/… – cmhughes Oct 9 '11 at 15:55
It indeed seems close to tex.stackexchange.com/questions/1492/…. I need to take a closer look, see if I can get my answer. Thanks – Gopi Oct 9 '11 at 16:07
Ok, it is not exactly working the same way since they seem to be working the other way around: changing the headings instead of the content. I suppose theoretically we could do it symetrically but it is not obvious to me :s. – Gopi Oct 9 '11 at 16:18
up vote 4 down vote accepted


pdflatex '\def\myfile{a.tex} \input main.tex'

and a main.tex with

share|improve this answer
Awesome, that was what I needed. Is there then a way such that latex gives to the output the name "a.pdf" (otherwise I will add the bash command "mv main.pdf a.pdf", but it seems less understandable than if it had the name in the first place :s) – Gopi Oct 9 '11 at 16:33
try -jobname=a – Herbert Oct 9 '11 at 16:50

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.