Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX reader: filename without extension in \includegraphics #4933

Closed
bbc2 opened this issue Sep 25, 2018 · 5 comments
Closed

LaTeX reader: filename without extension in \includegraphics #4933

bbc2 opened this issue Sep 25, 2018 · 5 comments

Comments

@bbc2
Copy link

bbc2 commented Sep 25, 2018

The following foo.tex compiles with pdflatex but not pandoc:

\documentclass{article}
\usepackage{graphicx}
\title{Foo}
\begin{document}
\includegraphics{bar}
\end{document}

Directory layout:

.
├── bar.png
└── foo.tex

Pandoc command:

> pandoc --self-contained foo.tex --output foo.html
File bar not found in resource path

Expected result: no error.

Without --self-contained, the output is also unexpected (missing .png extension):

<p><img src="bar" alt="image" /></p>

Version:

> pandoc --version
pandoc 2.2.3.2
Compiled with pandoc-types 1.17.5.1, texmath 0.11.1, skylighting 0.7.3
Default user data directory: /home/bertrand/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

@jgm
Copy link
Owner

jgm commented Sep 25, 2018 via email

@bbc2
Copy link
Author

bbc2 commented Sep 25, 2018

I just had a look at the manual available at https://ctan.org/pkg/graphicx but it doesn't say anything about default extensions. However, it mentions pdftex.def which is defined in the graphics-def package. In that file, I found https://github.com/latex3/graphics-def/blob/dc7e8133c0410bb8836e43f99b78274ad7fc24aa/pdftex.def#L522-L525:

\def\Gin@extensions{%
  .pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,%
  .PDF,.PNG,.JPG,.JPEG,.JBIG2,.JB2%
}

If both .png and .PNG are removed from the list, then pdflatex can't find bar.png in my earlier example, which seems to confirm the purpose of that definition. A quick strace shows that those extensions are tried in the same order as listed.

(For some reason, if only .png is removed, then a .png still works. After failing to open bar.PDF and bar.PNG, it tried bar.png anyway.)

The manual also describes options and commands that can modify what extensions are tried:

  • The \DeclareGraphicsExtensions command adds extension candidates.
  • The \DeclareGraphicsRule command changes how some file extensions are handled, which can involve executing a shell command.
  • The type, ext, read and command options of the \includegraphics command have the same meaning as in DeclareGraphicsRule.

I suppose that emulating all those commands would be too much, but just maybe supporting the default extensions and perhaps even \DeclareGraphicsExtensions would be nice?

@eilers
Copy link

eilers commented Jul 20, 2019

I think it would be good enough if pandoc provides a command line parameter that sets the fallback extension if it is missing in the filename. I think in most cases that should solve the issue.

@jgm
Copy link
Owner

jgm commented Jul 20, 2019

@eilers You mean, like --default-image-extension? (See the manual)

@jgm
Copy link
Owner

jgm commented Jul 20, 2019

It should be possible to modify the LaTeX reader to check existence for files, when the filename has no extension, using this order:
.pdf .png .jpg .mps .jpeg .jbig2 .jb2 (and their capitalized variants)
If a match is found, we could store the filename + the found extension in the Image element.

@jgm jgm closed this as completed in 465eeec Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants