I have set up the following file tree.
. [D] (working directory)
Test.tex [F]
SubFolder [D]
SubTest.tex [F]
SubSubFolder [D]
SubSubTest.tex [F]
I would like each file to print its path relative to the working directory, so that the PDF file produced by pdflatex Test
will display:
[]
[SubFolder/]
[SubFolder/SubSubFolder/]
First Attempt
Using the currfile
package.
Test.tex
\documentclass{article} \usepackage{currfile} \input{SubFolder/SubTest} \newcommand{\Dir}{\currfiledir} \begin{document} [\Dir]\par [\SubDir]\par [\SubSubDir] \end{document}
SubTest.tex
\usepackage{currfile} \input{SubSubFolder/SubSubTest} \newcommand{\SubDir}{\currfiledir}
SubSubTest.tex
\usepackage{currfile} \newcommand{\SubSubDir}{\currfiledir}
This did not yield the desired result. The compilation failed with the following error message:
! LaTeX Error: File `SubSubFolder/SubSubTest.tex' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)
Enter file name:
! Emergency stop.
<read *>
l.2 \input{SubSubFolder/SubSubTest}
^^M
End of file on the terminal!
Second Attempt
Adding the import
package. (The idea was inspired by this answer.)
Test.tex
\documentclass{article} \usepackage{currfile} \usepackage{import} \import{SubFolder}{SubTest} \newcommand{\Dir}{\currfiledir} \begin{document} [\Dir]\par [\SubDir]\par [\SubSubDir] \end{document}
SubTest.tex
\usepackage{currfile} \usepackage{import} \import{SubSubFolder}{SubSubTest} \newcommand{\SubDir}{\currfiledir}
SubSubTest.tex
as before.
This time the compilation completed successfully, but the resulting PDF file displayed differently than desired, namely:
[]
[]
[]
Testing the import package on its own
For comparison, by doing away with the currfile
package as in the following code, the compilation completed successfully, and the desired outcome was achieved. However, this did not really solve the problem, since the paths were now hard-coded rather than inferred automatically. However, it demonstrated that the import
package was capable of navigating the file tree correctly.
Test.tex
\documentclass{article} \usepackage{import} \import{SubFolder}{SubTest} \newcommand{\Dir}{\hspace{0pt}} \begin{document} [\Dir]\par [\SubDir]\par [\SubSubDir] \end{document}
SubTest.tex
\usepackage{import} \import{SubSubFolder}{SubSubTest} \newcommand{\SubDir}{SubFolder/}
SubSubTest.tex
\newcommand{\SubSubDir}{SubFolder/SubSubFolder/}
import
package before use it, the syntax is not identical to\input
.\newcommand
won't work as expected, you can\let\SubDir\currdirname
; that having said\let
is a primitive TeX command so you might want to start reading TeXbook to know what it does exactlyimport
package's documentation, but it didn't resolve the problem.\let
.