Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 main LaTeX file which inputs many other LaTeX files i.e. for example


Let's call the above file say main.tex. I want a single LaTeX file, which imports contents from input1.tex,input2.tex, input3.tex and input4.tex, so that I have only one single LaTeX file instead of the above four LaTeX files. How do I go about writing a bash-script which does this job for me?

PS: I need to submit an article a journal and I thought it would be good to have a single .tex file. The issue is the following. I have different files in sub-directories in a recursive manner and hence I cannot upload these individual files since the directory structure in the input command is on the local folder on my computer. I could of-course put these manually but I thought if there would be a way out similar to the .bbl file for the bibliography.

share|improve this question
You have many tools that seem to do what you want listed here:… – Salem May 25 '13 at 22:34

This solution should work.

perl latexpand main.tex > newarticle.tex
share|improve this answer
@guntbert I don't believe this is a "thank you" answer as it is the only answer here. The comment it is referencing points to an answer on TeX - LaTeX so I think this is fine. (I'm guessing you posted that comment from review and couldn't see this things, one of review's failings, I guess) – Seth Apr 16 '15 at 23:39

Your Answer


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