Suppose that both tex1.tex and tex2.tex are two independent tex files in the sense that both compile and generate a pdf file independently. I would like to include the output of tex2.tex in the tex1.tex dynamically. I want to achieve this with one step of just compiling tex1.tex file ( and latex automatically do the second compile as a prerequisite step if I have referred to its result)

My Question: Is there any mechanism (like some instruction that can be added to tex1.tex) telling latex that when I am compiling tex1.tex it should first compile tex2.tex to its corresponding pdf, and then compile tex1.tex document with the tex2.pdf file included as a picture inside it.


I am adding example files for tex1.tex and tex2.tex to make the question more concrete: suppose my tex1.tex is as bellow:



\title{Inserting output of a tex file as pdf in one step}


        I want to inset bellow this line my diagram from file (tex2.tex):

I want to inset bellow this line my diagram from file (tex2.tex):


and my tex2.tex file is as bellow:

% TikZ chains with labeled edges
% Author: Stefan Kottwitz , http://texblog.net
\tikzset{join/.code=\tikzset{after node path={%
edge[every join]#1(\tikzchaincurrent)\fi}}}
\tikzset{>=stealth',every on chain/.append style={join},
         every join/.style={->}}
\tikzstyle{labeled}=[execute at begin node=$\scriptstyle,
   execute at end node=$]
  \matrix (m) [matrix of math nodes, row sep=3em, column sep=3em]
    { 0 & A  & B  & C  & 0 \\
      0 & A' & B' & C' & 0 \\ };
  { [start chain] \chainin (m-1-1);
    \chainin (m-1-2);
    { [start branch=A] \chainin (m-2-2)
        [join={node[right,labeled] {\eta_1}}];}
    \chainin (m-1-3) [join={node[above,labeled] {\varphi}}];
    { [start branch=B] \chainin (m-2-3)
        [join={node[right,labeled] {\eta_2}}];}
    \chainin (m-1-4) [join={node[above,labeled] {\psi}}];
    { [start branch=C] \chainin (m-2-4)
        [join={node[right,labeled] {\eta_3}}];}
    \chainin (m-1-5); }
  { [start chain] \chainin (m-2-1);
    \chainin (m-2-2);
    \chainin (m-2-3) [join={node[above,labeled] {\varphi'}}];
    \chainin (m-2-4) [join={node[above,labeled] {\psi'}}];
    \chainin (m-2-5); }
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 21 '15 at 23:56
  • @ChristianHupfer I added example files. – qartal May 22 '15 at 0:17
  • Your example files are not really minimal. I am not sure if your are not after externalization really... – user31729 May 22 '15 at 0:20
  • I will check later on if your files work with bashful – user31729 May 22 '15 at 0:32
  • 1
    Have you considered a Makefile? – Hagen von Eitzen May 22 '15 at 8:32

Perhaps this is what you want: Use bashful package, which allows the execution of shell commands or external programs (I can test this only on Linux right now)

The external program(s)/commands must be 'enclosed' in a



Note: The compilation of the 2nd file is done each time when the outer wrapper document is compiled.




pdflatex tex2ext






  • 1
    I omitted a screen shot, since \blindtext is quite well-known – user31729 May 22 '15 at 0:04

Looks like a job for shell escape (\write18):

\immediate\write18{pdflatex \jobname2}

I've used the same demo files as Christian Hupfer's answer but have run them together (using the filecontents environment) to make things a little smoother.

To get this to work you'll need to allow shell escape, so

pdflatex --shell-escape <filename>

at the command line or the equivalent in your editor. Note that there is a security risk with \write18 as in theory any instruction could be passed by a third-party file.

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.