import
在處理大型 tex 專案時,我發現了一個奇怪的包問題。
最小運行範例
我使用的是 Linux Mint 21.3 和 texlive 2021.20220204-1。
這是我的資料夾結構。
/
+- main.tex
|
+- model.png
|
+- dir/
+- model.tex
其main.tex
內容有:
\documentclass{article}
\usepackage{graphicx}
\usepackage{import}
\begin{document}
\import{dir}{model}
\end{document}
其dir/model.tex
內容有:
\includegraphics{model}
model.png
只是一個圖像檔。
編譯時pdflatex main.tex
,我遇到了以下錯誤:
! LaTeX Error: File `model' not found.
我的初步調查
根據我的理解,includegraphics
應該在某些列表中搜尋帶有擴展名的圖像文件,例如 .pdf、.PDF、.png、.PNGmodel.png
等。不起作用。\graphicspath{{.}}
main.tex
如果我改為\import{dir}{model}
,main.tex
則\input{dir/model}
可以正確找到圖像。 (但這並不好。)
如果我改為\includegraphics{model}
,model.tex
則\includegraphics{model.png}
可以正確找到圖像。 (這也不好。)
如果我移入model.png
資料夾dir
,則可以正確找到圖像。 (這也不好。)
如果我重命名dir/model.tex
為不同的檔案名,例如,,dir/model123.tex
那麼也可以正確找到圖像。 (這也不好。)
這是比較奇怪的。看來我們在使用套件時最好不要使用相同的tex檔案名稱和圖像檔案名import
,然而,這只會讓人不方便。
完整的日誌
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex 2024.3.19) 23 APR 2024 15:34
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**main.tex
(./main.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-01-21>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
)
\c@part=\count185
\c@section=\count186
\c@subsection=\count187
\c@subsubsection=\count188
\c@paragraph=\count189
\c@subparagraph=\count190
\c@figure=\count191
\c@table=\count192
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks16
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2021/03/04 v1.4d Standard LaTeX Graphics (DPC,SPQR)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 2021/08/11 v1.11 sin cos tan (DPC)
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 107.
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def
File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex
))
\Gin@req@height=\dimen139
\Gin@req@width=\dimen140
)
(/usr/share/texlive/texmf-dist/tex/latex/import/import.sty
Package: import 2020/04/01 v 6.2
)
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def
File: l3backend-pdftex.def 2022-01-12 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count193
\l__pdf_internal_box=\box50
)
No file main.aux.
\openout1 = `main.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 7.
LaTeX Font Info: ... okay on input line 7.
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count194
\scratchdimen=\dimen141
\scratchbox=\box51
\nofMPsegments=\count195
\nofMParguments=\count196
\everyMPshowfont=\toks17
\MPscratchCnt=\count197
\MPscratchDim=\dimen142
\MPnumerator=\count198
\makeMPintoPDFobject=\count199
\everyMPtoPDFconversion=\toks18
) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
85.
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
(./dir/model.tex
! LaTeX Error: File `model' not found.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.2 \includegraphics[width=.5\linewidth]{model}
?
) [1
{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./main.aux) )
Here is how much of TeX's memory you used:
1337 strings out of 479654
21973 string characters out of 5883416
305473 words of memory out of 5000000
19466 multiletter control sequences out of 15000+600000
469259 words of font info for 28 fonts, out of 8000000 for 9000
309 hyphenation exceptions out of 8191
55i,5n,62p,200b,107s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/share/
texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on main.pdf (1 page, 9020 bytes).
PDF statistics:
13 PDF objects out of 1000 (max. 8388607)
7 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)