Accessing template from subfolder raises problems on relative paths

I would like to use the following folder structure for my project:

/template
template.tex
template.sty
/doc1
doc1.tex
/doc2
doc2.tex


The doc documents are supposed to access the template that defines part of the preamble. So, doc looks like

\input{../template/template.tex}
\begin{document}
...
\end{document}


and template.tex looks as follows:

\documentclass[12pt]{scrartcl}
\usepackage{template}
\usepackage{...}


However, this does not work, because template.sty is not found, which seems to be a problem of relative/absolute paths. Is there a nice solution to this problem?

Search path at TeX macro level

The macro \input@path can contain additional search paths:

\makeatletter
\providecommand*{\input@path}{}
\makeatother
\input{template.tex}
% ...
\begin{document}
...
\end{document}


Environment variables

Another way is setting the environment variable TEXINPUTS to add the path ../template to the search path for TeX input files, e.g. for TeX Live/Linux/bash:

export TEXINPUTS=:../template


Also an absolute path could be used instead of the relative path. The colon at the begin (probably semicolon in Windows) says that first the configured paths without TEXINPUTS are searched, then TeX looks into ../template.

TEXMFHOME

Also the template files could be installed in the home TEXMF tree, example for TeX Live/Linux:

~/texmf/tex/latex/template/template.tex
~/texmf/tex/latex/template/template.sty