pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.12k stars 106 forks source link

\input@path is not honored by usetikzlibrary #1259

Open tobiasBora opened 1 year ago

tobiasBora commented 1 year ago

Brief outline of the bug

As far as I see, there is no way to add a folder to the search path of tikz. This becomes very annoying when importing a file in a subfolder that requires a custom tikz library, or when my custom libraries are not put at the root of my project.

More precisely, I have a structure like this (see below for exact content):

mycachedfiles/a.tex
myinput.tex
tikzlibrarymy.test.code.tex

I’d like to compile it using:

cd mycachedfiles
pdflatex a.tex

However, if myinput.tex contains \usetikzlibrary{my.test}, then I will get an error like:

! Package tikz Error: I did not find the tikz library 'my.test'. I looked for f
iles named tikzlibrarymy.test.code.tex and pgflibrarymy.test.code.tex, but neit
her could be found in the current texmf trees..

By default, LaTeX will try to search in folders listed in \input@path, so \input{tikzlibrarymy.test.code.tex} would work… unfortunately \usetikzlibrary gives an error without even trying to run the \input.

Minimal working example (MWE)

MWE

% a.tex:
\documentclass[]{article}
\makeatletter
% Works for \input{} but not for \usetikzlibrary
\def\input@path{{..}}
\makeatother

\input{../myinput.tex} % no more success with subimport

\begin{document}

\begin{tikzpicture}
  \node[my test style]{A};
\end{tikzpicture}

\end{document}
% myinput.tex
\usepackage{tikz}
\usetikzlibrary{my.test}
% tikzlibrarymy.test.code.tex:
\tikzset{
  my test style/.style={
    draw,
    circle,
    fill=red,
  }
}
muzimuzhi commented 1 year ago

Similar: #565

A more general question: In LaTeX format, should pgf's \pgfutil@IfFileExists respect \input@path as its LaTeX relative \IfFileExists does? This would affect the loading of library/module, .table files, and of course images.

Originally posted by @muzimuzhi in https://github.com/pgf-tikz/pgf/issues/980#issuecomment-761167615

hmenke commented 1 year ago

\input@path is a LaTeXism and not portable across format.

tobiasBora commented 1 year ago

Then wouldn't it be possible to define another variable for that? Or provide this functionality only for LaTeX?

muzimuzhi commented 1 year ago

Perhaps \pgfutil@IfFileExists can be extended to take a list of directories, for example \pgfinputpath, into consideration. Then in LaTeX format \pgfinputpath can be initialized to \input@path at some early stage in loading pgf or tikz package. In formats other than LaTeX \pgfinputpath can be defined by user before pgf or tikz is loaded.

Update: also \pgfutil@InputIfFileExists.