[Tex/LaTex] Standalone with package in parent directory

standalone

I have three files, the files main.tex and package.sty located in the same folder and a standalone file fig.tex located in a subfolder sub, using a command from package.sty. The problem is that standalone says it cannot build fig.pdf. I use standalone v1.1b. I give the option --shell-escape.

  • Am I doing something wrong?
  • If not, is there a way to still use the
    buildnew option, with a setup where a standalone-file in a
    subdirectory uses a file in a parent-directory?

The file main.tex

\documentclass{article}
\usepackage[mode=buildnew]{standalone}
\usepackage{tikz,package}
\begin{document}
    \includestandalone{sub/fig}
\end{document}

The file package.sty

\newcommand{\foo}{b}

The file test.tex

\documentclass[tikz]{standalone}
\usepackage{../package}
\begin{document}
\begin{tikzpicture} 
    \node {$\foo$};
\end{tikzpicture}
\end{document}

Edit: One option seems to be to place a symbolic link to the package in the subfolder and then use the link. But this is not platform independent, and makes compilation more involved.

Best Answer

The following approach seems natural in latex and also works on a per project way, i.e. when each project requires different packages or is in a different repository.

  • Create a directory structure texmf/tex/latex/ directory
  • Let the environment variable TEXMFHOME point to texmf, e.g. via export TEXMFHOME=<path-to-the-new-texmf-dir>. This puts texmf into the compilers search path. The subdirectories tex/latex are needed because the compiler expects files with different file endings in different places
  • Move package.sty to texmf/tex/latex/
  • Now, you can use \usepackage{package} in sub/fig.tex and in main.tex and the file is found
Related Question