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
\edef\ExpandedFileName{\rootFolder/foo.tex} \input{\ExpandedFileName}, but this does not appear to be the case as the error message I get isLaTeX Error: File /home/user/Documents/tex/foo.tex not found-- identical message if I use the\edefor not. – Peter Grill Feb 8 '12 at 4:51\documentclassand the appropriate packages. – Peter Grill Feb 8 '12 at 5:09\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