public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Modifying image conversion from epub to ConTeXt
@ 2019-07-14 18:07 Patrick Kenny
       [not found] ` <cf583d7d-be4f-4513-95f0-7abb4f642580-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Kenny @ 2019-07-14 18:07 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1272 bytes --]

I have an epub that I am attempting to convert to TeX for use with ConTeXt.

This epub includes JPGs and SVGs.  The JPGs are fine as is, but for the 
SVGs, I want to modify the conversion to prevent line breaks when at the 
start of a paragraph and specify a width for all of them.

Conversion command:
pandoc -f epub -t context -o body.tex myepub.epub

Current output:
{\externalfigure[media/svg/1f4ae.svg]} Title
{\externalfigure[media/svg/1f4af.svg]}

Desired output:
\dontleavehmode{\externalfigure[media/svg/1f4ae.svg][width=0.5cm]} Title
\dontleavehmode{\externalfigure[media/svg/1f4af.svg][width=0.5cm]}

What's the best way to modify how all the SVGs are converted but not touch 
the JPGs?



-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/cf583d7d-be4f-4513-95f0-7abb4f642580%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1965 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Modifying image conversion from epub to ConTeXt
       [not found] ` <cf583d7d-be4f-4513-95f0-7abb4f642580-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-07-14 18:20   ` John MacFarlane
       [not found]     ` <m2lfx0a36q.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: John MacFarlane @ 2019-07-14 18:20 UTC (permalink / raw)
  To: Patrick Kenny, pandoc-discuss


You can use a lua filter.  Intercept a single Para containing an
Image with an svg extension, and produce a "RawBlock" with the
context code you want.  The jpgs will stay the same.

Patrick Kenny <ptmkenny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I have an epub that I am attempting to convert to TeX for use with ConTeXt.
>
> This epub includes JPGs and SVGs.  The JPGs are fine as is, but for the 
> SVGs, I want to modify the conversion to prevent line breaks when at the 
> start of a paragraph and specify a width for all of them.
>
> Conversion command:
> pandoc -f epub -t context -o body.tex myepub.epub
>
> Current output:
> {\externalfigure[media/svg/1f4ae.svg]} Title
> {\externalfigure[media/svg/1f4af.svg]}
>
> Desired output:
> \dontleavehmode{\externalfigure[media/svg/1f4ae.svg][width=0.5cm]} Title
> \dontleavehmode{\externalfigure[media/svg/1f4af.svg][width=0.5cm]}
>
> What's the best way to modify how all the SVGs are converted but not touch 
> the JPGs?
>
>
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/cf583d7d-be4f-4513-95f0-7abb4f642580%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Modifying image conversion from epub to ConTeXt
       [not found]     ` <m2lfx0a36q.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-07-20  5:13       ` Patrick Kenny
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Kenny @ 2019-07-20  5:13 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2877 bytes --]

Thank you!

I don't know how to use lua, but based on your hint, I was able to do it in 
panflute.

Here's my code in case it helps someone else:

#!/usr/local/bin/python3


"""
Add formatting for SVG for use with ConTeX.
"""


import panflute as pf




def action(elem, doc):
    if isinstance(elem, pf.Image):
        extension = elem.url[-3:]
        if extension == 'svg':
            url = elem.url
            processedstring = '\dontleavehmode{\externalfigure[' + url + 
'][width=0.5cm]}'
            return(pf.RawInline(processedstring, 'tex'))
        else:
            return elem


def main(doc=None):
    return pf.run_filter(action, doc=doc)


if __name__ == '__main__':
    main()




On Monday, July 15, 2019 at 3:20:30 AM UTC+9, John MacFarlane wrote:
>
>
> You can use a lua filter.  Intercept a single Para containing an 
> Image with an svg extension, and produce a "RawBlock" with the 
> context code you want.  The jpgs will stay the same. 
>
> Patrick Kenny <ptmk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes: 
>
> > I have an epub that I am attempting to convert to TeX for use with 
> ConTeXt. 
> > 
> > This epub includes JPGs and SVGs.  The JPGs are fine as is, but for the 
> > SVGs, I want to modify the conversion to prevent line breaks when at the 
> > start of a paragraph and specify a width for all of them. 
> > 
> > Conversion command: 
> > pandoc -f epub -t context -o body.tex myepub.epub 
> > 
> > Current output: 
> > {\externalfigure[media/svg/1f4ae.svg]} Title 
> > {\externalfigure[media/svg/1f4af.svg]} 
> > 
> > Desired output: 
> > \dontleavehmode{\externalfigure[media/svg/1f4ae.svg][width=0.5cm]} Title 
> > \dontleavehmode{\externalfigure[media/svg/1f4af.svg][width=0.5cm]} 
> > 
> > What's the best way to modify how all the SVGs are converted but not 
> touch 
> > the JPGs? 
> > 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "pandoc-discuss" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
> <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/cf583d7d-be4f-4513-95f0-7abb4f642580%40googlegroups.com. 
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f6c9731b-bb0d-4764-9917-c0caf205a08b%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 11479 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-20  5:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-14 18:07 Modifying image conversion from epub to ConTeXt Patrick Kenny
     [not found] ` <cf583d7d-be4f-4513-95f0-7abb4f642580-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-14 18:20   ` John MacFarlane
     [not found]     ` <m2lfx0a36q.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-07-20  5:13       ` Patrick Kenny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).