7

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):

\documentclass{article}
\usepackage{embedfile}
\usepackage{pgfplots}
\usepackage{letltxmacro}

\makeatletter
\LetLtxMacro\latex@iinput\@iinput
\renewcommand{\@iinput}[1]{%
    \latex@iinput{#1}%
    \embedfile[desc=input file]{#1}%
}
\makeatother

\begin{document}
    \input{input-prova.tex}
    \begin{tikzpicture}
        \begin{axis}
            \addplot {x};
        \end{axis}
    \end{tikzpicture}
\end{document}

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:

\makeatletter
\LetLtxMacro\latex@iinput\@iinput
\renewcommand{\@iinput}[2][input file]{%
    \latex@iinput{#2}%
    \embedfile[desc=#1]{#2}%
}
\makeatother

\begin{document}
    \input[file description]{input-prova.tex}
\end{docmuent}

I get an error...

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

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

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

0

1 Answer 1

7

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

\makeatletter
\let\latex@input\input
\newcommand\red@input[2][input file]{%
  \embedfile[desc={#1}]{#2}\latex@input{#2}%
}
\AtBeginDocument{\let\input\red@input}
\makeatother

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]{%
  \embedfile[desc={#1}]{#2}\input{#2}%
}

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

2
  • 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 .