0

How could I add a folder to the search path of tikz?

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

I tried to play with \subimport, \input@path… without success. Any idea?

MWE

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

% Not working: % \input{../myinput.tex} % Not better: \usepackage{import}% \subimport{../}{myinput.tex}%

\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,
  }
}
tobiasBora
  • 8,684
  • 1
    A few complicated things in play here. \input@path affects \input but not \@@input, try TEXINPUTS. (that having said I believe there hasn't been something that explains what's the difference between the 2 above and e.g. \l_file_search_path_seq, graphicpath etc.) – user202729 May 09 '23 at 14:18
  • @user202729 thanks, but can’t I find a generic solution working without touching environment variables? (they are not easy to change in my setting) – tobiasBora May 09 '23 at 14:50
  • Probably need to patch TikZ code then. – user202729 May 09 '23 at 15:10
  • 1
    Maybe you can work around the problem by placing a symlink to tikzlibrarymy.test.code.tex in your cached folder? – samcarter_is_at_topanswers.xyz May 09 '23 at 20:35
  • @samcarter_is_at_topanswers.xyz yeah, I guess it’s a solution, but I don’t find it very elegant. For instance I can’t copy the code on a usb stick as fat16 does not handle symlinks… – tobiasBora May 09 '23 at 20:55
  • 2
    I'd say almost everything is more elegant than patching TikZ code. For FAT16 you can replace the symlink idea with a file with content of a single line \input{correct/path/to/file} – user202729 May 10 '23 at 02:13
  • This trick is nice. I would not want to patch TikZ myself, true. But I’d love to see TikZ patch its own code ^^ I submitted an issue in https://github.com/pgf-tikz/pgf/issues/1259 – tobiasBora May 10 '23 at 08:23

1 Answers1

2

One brute workaround: insert

\makeatletter
\let\pgfutil@IfFileExists     =\IfFileExists
\let\pgfutil@InputIfFileExists=\InputIfFileExists
\makeatother

just before

\usetikzlibrary{my.test}

in myinput.tex.

Or if its OK to make tikzlibrarymy.test.code.tex seen by all your local LaTeX runs, you can create symlink(s) for path to tikzlibrarymy.test.code.tex (or the directory it lives in) in proper subdirectory of TDS tree TEXMFHOME or TEXMFLOCAL, for example

$(kpsewhich --var-value TEXMFHOME)/tex/generic/pgf/frontendlayer/tikz/libraries
# or just
$(kpsewhich --var-value TEXMFHOME)/tex/generic/pgf
muzimuzhi Z
  • 26,474
  • Thanks a lot. But it seems like if I do so, if there exists a library with the same name installed system-wide, then the one specified in \input@path will not have priority (unledd I missed something)… is it possible to say that the \input@path should have priority? – tobiasBora Jul 09 '23 at 15:20
  • Thought possible, I don't think that's the right way to go. Current behavior is the one \IfFileExists and \InputIfFileExists from LaTeX use, for example the system-wide tikz.sty has priority than any modified tikz.sty in any of the paths in \input@path. I suggest to use another library name. You can load the system-wide "version" with \usetikzlibraray and then put your own modifications in your library source file. – muzimuzhi Z Jul 09 '23 at 16:12
  • Oh, is it possible? https://tex.stackexchange.com/questions/439906/inputpath-and-load-path-priority suggests that it’s not (unless playing with environment variables… heck) Also, having a separate name is not extremely practical as the library (for this second usecase) is in a submodule, and it would be a nightmare to synchronize them. Guess I will use for this usecase \input even if it’s not extremely clean. – tobiasBora Jul 09 '23 at 16:21
  • 1
    By providing a modified pair of \pgfutil@IfFileExists and \pgfutil@InputIfFileExists with path priority modified, I guess it's possible. – muzimuzhi Z Jul 09 '23 at 16:38
  • Oh I see, make sense, thanks. – tobiasBora Jul 09 '23 at 18:05