添加 \usetikzlibrary 的搜索路径

添加 \usetikzlibrary 的搜索路径

我如何将文件夹添加到 tikz 的搜索路径?

更准确地说,我有一个这样的结构(具体内容见下文):

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

我想使用以下命令进行编译:

cd mycachedfiles
pdflatex a.tex

但是,如果myinput.tex包含\usetikzlibrary{my.test},那么我将收到如下错误:

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

我尝试玩\subimport\input@path…,但没有成功。有什么想法吗?

平均能量损失

% 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,
  }
}

答案1

一个粗暴的解决方法:插入

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

就在之前

\usetikzlibrary{my.test}

myinput.tex

或者,如果可以让所有本地 LaTeX 运行都看到它,则可以在 TDS 树的适当子目录中为路径(或其所在的目录)tikzlibrarymy.test.code.tex创建符号链接,例如tikzlibrarymy.test.code.texTEXMFHOMETEXMFLOCAL

$(kpsewhich --var-value TEXMFHOME)/tex/generic/pgf/frontendlayer/tikz/libraries
# or just
$(kpsewhich --var-value TEXMFHOME)/tex/generic/pgf

相关内容