帶有巨集的 \import 和 \includegraphics:在巨集定義時保留本機路徑

帶有巨集的 \import 和 \includegraphics:在巨集定義時保留本機路徑

我幾天來一直在研究這個問題,嘗試了\def\edef\noexpand\expandafter等的多種組合。

假設我有一個模組,/tmp/module/其中包含module.teximage.png。在module.tex我定義一個巨集中,除其他外,它用於\includegraphics通過相對路徑拉入此子模組中的圖像:

% module.tex
\newcommand{\myQuizHeader}[1]{
  Quiz #1
  \includegraphics[width=1.5in]{image.png}
}

然後從我的主文檔中執行\importor \subimport,然後嘗試使用\myQuizHeader巨集:

% main.tex
\documentclass[11pt,letterpaper]{article}
\usepackage{graphicx}
\usepackage{import}

\begin{document}
  \import{/tmp/module/}{module.tex}
  \myQuizHeader{27}
\end{document}

雖然 import 正確地在模組路徑前面新增了模組路徑,以便在 inside 中查找與模組相關的檔案和影像module.tex,但這些路徑在離開模組時會被刪除,因此在該模組中定義的巨集不再正常運作。當我\myQuizHeader{27}從主文件調用時,找不到圖像。

解決這個問題的正確方法是什麼?我嘗試將\Ginput@path變數保存到模組內的局部變數中,但後來我陷入了\edef困境\noexpand

非常感謝!

相關內容