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

Suggestion: MS writer, preserve image name #4475

Open
teoric opened this issue Mar 19, 2018 · 10 comments
Open

Suggestion: MS writer, preserve image name #4475

teoric opened this issue Mar 19, 2018 · 10 comments

Comments

@teoric
Copy link

teoric commented Mar 19, 2018

Currently (pandoc 2.1.2), pandoc's ms writer drops the complete image from the source

![DESCRIPTION](images/image) 

becomes

[IMAGE: DESCRIPTION]

But it seems to become so useful that I would suggest to make the file name available somehow; that way, one can make use of it when working with the ms document, and get a nice PS/PDF out of it. The following would be very unobtrusive markup-wise:

.PSPIC "images/name" WIDTH HEIGHT
[IMAGE: DESCRIPTION]

(Only provide WIDTH and HEIGHT if defined in the original document in useful units. Potentially comment them if they are percent values or other useless values.)
This would even work if images/name is an EPS graphic and the file is processed with -Tps, but not give a nice caption. Else, it would be easily replaced by .PDFPIC "images/name" WIDTH HEIGHT, if one cares to do so.
If the resulting error messages are too annoying, or you want to come closer to the LaTeX approach, one could consider the following; this way, tweaking the output to a real figure would be rather simple, and would show a real placeholder.

.KF \" start keep - non-floating with KS
.DS C \" center display
.ANYPIC  "images/name" WIDTH HEIGHT \"   replace this by a call to .PSPIC/.PDFPIC
.CAPTION "[DESCRIPTION 1]"
.DE \" end display
.KE \" end keep

(Only provide WIDTH and HEIGHT if defined in the original document in useful units. Potentially comment them if they are percent values or other useless values.)
and e.g. include in the standard template as a dummy definition:

.de ANYPIC  \" macro to be replaced by user with PSPIC or PDFPIC
\\fC\\$1\\fP
.br
..
.nr IMAGE 0 1 \" register for image number, autoincrement
.de CAPTION
\v'1v'
.\"  nr IMAGE +1
Figure \\n+[IMAGE]. \\fB\\$1\\fP
..

For the term figure, you could rely on the groff localisation efforts (\*[locale]-lifg), but that may be to advanced as you would also have to mso <LANG>.tmac, which only exists for some languages.

@teoric
Copy link
Author

teoric commented Apr 15, 2018

I now have a lua filter + ms macro version that works for me and also tries to convert graphics to PDF. I would gladly share this (the Lua part also contains some other stuff; I could prepare a cleaned-up version) if you are interested, but if ms is considered more of a draft format, it might be better to just close this issue.

@jgm
Copy link
Owner

jgm commented Apr 15, 2018

I'm certainly interested. You might consider sharing your filter on pandoc/lua-filters.
But I see no reason why we shouldn't make the recommended changes, or something like them, in pandoc itself.

@teoric
Copy link
Author

teoric commented Apr 15, 2018

Oh, great! So do you want to have a look at the lua filter to see how it handles these changes and then consider what to take from it, and I share the filter for the rest? The relevant parts would be Image for the image code, Table for a somewhat too complicated table wrapper (I actually used graphics within tables to get the right captions with LaTeX and ms, that's why they are related).
I made a repository with the macro definitions for .ANYPIC and the table wrappers as well as some header spacing changes that suit my personal taste better.
Some definitions for integration and the internationalisation are in my little fork of the standard template, which also adds some dynamic line-spacing modifications; changes are rather heavily commented, but I would gladly provide some other format, if that helps; it may be preferable to use Pandoc internationalisation strings if they exist, or let users define them in their preamble; I currently pull them from the groff files, but they are limited to German, English and French.)

@terefang
Copy link

is this still broken ?

jgm added a commit that referenced this issue Sep 14, 2023
See #4475.

+ PDFPIC is now used for PDF images in figures.
+ Inline images that are postscript or PDF are rendered using
  PSPIC or PDFPIC. This isn't ideal, because they will still be
  rendered as if in a separate paragraph, but it's probably
  better than just printing the image name.
+ Units are included in height.

For further improvement, we might consider in Text.Pandoc.PDF
using something like `convertImages` (which we currently use for
converting to PDF via LaTeX) to convert SVG (and other?) images
to PDF so they can be rendered in this way.
@jgm
Copy link
Owner

jgm commented Sep 14, 2023

I just pushed some small improvements (PDF images will now work).
I'm not sure I want to go all the way to using a custom macro, but we might be able to have Text.Pandoc.PDF convert images to PDF before calling the ms writer.

@terefang
Copy link

i have tried the lua filter and template enhancements referenced above (from @teoric), but they did not work for me.

@teoric
Copy link
Author

teoric commented Sep 16, 2023

I suppose this is not the right place to discuss my enhancements, but I can try to look into problems if you write to me or raise an issue at my repo. One problem that occurs sometimes has to do with the output of some tools, which may be easy to fix locally.

@jgm, PDF inclusion and your further plans sound great, thank you!

@terefang
Copy link

terefang commented Sep 16, 2023

@teoric i was only using your filter to see if it was i viable workaround

@jgm i am really interested at improving the ms writer by giving feedback

to explain my situation a little bit better: my use case involves mostly converting markdown to pdf with a ms template that i adapted from the standard.

i also use a pagebreak.lua filter script to align some headers to the start of a new page.

what i now need is to insert full-width images in png/jpg/svg formats.

@teoric
Copy link
Author

teoric commented Sep 16, 2023

@terefang I was only trying to tell you that I would be willing to help you exploring/improving viability and that there are some undocumented stumbling blocks and dependencies. (Not documented because nobody has ever expressed interest in using this, and for me, the approach has been viable the few times I needed it ;-).) But I understand now that you are seeking a different solution entirely.

@terefang
Copy link

@teoric i understand, thanks, but for me the way forward is to have this in pandoc

wraithm pushed a commit to bitnomial/pandoc that referenced this issue Mar 21, 2024
See jgm#4475.

+ PDFPIC is now used for PDF images in figures.
+ Inline images that are postscript or PDF are rendered using
  PSPIC or PDFPIC. This isn't ideal, because they will still be
  rendered as if in a separate paragraph, but it's probably
  better than just printing the image name.
+ Units are included in height.

For further improvement, we might consider in Text.Pandoc.PDF
using something like `convertImages` (which we currently use for
converting to PDF via LaTeX) to convert SVG (and other?) images
to PDF so they can be rendered in this way.
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