lbeckman314 / mdbook-latex

An mdbook backend for generating LaTeX and PDF documents.
https://liambeckman.com/code/mdbook-latex/
Mozilla Public License 2.0
104 stars 11 forks source link

Incorrect reference to images from nested directory #5

Closed yatesco closed 4 years ago

yatesco commented 4 years ago

Hi there - this might be an issue upstream!

I have the following structure:

src
src\chapter-1
src\chapter-1\a.png
src\chapter-1\chapter.md

and in src\chapter-1\chapter.md\chapter.md I include a relative link to a.png.

mdbook build works fine and the generated HTML correctly links the images, however, when the generated markdown from this project doesn't take the fact they are relative (to chapter-1) into account, nor does it copy the images to the book directory, resulting in the generated markdown containing a.png instead of chapter-1\a.png.

Same problem for the generated latex, resulting in errors because it can't find the images.

Help :-)

lbeckman314 commented 4 years ago

Thank you for raising this issue! I will take a look at the code responsible for image handling (1) and see where it's missing this case.

(1) https://github.com/lbeckman314/md2tex/blob/master/src/lib.rs#L258-L288

yatesco commented 4 years ago

Hey - my pleasure! Let me know if I can help with a reproducible repo for example.

lbeckman314 commented 4 years ago

Thank you for your patience — I'm still working on this issue will provide updates in the days ahead.

enaut commented 4 years ago

I have this problem too... did you continue this? I think it might be good to copy the images to the bookdirectory and reference them. The same as the html renderer does. That way you would get an independent latex file that you can take and improve or render with external renderers.

enaut commented 4 years ago

I think the reason for the failing images is here:

https://github.com/lbeckman314/mdbook-latex/blob/478035406ebb402af3781eb1793a638c7299fabd/src/main.rs#L164

You replace in content and write to new_content. Meaning any subsequent image removes the previous modification. So correctly this line should read:

new_content = new_content.replace(&path.into_string(), &new_path);

I went ahead and implemented my suggestion from above and copied over the images into the book directory unfortunately this requires changes in both md2tex and here. Pullrequests incomming.