0

The following question is closely related to this one but represents a scenario much closer to my real life use case, in which descendants reference their ancestors, rather than vice versa, and the main file is one of the leaves rather than the root of the file tree.


I have set up the following file tree. (It's similar to the one described in my other post, with the addition of the Sibling branch.)

. [D] (working directory)
Test.tex [F]
   SubFolder [D]
      SubTest.tex [F]
      SubSubFolder [D]
         SubSubTest.tex [F]
   SiblingFolder [D]
      SiblingTest.tex [F]

To give real-life context to this file structure: The working directory is a container for all the courses I take this academic year. Each subfolder is a container for a different course. Each subsubfolder is a container for a different homework assignment or project in the associated course. And the sibling folders are for fonts, graphics, bibliographies, and other files I wish to make available universally. When I compile a homework problem, I do so from the homework problem's directory, not from the root of the file tree.

Back to the current problem. I would like to be able to navigate the file tree from one level to the other starting from SubSubTest.tex. The desired display of the PDF file to be produced by pdflatex SubSubTest should be:

[../../]
[../]
[]
[../../SiblingFolder/]

An Attempt

  • SubSubTest.tex

    \documentclass{article}
    \usepackage{import}
    \import{..}{SubTest}
    \newcommand{\SubSubDir}{\hspace{0pt}}
    \begin{document}
    [\Dir]\par
    [\SubDir]\par
    [\SubSubDir]\par
    [\SiblingDir]
    \end{document}
    
  • SubTest.tex

    \usepackage{import}
    \import{..}{Test}
    \newcommand{\SubDir}{../}
    
  • Test.tex

    \import{SiblingFolder}{SiblingTest}
    \newcommand{\Dir}{../../}
    
  • SiblingTest.tex

    \newcommand{\SiblingDir}{../../SiblingFolder/}
    

Executing

> cd ~/SubFolder/SubSubFolder
> pdflatex SubSubFolder

resulted in a compilation failure with the following error message.

! LaTeX Error: File `SiblingFolder/SiblingTest.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.1 \import{SiblingFolder}{SiblingTest}
                                       ^^M
End of file on the terminal!

How can this issue be fixed?

6
  • 1
    Maybe you need to use \subimport instead of \import? Though I didn't read the documentation to see what's the difference between the 2
    – user202729
    Nov 22, 2022 at 9:43
  • You could just use \input{SubSubTest} or \input{SiblingTest} from any file if you had arranged TEXINPUTS=/path/workingdir//: so all files in that tree are found Nov 22, 2022 at 10:20
  • @DavidCarlisle This solution is inadequate. It assumes I know in advance the names of all the files in the tree hierarchy and that there are no duplicate names nor will there every be such.
    – Evan Aad
    Nov 22, 2022 at 10:31
  • well it assumes no duplicates, but nothing else. If texlive can ensure no duplicates amongst its thousands of files, it's not much to ask that there be no duplicates in a single document, and even if there are duplicates you can distinguish them (from anywhere) as \input{dir1/file} and \input{dir2/file}. But no matter, I'm sure someone will post something closer to what you ask for. Nov 22, 2022 at 10:41
  • @user202729 Thank you! This solved it, as well as the double forward slash problem mentioned in my other post, which I'm going to amend. You're so clever! Why didn't you post answers?
    – Evan Aad
    Nov 22, 2022 at 10:48

1 Answer 1

0

The solution is to replace all occurrences of the \import command by \subimport.

The idea is due to user202729's comment to my original post.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .