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
  • 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
  • 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
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

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.