In a tex.SX user profile, I read the best practice recommendation

Execute pdflatex \input{filename} instead of pdflatex filename.

I have always used the latter one, directly, in scripts, and in Makefiles.

What would be a reason to always use pdflatex \input{filename} instead?

  • 1
    you can ask Garbage Collector aka Adorable Creature herself in the chat, she is there from time to time.
    – yo'
    Feb 7, 2013 at 11:31
  • Oh, I totally missed that I already have the "talk in chat" privilege now.
    – fbmd
    Feb 8, 2013 at 21:37
  • Chatting requires "only" 20 pts :)
    – yo'
    Feb 8, 2013 at 21:43
  • 1
    It should be meant as best typing practice. :-) Feb 13, 2013 at 14:33
  • @GarbageCollector Turning a disadvantage to an advantage, clever! :-) Feb 13, 2013 at 17:06

1 Answer 1



  • It is a good trick, if someone wants to put TeX code before. Examples:

    pdflatex '\def\foo{bar}\input{filename}'
    pdflatex '\includeonly{introduction}\input{filename}'

    or inside \write18 (shell escape feature):

    \immediate\write18{\detokenize{pdflatex '\def\foo{bar}\input{filename}'}}
    \immediate\write18{\detokenize{pdflatex '\includeonly{introduction}\input{filename}'}}

    e-TeX's \detokenize prevents the expansion of the macros inside \write, see question.

  • Also LaTeX catches the error message a little better, because it checks for the file first and throws a proper error message.

    The TeX behaviour of '\input' without braces or on the command line would be:

    pdflatex filename
    ! I can't find file `filename'.
    <*> filename
    (Press Enter to retry, or Control-D to exit)
    Please type another input file name: 

    Then you can escape from there with Control-D (Unix) or Control-Z (Windows). or the file x.tex of LaTeX's tools bundle can be used for this purpose.

    LaTeX throws instead:

    pdflatex '\input{filename}
    ! LaTeX Error: File `filename.tex' not found.
    Type X to quit or <RETURN> to proceed,
    or enter new name. (Default extension: tex)
    Enter file name: 

    Then LaTeX already looks for x or X as answer to abort the job.

    Answer to a comment: However, in both variants an error message is thrown, if the file does not exist. An interactive prompt in a command chain (pdflatex test && do something) can be avoided by the pdfTeX options interaction=batchmode or --interaction=nonstopmode.


  • It's longer than filename.
  • The backslash needs special treatment (quoting, doubling) with many shells.


IMHO the two described "advantages" are indeed too weak for always using pdflatex \input{test} over pdflatex test. At least I have tried to find possible reasons. And the trick with putting TeX stuff before \input is worth to be remembered.

  • 3
    Still, these doesn't seem to me as advantages of pdflatex "\input{filename}", rather as features: You can do pdflatex "\def\foo{bar}\input{filename}" if you have a need for such trick. It is a bit like saying: You can use cat this way: cat file | sed 's///g' because this allows you to do cat file | sed 's/foo/bar/g' easily.
    – yo'
    Feb 7, 2013 at 11:29
  • 2
    Well, saying cat file | sed ..., independently of what sed ends up doing, is a canonical example of a Useless Use Of Cat... :-) Feb 7, 2013 at 15:55
  • 1
    I am sorry, but I still don't get it. I use the \input trick quite a lot to put TeX code before when I need so, but what exactly is the advantage of a plain pdflatex \input{filename} over pdflatex filename, as asked by the OP?
    – Daniel
    Feb 13, 2013 at 8:28
  • I really should try asking the user who stated this in the first place. I see the point in the answer, but advantage #1 is not as common to make a habit of \input{}, and advantage #2 breaks pdflatex file && do something bash chains with an interactive prompt. I still see no reason to always use it.
    – fbmd
    Feb 13, 2013 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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