I would like to redefine the \input command so that it also embed the input file to the generated pdf. So far I used the code from thi s question (Mark on document where input starts and what is the filename):


    \embedfile[desc=input file]{#1}%

            \addplot {x};

This works but it has a problem: when I use other packages as pgfplots my redefinition of \input affect also \input's commands present in the package's source codes and in my final pdf I have all these files embedded..

The second problem is that when I try to add an argument to this command in this way:

\renewcommand{\@iinput}[2][input file]{%

    \input[file description]{input-prova.tex}

I get an error...

I know that both problems can be resolved by defining my own command lie this:

\newcommand{\myinput}[2][input file]{%

but I was wondering if there is a way of doing it without changing the name of the \input command.


1 Answer 1


You don't want to modify the internal command, but the user level one.

\newcommand\red@input[2][input file]{%

This will ensure only \input commands after \begin{document} will cause embedding of the source. However, some package might use \input at runtime, and also these file will be embedded. Commands that directly use the internal command \@iinput will not cause embedding.

Also changing the syntax of a documented command is not the best approach, so I'd go with a new command:

\newcommand{\sourceinput}[2][input file]{%

and use \sourceinput for the files I really want to be embedded.

  • Thanks, I thought that packages input files only when loaded but if they can do it also at the runtime then I will use your second option
    – Red
    Commented Oct 10, 2013 at 12:37
  • \embedfile[desc={#1}]{#2} for the case that the description contains square brackets. Commented Oct 10, 2013 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .