最小运行示例

最小运行示例

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、.PNG 等。然而,model.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)

相关内容