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

Provide a way to specify multiple base path for finding images, like TEXINPUT #852

Closed
bwl21 opened this issue May 10, 2013 · 17 comments
Closed

Comments

@bwl21
Copy link

bwl21 commented May 10, 2013

I get a pandoc message

pandoc: Could not find image `floating-image.pdf', skipping...

Would it be possible to make it a bit more expressive such as

pandoc: Could not find image `floating-image.pdf`, skipping ... 
               in "mytestfile.md line 1234, producing docx output

I was calling pandoc with multiple output formats, the problem only occurs while generating docx. The image file exists, but as it is a pdf, I guess pandoc cannot process it. If this is the case, pandoc should express that fact.

Pandoc could use ghostscript to convert it to a proper format, but that's another story (or another request:-)

@bwl21
Copy link
Author

bwl21 commented May 10, 2013

comment by jgm

Pandoc could use ghostscript to convert it to a proper format, but that's another story (or another request:-)
Pandoc tries not to rely on shelling out to external scripts. I've even coded zip file encoding in Haskell. This makes pandoc much more portable.

Agree, but pandoc alrady relies on TeX which also brings a ghostcript. But as said, this would be another issue.

An alternative would be that pandoc at least implements an optimization such that it looks if more appropriate graphic files exist.

e.g for [foo](./graphics/foo.pdf) it looks for graphics/foo.jpg, graphics/foo.svg as well and explicitly complains if no approriate file can be found.

Then it is in the responsibility of the document author to provide an appropirate format. In this case I would organize this by wortsammler.

@bwl21
Copy link
Author

bwl21 commented May 10, 2013

BTW one more thing in the same context:

as of now the graphics is included relative to the current working directory. This sometimes causes trouble. Would it be possible to specify an option --graphics-base-dir to make that process a bit more reliable.

@jgm
Copy link
Owner

jgm commented Jul 4, 2013

I am not sure why you'd get the error you're seeing if the file exists. Probably it isn't in the right directory (pandoc will look in the directory of the first file specified on the command line). (I'm sorry, but we can't provide line number information here, as this message is emitted by the docx writer, and the pandoc AST does not store source positions.)

In any case, I don't have enough to go on to reproduce the problem.

@bwl21
Copy link
Author

bwl21 commented Jul 4, 2013

Oh, is that really true, that pandoc looks for the graphics relative to the directory of the first file specified in the commandline. I thought it looks relative to the current working directory.

I will try to provide a test case that can reproduce the problem.

@bwl21
Copy link
Author

bwl21 commented Jul 4, 2013

I made some tests. It appears to me that this behavior is there only in case of docx output. In case of LaTeX/Pdf it is relative to the current working directory. This is somehow inconsistent ;-(

So in order to make it more robust, I hereby repeat my proposal to have --graphic-base path;path;path similar to TEXINPUTS.

I know that the command line gets longer and longer ...
Maybe some day it makes sense to allow that commandline-options are read from a configuration file which is passed in the commandline.

@db78
Copy link

db78 commented Jul 11, 2013

Hi bwl21,

were you able to figure out this issue?
I am having issue outputing image from .tex to .docx.

thanks,
db78

@mpickering mpickering added the bug label Dec 7, 2014
@JJ
Copy link

JJ commented Jan 4, 2015

Same error here when working from Markdown to epub

@jgm jgm changed the title Pandoc' messages should be a bit more expressive Provide a way to specify multiple base path for finding images, like TEXINPUT Feb 22, 2017
@jgm jgm added this to the pandoc 2.0 milestone Feb 26, 2017
@jgm
Copy link
Owner

jgm commented Feb 26, 2017

Now that we have a representation of resource path in CommonState, it will be easy to add an option like this.

@jgm
Copy link
Owner

jgm commented Feb 27, 2017

Option could be called --graphics-path, -I, --resource-path?
And we need a convention for breaking it into parts: colon, semicolon, multiple options?

@JJ
Copy link

JJ commented Feb 27, 2017 via email

@bwl21
Copy link
Author

bwl21 commented Feb 27, 2017

@jgm

Interesting question, if we have a graphics-path or a resource-path. Original request was for a graphics path, but is no problem to extend it to other resources (if there are such).

@JJ yes, in unix-land; in windows, the like ":".

AFAIK MikTeX accepts C:/foo/bar;X:/bar/foo; as a valid path. So I would support ";"

@jgm jgm added enhancement and removed bug labels Mar 5, 2017
@SamuelePilleri
Copy link

I was about to open an issue on this very same problem.

I managed to hack-in this feature (LaTeX only) this way; the graphics: true forces the $graphics variable in LaTeX default template to be set to true, otherwise, if no image is included, \usepackage{graphicx} is not executed and that command in header-includes is invalid.

Directory structure:

 +--- sources
      |
      +--- images
      |    |
      |    +--- photo.jpg
      |
      +--- document.md

Markdown source:

---
graphics: true
header-includes:
- \graphicspath{{./images/}}
---

![Image](photo.jpg)

Pandoc does produce an error, but the output is correct:

pandoc: Could not find image `photo.jpg', skipping...

Since this feature is quite similar to --default-image-extension, I think that could be managed in the same way (or just by appending random strings around).

Thanks to all devs and contributors for their excellent work.

@jgm
Copy link
Owner

jgm commented Mar 27, 2017

Perhaps the directory of the first input file should be added automatically to the resource path.

@SamuelePilleri
Copy link

SamuelePilleri commented Mar 27, 2017 via email

jgm added a commit that referenced this issue May 20, 2017
SEARCHPATH is separated by the usual character,
depending on OS (: on unix, ; on windows).

Note: This does not yet work for PDF output, because the
routine that creates PDFs runs outside PandocMonad.
(This has to do with its use of inTemporaryDirectory and
its interaction with our exceptions.)

The best solution would be to figure out how to move the
PDF creation routines into PandocMonad.  Second-best,
just pass an extra parameter in?

See #852.
@jgm
Copy link
Owner

jgm commented May 20, 2017

TODO:

  • Make this work with PDF output. (If I recall, the issue here is withSystemTempDirectory, withTempFile, withTempDirectory, which require a monad that is an instance of MonadMask. There was some issue, I think, making PandocMonad instances instances of MonadMask.)
  • Automatically set the path, if the option is not specified, to include the path of the first input file. (And document that.)
  • Currently the working directory is always added to the resource path. Should it be? We could require that it be explicitly specified in the resource path if --resource-path is used; this would free up authors to prefer images from another directory.

@jgm
Copy link
Owner

jgm commented May 21, 2017

Closed by 8c1b81b

@antecede
Copy link

antecede commented Oct 6, 2020

It is highly recommended that the PDF format of the picture prompt message alone some obvious!!
Instead of telling you that you can't find the file, it's better to automatically convert the PDF to JPG or PNG later.
At the same time \subfloat, this seed image skips directly without any hint and doesn't seem to find the corresponding PDF

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

7 participants