是否可以为 \input{...} 全局设置类似于 \graphicspath{...} 的默认路径?

是否可以为 \input{...} 全局设置类似于 \graphicspath{...} 的默认路径?

对于graphicx包,我们可以使用,\graphicspath{...}这样我们就可以在的参数中直接使用文件名\includegraphics{...}。是否可以在中直接使用文件名做类似的事情\input{...}。我知道提到的方法这里但如果这是实现方法,那么它为什么\graphicspath{...}存在呢?

答案1

\graphicspath来自 LaTeX 的\input@path,仅使用图形文件的路径。 \input@path可以单独设置,例如:

\makeatletter
\def\input@path{{path1/}{path2/}}
\makeatother

如果包通过 查找文件,则在内部graphics将其路径存储\graphicspath在 中\Ginput@path,并在本地设置\input@path为。\Ginput@path\IfFileExists

除了\input@path

\input@path可以是未定义的(通常是 LaTeX 中的默认设置),也可以是已经包含其他路径条目。因此,在下面的代码中,首先为未定义\providecommand的情况定义宏。然后扩展 的定义。\input@path\g@addto@macro\input@path

\makeatletter
\providecommand*{\input@path}{}
\g@addto@macro\input@path{{path1/}{path2/}}% append
\makeatother

\edef可以使用,它扩展了定义文本。下一个示例使用它来将内容添加到\input@path的旧含义中\input@path

\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{path1/}{path2/}\input@path}% prepend
\makeatother

答案2

您可以尝试以下操作:

\graphicspath{{figures/}{logs/}}

必须有两个项目,如数字和日志。此外,/项目后面必须有。

尝试一下!

相关内容