1

I'm about to share my LaTeX document and all its accessory files in such a way that it is self-contained and ready to compile. But I can't figure out how to refer to a sister folder from a .sty file.

I have the following .tex file in the mother directory:

\documentclass{article}
\usepackage{./testfolder/testpackage}
\begin{document}
Test
\end{document}

And a .sty file called testpackage.sty in a daughter folder:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{./testfolder/testpackage}
\usepackage{libertine}
\endinput

So far, so good. But now I need to load another package from testpackage.sty, and the package I need to load is located in the sister folder relative to the folder testpackage.sty is in. So I try this:

.tex file in the mother directory:

\documentclass{article}
\usepackage{./testfolder/testpackage}
\begin{document}
Test
\lipsum[1]
\end{document}

.sty file in daughter directory 1:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{./testfolder/testpackage}
\usepackage{libertine}
\usepackage{../testfolder2/testpackage2}
\endinput

.sty file in daughter directory 2 (sister directory of directory 1):

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{../testfolder2/testpackage2}
\usepackage{lipsum}
\endinput

Trying to compile my .tex file results in this error:

LaTeX Error: File `../testfolder2/testpackage2.sty' not found.

What am I doing wrong? According to LaTeX/Modular Documents, it should be possible to use ../ to specify sister directories.

(I know there are conventions for how to illustrate directory paths, but I couldn't find anything by googling, so I gave that up for this question).

  • 1
    You must give the path relativ to your main tex-file, not relative to the style, so probably you need \usepackage{testfolder2/testpackage2} – Ulrike Fischer Jun 19 '14 at 19:23
  • 1
    Don't do \usepackage{./testfolder/testpackage} it's a syntax error that will generate a warning if \ProvidesPackage is used in the package (as it should be) the argument to \usepackage is a name not a file path (even though the latter sort of half works) the relative paths are always relative to the main input document not to the file with the \input – David Carlisle Jun 19 '14 at 19:24
  • @DavidCarlisle I don't understand your comment, but I think we've been over this before here. I don't get any warnings. – Sverre Jun 19 '14 at 19:31
  • @Sverre I noticed afterwards you'd put the same path in the provides package which suppresses the warning, but it's still wrong:-) it should be \usepackage{testpackage2} – David Carlisle Jun 19 '14 at 19:43
  • 1
    Is this really the best way? Why not use bundledoc and the --include="file1.sty, file2.sty" so that bundledoc creates a new and shareable file that includes the important .sty files in it via the filecontents environment. This will (probably) be more portable across time, space, and different file directory structures. – jon Jun 20 '14 at 2:15
1

Based on Ulrike's comment, it should be like this:

.tex file in the mother directory:

\documentclass{article}
\usepackage{./testfolder/testpackage}
\begin{document}
Test
\lipsum[1]
\end{document}

.sty file in daughter directory 1:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{./testfolder/testpackage}
\usepackage{libertine}
\usepackage{testfolder2/testpackage2}
\endinput

.sty file in daughter directory 2:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{testfolder2/testpackage2}
\usepackage{lipsum}
\endinput
  • If you do this then the package can only be called from the parent directory, the package could never be installed in the normal tree and found via the tex path as the \usepackage name argument has to be literally {./testfolder/testpackage} to avoid a warning. – David Carlisle Jun 19 '14 at 19:50
  • @DavidCarlisle Are you saying that the .sty file in directory 1 should have \usepackage{testpackage2} and the .sty file in directory 2 should have \ProvidesPackage{testpackage2}? Please clarify. – Sverre Jun 19 '14 at 20:01
  • well the .sty in directory1 should have \RequirePackage{testpackage2} (although \RequirePackage and \usepackage are identical really, and the document should have \usepackage{testpackage} – David Carlisle Jun 19 '14 at 20:05
  • @DavidCarlisle But keeping \ProvidesPackage{testfolder2/testpackage2} in the .sty file in directory 2 is still correct? – Sverre Jun 19 '14 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.