Sign up ×
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.

What I'm trying to do is input file1 if it exists and input file2 otherwise, without having to deal with an 'I can't find file' error. I would like to accomplish this using TeX, without using symbolic links. What I would like is some kind of \try command:


Of course, this would try to input file1 and, if it encounters an error, input file2 instead.

I'm sure people who are more proficient than I am with plain TeX could accomplish this easily.

(Please feel free to edit the tags.)

share|improve this question

marked as duplicate by lockstep, T. Verron, Stephen, Werner, Kurt Feb 28 '13 at 21:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

There's an \InputIfFileExists, see e.g. how do I use the \input command on windows, combined with \IfFileExists? – Torbjørn T. Feb 28 '13 at 20:25
A poor man's attempt at conditioning: \IfFileExists{fileA.tex}{\input{fileA.tex}}{\input{fileB.tex}}; \InputIfFileExists does exactly this. – Werner Feb 28 '13 at 20:30
Excellent! Thank you. Should I close this question, then? – Z Norwood Feb 28 '13 at 20:31
I dunno. I think try/catch functionality in LaTeX would be useful, if possible. I have my doubts though, since all the languages I can think off with that feature have a thin over-layer as sort of a dispatcher. – Sean Allred Feb 28 '13 at 20:33

Browse other questions tagged or ask your own question.