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

subfigure images in docx does not rescale #394

Closed
ayhy opened this issue Jul 31, 2023 · 4 comments
Closed

subfigure images in docx does not rescale #394

ayhy opened this issue Jul 31, 2023 · 4 comments

Comments

@ayhy
Copy link

ayhy commented Jul 31, 2023

with subfigGrid=true, following code in html creates auto-rescales image table.

<div id="fig:coolFig"  class="subfigures">
![sample](./Images/ch1/sample.png){#fig:cfquatSample width=25%}
![star](./Images/star.svg){#fig:cfquatStar width=25%}
![star](./Images/star.svg){#fig:cfquatBlueStar width=25%}
![profcat](./Images/Professortocat.png){#fig:cfquatProf width=25%}

![bluestar2](./Images/bluestar.svg){#fig:cfbs}
![profcat2](./Images/Professortocat.png){#fig:cfpc}
![bluestar3](./Images/bluestar.svg){#fig:cfbs2}
![profcat4](./Images/Professortocat.png){#fig:cfpc2}

SVG, pngfiles 25% specified in its row.
</div>

image

However on docx output images retain original size.
image

Is there a way to fit image for docx table cell?
Regular width specification determines col width and I could not find a way to manually rescale image.

@lierdakil
Copy link
Owner

Hi. Thanks for the report.

Apparently, Pandoc interprets image widths in docx relative to the page width, regardless of context since 3.0. Well, there is a relatively simple fix for this (hopefully, IIUC what's going on), but I don't have the mental bandwidth to implement it at the moment. Please ping me if I don't get around to it by the end of this week. If you want to make a PR, that'd be even better, I think all that needs to be done is this code here

inlToCell :: Inline -> Maybe Block
inlToCell (Image (id', cs, as) txt tgt) = Just $
Figure (id', cs, []) (Caption Nothing [Para txt]) [Plain [Image ("", cs, setW as) txt tgt]]
inlToCell _ = Nothing
setW as = ("width", "100%"):filter ((/="width") . fst) as

needs to set image width to column width instead of 100% when output format is docx. Column widths are in widths defined a few lines above. Let me know if it's something you'd be interested in doing, I can offer a couple more pointers.

@BettyJJ
Copy link

BettyJJ commented Nov 16, 2024

@lierdakil Ping 🙏
If you don't have time, I'll try to work on it after I finish my current work and have time to learn some Haskell 😅

@lierdakil
Copy link
Owner

Okay, sorry, I completely forgot about it 🤦

Anyway, I believe I have a fix.

---
subfigGrid: true
---

<div id="fig:coolFig"  class="subfigures">

![](/tmp/octocat.png){#fig:cfquatSample}
![](/tmp/octodex.png){#fig:cfquatStar}
![](/tmp/octocat.png){#fig:cfquatBlueStar}
![](/tmp/octodex.png){#fig:cfquatProf}

![](/tmp/octodex.png){#fig:cfbs}
![](/tmp/octocat.png){#fig:cfpc}
![](/tmp/octodex.png){#fig:cfbs2}
![](/tmp/octocat.png){#fig:cfpc2}

Pngfiles
</div>

gets us this docx:

image
(as rendered by onlyoffice)

@lierdakil lierdakil reopened this Dec 15, 2024
@lierdakil
Copy link
Owner

Imma keep this open for now. 40852a9 should finish building in the next half an hour, so if anyone wants to verify the fix, feel free to grab artifacts from https://github.com/lierdakil/pandoc-crossref/actions/runs/12337044436.

I'll make a patch release within a few days.

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

3 participants