4

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.

  • 1
    I don't think you can use ../ in a \usepackage path. However, without a link, can't you put simply your preamble in the same folder as the standalone input, and use \usepackage{<standalone-subfile-folder>/package} in your main and simply \usepackage{package} in the standalone ? – marsupilam Aug 11 '17 at 20:08
  • 1
  • Here the same question was posed. The answer is that the latex-run for the figure is not allowed to create files in the parent folder. Solution would be to let the files be created in the figures directory. There supposedly is an build option for that, to which you can pass latex compiler options. However, currently I do not get it to work. – Heinrich Ody Aug 11 '17 at 20:35
  • @marsupilam Thanks for your comment. That works as long as all files using package are in the same folder. Also, it makes the file structure somewhat confusing. – Heinrich Ody Aug 11 '17 at 20:51
  • 1
    Agreed, that would certainly be sub-optimal (but that's because of the constraint of no links !). Maybe you could make a proxy preamble file in your main folder, simply containing \usepackage{subfolder/package} to hide a bit this unpleasant involvment. – marsupilam Aug 11 '17 at 20:59
  • 3
    You shouldn't have any path in the argument of \usepackage{} as I understand it. Whether above or below the current directory. You can add to TEXINPUTS to get TeX to look in an additional place, however. – cfr Aug 12 '17 at 12:52
  • 1
    @cfr but this is a shell variable, no ? (I guess it can also be passed to TeX during compilation.) But what if we want to do all this using plain LaTeX files without compilation flags or shell variables, for portability ? – marsupilam Aug 12 '17 at 18:52
  • @cfr Perhaps you are right, that I should not use a path in usepackage, but still it works. I mean, the file fig.tex figure with \usepackage{../foo} is compiled correctly. It does not work with nested compilation calls. Anyway, your suggestion with TEXINPUTS seems to work nicely. Thanks – Heinrich Ody Aug 12 '17 at 19:32
  • 2
    @HeinrichOdy My understanding is that it just happens to work and that this may be regarded as unfortunate. Hence, if it stops working, it will not be a bug as it is not designed to work in the first place. – cfr Aug 12 '17 at 22:42

1 Answers1

2

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