public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Re: Including SVGs with LaTeX math in Pandoc?
@ 2023-03-06 15:46 Bastien DUMONT
  2023-03-06 15:53 ` A A
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien DUMONT @ 2023-03-06 15:46 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

You can include the command directly in the resulting LaTeX document. This filter should do the job:

```
function Image(image)
  local file = image.src
  if FORMAT == 'latex' and string.match(file, '%.svg$') then
    return pandoc.RawInline('latex', '\\includesvg[scale=1.0]{' .. file .. '}')
  end
end
```


Le Monday 06 March 2023 à 04:11:37PM, A A a écrit :
> I’d like to include SVG graphics in my LaTeX document using pandoc. I
> understand this is currently [1]not supported so I have resorted to the idea of
> performing the SVG to PDF conversion externally and then including in my
> markdown using something like this:
> 
> ![whee](foo.pdf)
> 
> I would prefer not to do this conversion using raw inkscape because the svg
> package in LaTeX has the added advantage of rendering LaTeX math within the
> figure if it encounters LaTeX math in the SVG. This won’t happen if I only use
> inkscape.
> 
> Unfortunately, I haven’t found a way to ensure that the resulting PDF is
> cropped to the extents of the image after doing a LaTeX compilation. For
> example:
> 
> \documentclass{article}
> 
> \usepackage{svg}
> 
> \begin{document}
>     \includesvg[scale=1.0]{idea.svg}
> 
> \end{document}
> 
> will compile as a full A4 sized page with page number. If I then include it in
> my markdown as ![idea](idea.pdf) I’d get the whole page as my “figure” and not
> only the SVG.
> 
> How can include SVGs with LaTeX math in Pandoc ?
> 
> --
> 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 [2]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [3]https://groups.google.com/d/msgid/
> pandoc-discuss/
> CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com.
> 
> References:
> 
> [1] https://github.com/jgm/pandoc/issues/265
> [2] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [3] https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com?utm_medium=email&utm_source=footer

-- 
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/ZAYK7Z%2BjpC9LlcAc%40localhost.


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

* Re: Including SVGs with LaTeX math in Pandoc?
  2023-03-06 15:46 Including SVGs with LaTeX math in Pandoc? Bastien DUMONT
@ 2023-03-06 15:53 ` A A
       [not found]   ` <CAMwawgNE1b+Lzo6edzZsOX_PA-Z9TDPVFKecb-CEFuy2cK0LXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: A A @ 2023-03-06 15:53 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3519 bytes --]

I'd rather not write any filters for this, and convert to PDF or another
format externally, then embed in markdown. Is there perhaps a way to do
that?

On Mon, 6 Mar 2023 at 16:46, Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org>
wrote:

> You can include the command directly in the resulting LaTeX document. This
> filter should do the job:
>
> ```
> function Image(image)
>   local file = image.src
>   if FORMAT == 'latex' and string.match(file, '%.svg$') then
>     return pandoc.RawInline('latex', '\\includesvg[scale=1.0]{' .. file ..
> '}')
>   end
> end
> ```
>
>
> Le Monday 06 March 2023 à 04:11:37PM, A A a écrit :
> > I’d like to include SVG graphics in my LaTeX document using pandoc. I
> > understand this is currently [1]not supported so I have resorted to the
> idea of
> > performing the SVG to PDF conversion externally and then including in my
> > markdown using something like this:
> >
> > ![whee](foo.pdf)
> >
> > I would prefer not to do this conversion using raw inkscape because the
> svg
> > package in LaTeX has the added advantage of rendering LaTeX math within
> the
> > figure if it encounters LaTeX math in the SVG. This won’t happen if I
> only use
> > inkscape.
> >
> > Unfortunately, I haven’t found a way to ensure that the resulting PDF is
> > cropped to the extents of the image after doing a LaTeX compilation. For
> > example:
> >
> > \documentclass{article}
> >
> > \usepackage{svg}
> >
> > \begin{document}
> >     \includesvg[scale=1.0]{idea.svg}
> >
> > \end{document}
> >
> > will compile as a full A4 sized page with page number. If I then include
> it in
> > my markdown as ![idea](idea.pdf) I’d get the whole page as my “figure”
> and not
> > only the SVG.
> >
> > How can include SVGs with LaTeX math in Pandoc ?
> >
> > --
> > 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 [2]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [3]
> https://groups.google.com/d/msgid/
> > pandoc-discuss/
> > CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com
> .
> >
> > References:
> >
> > [1] https://github.com/jgm/pandoc/issues/265
> > [2] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [3]
> https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com?utm_medium=email&utm_source=footer
>
> --
> 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/ZAYK7Z%2BjpC9LlcAc%40localhost
> .
>

-- 
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/CAMwawgNE1b%2BLzo6edzZsOX_PA-Z9TDPVFKecb-CEFuy2cK0LXw%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 5272 bytes --]

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

* Re: Including SVGs with LaTeX math in Pandoc?
       [not found]   ` <CAMwawgNE1b+Lzo6edzZsOX_PA-Z9TDPVFKecb-CEFuy2cK0LXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2023-03-13  0:59     ` Julien Dutant
  0 siblings, 0 replies; 4+ messages in thread
From: Julien Dutant @ 2023-03-13  0:59 UTC (permalink / raw)
  To: pandoc-discuss


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

Perhaps one of these:

method 1, without external conversion. Load the LaTeX package in markdown, 
insert the raw LaTeX command:

``` markdown
---
header-includes:
    ``` {=latex}
    \usepackage{svg}
   ```
---

See illustration below:

\includesvg[scale=1.0]{idea.svg}
```

Downside: the image only shows in LaTeX/PDF output. You could use a filter 
that allows you to hide/show bits depending on output formats, but then you 
might as well use Bastien's filter.

method 2, external conversion: as you've done, but you should use the 
standalone document class (assuming it doesn't conflict with the svg 
package. It crops documents to the size of the image. See 
https://ctan.org/pkg/standalone 

Best, J

On Monday, March 6, 2023 at 3:53:48 PM UTC A A wrote:

> I'd rather not write any filters for this, and convert to PDF or another 
> format externally, then embed in markdown. Is there perhaps a way to do 
> that?
>
> On Mon, 6 Mar 2023 at 16:46, Bastien DUMONT <bastien...-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> wrote:
>
>> You can include the command directly in the resulting LaTeX document. 
>> This filter should do the job:
>>
>> ```
>> function Image(image)
>>   local file = image.src
>>   if FORMAT == 'latex' and string.match(file, '%.svg$') then
>>     return pandoc.RawInline('latex', '\\includesvg[scale=1.0]{' .. file 
>> .. '}')
>>   end
>> end
>> ```
>>
>>
>> Le Monday 06 March 2023 à 04:11:37PM, A A a écrit :
>> > I’d like to include SVG graphics in my LaTeX document using pandoc. I
>> > understand this is currently [1]not supported so I have resorted to the 
>> idea of
>> > performing the SVG to PDF conversion externally and then including in my
>> > markdown using something like this:
>> > 
>> > ![whee](foo.pdf)
>> > 
>> > I would prefer not to do this conversion using raw inkscape because the 
>> svg
>> > package in LaTeX has the added advantage of rendering LaTeX math within 
>> the
>> > figure if it encounters LaTeX math in the SVG. This won’t happen if I 
>> only use
>> > inkscape.
>> > 
>> > Unfortunately, I haven’t found a way to ensure that the resulting PDF is
>> > cropped to the extents of the image after doing a LaTeX compilation. For
>> > example:
>> > 
>> > \documentclass{article}
>> > 
>> > \usepackage{svg}
>> > 
>> > \begin{document}
>> >     \includesvg[scale=1.0]{idea.svg}
>> > 
>> > \end{document}
>> > 
>> > will compile as a full A4 sized page with page number. If I then 
>> include it in
>> > my markdown as ![idea](idea.pdf) I’d get the whole page as my “figure” 
>> and not
>> > only the SVG.
>> > 
>> > How can include SVGs with LaTeX math in Pandoc ?
>> > 
>> > --
>> > 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 [2]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> > To view this discussion on the web visit [3]
>> https://groups.google.com/d/msgid/
>> > pandoc-discuss/
>> > CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%
>> 40mail.gmail.com.
>> > 
>> > References:
>> > 
>> > [1] https://github.com/jgm/pandoc/issues/265
>> > [2] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>> > [3] 
>> https://groups.google.com/d/msgid/pandoc-discuss/CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com?utm_medium=email&utm_source=footer
>>
>> -- 
>> 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/ZAYK7Z%2BjpC9LlcAc%40localhost
>> .
>>
>

-- 
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/3296c082-c030-4075-94a7-fa34aed7e3c1n%40googlegroups.com.

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

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

* Including SVGs with LaTeX math in Pandoc?
@ 2023-03-06 15:11 A A
  0 siblings, 0 replies; 4+ messages in thread
From: A A @ 2023-03-06 15:11 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]

I’d like to include SVG graphics in my LaTeX document using pandoc. I
understand this is currently not supported
<https://github.com/jgm/pandoc/issues/265> so I have resorted to the idea
of performing the SVG to PDF conversion externally and then including in my
markdown using something like this:

![whee](foo.pdf)

I would prefer not to do this conversion using raw inkscape because the svg
package in LaTeX has the added advantage of rendering LaTeX math within the
figure if it encounters LaTeX math in the SVG. This won’t happen if I only
use inkscape.

Unfortunately, I haven’t found a way to ensure that the resulting PDF is
cropped to the extents of the image *after* doing a LaTeX compilation. For
example:

\documentclass{article}

\usepackage{svg}

\begin{document}
    \includesvg[scale=1.0]{idea.svg}

\end{document}

will compile as a full A4 sized page with page number. If I then include it
in my markdown as ![idea](idea.pdf) I’d get the whole page as my “figure”
and not only the SVG.

How can include SVGs with LaTeX math in Pandoc ?

-- 
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/CAMwawgPKcXu-CapB6d_vSWc7%3DvfA_sQSzFnnv4nGBurq6%2BMkEw%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 5756 bytes --]

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

end of thread, other threads:[~2023-03-13  0:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 15:46 Including SVGs with LaTeX math in Pandoc? Bastien DUMONT
2023-03-06 15:53 ` A A
     [not found]   ` <CAMwawgNE1b+Lzo6edzZsOX_PA-Z9TDPVFKecb-CEFuy2cK0LXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-03-13  0:59     ` Julien Dutant
  -- strict thread matches above, loose matches on Subject: below --
2023-03-06 15:11 A A

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).