5

I have a folder tree a little like this, "document.tex" is the root file, section1 is a folder

document.tex 
|--[section1]
|     |--index.tex

My document.tex code is like that:

\documentclass{article}

\usepackage{currfile}

\newcommand{\insertIndex}[2]
{% 
   \input{#1#2/index} 
}
\begin{document}

\insertIndex{\currfiledir}{section1}

\end{document}

The command throw a error because it say

section1/section1/index.tex" don't exist.

I try a lot and I don't understand why it duplicate the folder

If I view the string #1#2/index without the input the path is correct

Troncador
  • 153
  • 4
  • Welcome to TeX.SE. It would be very helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Feb 11 '14 at 00:09
  • Your code works just fine for me. I created the file section1/section1/index.tex, and it's content was properly displayed. Have you any spaces in your directory/file names? Also, what does index.tex look like (i.e., does it have a preamble?). – Peter Grill Feb 11 '14 at 02:25
  • the file I want to open is "section1/index.tex" but (I don't know why) he try to open "section1/section1/index.tex" it duplicate the word "section1". In the file index.tex I simply write "hello world" – Troncador Feb 11 '14 at 02:50
  • Opps, looked into it further and it is an expansion issue: So if you use \edef\CurrentFileDir{\currfiledir} \insertIndex{\CurrentFileDir}{section1} things work correctly. I am not very knowledgeable about expansion issues (just know enough to be dangerous :-)) so am hesitant to attempt to explain it. But that should get you going until a proper answer comes along. – Peter Grill Feb 11 '14 at 03:17
  • Also, you need to use \newcommand{\insertIndex}[2]{% (note the trailing %. See for instance Tex Capacity Exceeded (if remove % after use of macro). – Peter Grill Feb 11 '14 at 03:21
  • thanks! I work fine. You made my day =), I didn't know the "edef" command. Please submite your answer like a answer for approve it – Troncador Feb 11 '14 at 03:37
  • I can't reproduce your problem. – egreg Feb 11 '14 at 18:58

1 Answers1

2

This appears to be an expansion issue. So first expand \currfiledir before using it:

\edef\CurrentFileDir{\currfiledir} 
\insertIndex{\CurrentFileDir}{section1}

References:

Code:

\documentclass{article}

\usepackage{currfile}

\newcommand{\insertIndex}[2]{%
   \input{#1#2/index}%         <---- Note % here 
}
\begin{document}

\edef\CurrentFileDir{\currfiledir}%
\insertIndex{\CurrentFileDir}{section1}%

\end{document}
Peter Grill
  • 223,288