# Using \newcommand and \input

I like to use variables for my paths, so that if I migrate to another system/username, I don't have to change every path name. This does not seem to be working with the input command. I have the following in my main.tex file:

\newcommand{\rootFolder}{/home/user/Documents/tex}
....
\input{\rootFolder/foo/bar.tex}


But I get the following error.

1 || ** \rootFolder/foo/bar.tex:
2 main.tex|86 error| Could not open "\rootFolder/foo/bar.tex"


My spider senses tell me it is not expanding \rootFolder. Can anyone tell me what I am doing wrong?

EDIT User Peter Grill asked me for a minimal working example (MWE) so here it is. Also, I should have mentioned that I am getting this error from inside Vim.

test.tex:

hello world


main.tex (local path):

\documentclass{article}
\begin{document}
\input{test.tex}
\end{document}

% Works Fine


main.tex (variable):

\newcommand{\rootFolder}{/home/user/Documents}

\documentclass{article}
\begin{document}
\input{\rootFolder/test.tex}
\end{document}

% Vim Error:
% 1 || ** \rootFolder/test.tex:
% 2 main.tex|5 error| Could not open "\rootFolder/test.tex"


main.tex (edef):

\newcommand{\rootFolder}{/home/user/Documents}

\documentclass{article}
\begin{document}
\edef\ExpandedFileName{\rootFolder/test.tex}\input{\ExpandedFileName}
\end{document}

% Vim Error:
% 1 || ** \ExpandedFileName:
% 2 main.tex|5 error| Could not open "\ExpandedFileName"


main.tex (no edef):

\newcommand{\rootFolder}{/home/user/Documents}

\documentclass{article}
\begin{document}
\ExpandedFileName{\rootFolder/test.tex}\input{\ExpandedFileName}
\end{document}

% Vim Error:
% 1 || ** \ExpandedFileName:
% 2 main.tex|5 error| Could not open "\ExpandedFileName"
% pdflatex Error:
% Undefined control sequence.
% l.5     \ExpandedFileName{\rootFolder/test.tex}\input{\ExpandedFileN...


main.tex (expandafter):

\newcommand{\rootFolder}{/home/user/Documents}

\documentclass{article}
\begin{document}
\expandafter\input\expandafter{\rootFolder/test.tex}
\end{document}

% Vim Error:
% 1 test.tex|5 error| Don't use "\expandafter" in LaTeX documents

-
The usual way of trying to fix that is \edef\ExpandedFileName{\rootFolder/foo.tex} \input{\ExpandedFileName}, but this does not appear to be the case as the error message I get is LaTeX Error: File /home/user/Documents/tex/foo.tex not found -- identical message if I use the \edef or not. –  Peter Grill Feb 8 '12 at 4:51
There probably is something else going on, so perhaps you should compose a fully compilable MWE that reproduces this error message including the \documentclass and the appropriate packages. –  Peter Grill Feb 8 '12 at 5:09
@Peter: without \expandafter\input\expandafter{\ExpandedFileName}, you'd run into the same issue as before anyway, wouldn't you? –  Ulrich Schwarz Feb 8 '12 at 6:08
@PeterGrill just added the MWEs –  puk Feb 8 '12 at 7:04
Using a command in this way should principally work. If the file is nevertheless not found then either the path is wrong or the security settings in your texmf.cnf (openin_any) doesn't allow absolute pathes. –  Ulrike Fischer Feb 8 '12 at 9:05