Different image format between html and pdf

200 views
Skip to first unread message

lpezard

unread,
Nov 18, 2008, 10:02:16 AM11/18/08
to sphinx-dev
Hi all,

Thanks a lot for Sphinx, I'm right now using it for my web page that I
use to distribute documents to my students. I can no more write html
or latex directly now!

I would like to insert pictures in svg format in the html and pdf
format in latex/pdf but I do not see any obvious solution. So I'm
wondering if:

1. Is it a good idea? (if not why?)

2. Is there an easy way to say "use file.svg for html and file.pdf for
latex/pdf"

3. As far as I can remember, pdflatex searches for file with extension
that it knows (.jpg, .png, .pdf, ...) and I can write something like:

\includegraphics{foo}

and it searches for foo.jpg, etc.

The same way, in my .rst file, I would like to write something like:

.. figure:: fooo
...

and maybe with some configuration list the html build would search in
a list of extensions ie ['jpg', 'svg'...] and the latex one for
another list.

Does this make sense?

Thanks again for Sphinx and for your help!

All the best,

Laurent

Yarko Tymciurak

unread,
Nov 18, 2008, 1:29:48 PM11/18/08
to sphin...@googlegroups.com
the builders will choose the "best" format from what is available, and you write in your rst this:

.. image:: my_images/foo.*

instead of (for example)

.. image:: my_images/foo.pdf


Yarko Tymciurak

unread,
Nov 18, 2008, 2:26:20 PM11/18/08
to sphin...@googlegroups.com
If you look at the sources, sphinx/builder.py - you'll see the supported_image_types:

In StandaloneHTMLBuilder & SerializingHTMLBuilder, they are:
image/svg+xml
image/png
image/gif
image/jpeg

HTMLHelpBuilder & LaTeXBuilder do not include svg;

LaTeXBuilder adds 'application/pdf'

I think these must be parsed in order, as if you have both pdf and png of a file, latex picks pdf.  That would lead me to expect the same behavior for svg.

Regards,
Yarko

lpezard

unread,
Nov 18, 2008, 4:06:05 PM11/18/08
to sphinx-dev
Thanks a lot Yarko!

I'm sorry I missed the foo.* trick in the doc (or I did forget about
it!). I apologize.

I've tried your advice but I get a strange behavior:
My file named lesson1.rst is in the directory $ROOT/source/teachning/
course1. In that file when I write:

.. figure:: foo.*

In got a warning saying that: "... Image file not readable: teaching/
course1/teaching/course1/foo.svg" (and another one for the foo.pdf
file). This is strange since both files are caught (which is not
obvious with the "foo.*" syntax) but it seems that these files are not
searched in the right place.

When I use:

.. figure:: mypics/foo.*

the warning says "... Image file not readable: teaching/course1/
teaching/course1/mypics/foo.svg" (for the tests I put the files in
both places)

The warning disappears when I try:

.. figure:: foo.svg

or

.. figure:: mypics/foo.svg

Any idea?

Regards,

Laurent

PS: I use Sphinx-0.5dev_20081117-py2.5.egg

On 18 nov, 20:26, "Yarko Tymciurak" <yark...@gmail.com> wrote:
> If you look at the sources, sphinx/builder.py - you'll see the
> supported_image_types:
> In StandaloneHTMLBuilder & SerializingHTMLBuilder, they are:
>
> image/svg+xml
> image/png
> image/gif
> image/jpeg
>
> HTMLHelpBuilder & LaTeXBuilder do not include svg;
>
> LaTeXBuilder adds 'application/pdf'
>
> I think these must be parsed in order, as if you have both pdf and png of a
> file, latex picks pdf. That would lead me to expect the same behavior for
> svg.
>
> Regards,
> Yarko
>
> On Tue, Nov 18, 2008 at 12:29 PM, Yarko Tymciurak <yark...@gmail.com> wrote:
> > the builders will choose the "best" format from what is available, and you
> > write in your rst this:
> > .. image:: my_images/foo.*
>
> > instead of (for example)
>
> > .. image:: my_images/foo.pdf
>
> > Seehttp://sphinx.pocoo.org/rest.html#images

Yarko Tymciurak

unread,
Nov 18, 2008, 7:18:02 PM11/18/08
to sphin...@googlegroups.com
Hmmm....   are you using the trunk version of Sphinx?

There was a problem w/ paths and * selection of image files which Georg fixed a short while back (few weeks).

You can get a zip / tar.gz, or tar.bz2 from http://www.bitbucket.org/birkenfeld/sphinx/

(download in upper-right)

lpezard

unread,
Nov 19, 2008, 2:00:04 AM11/19/08
to sphinx-dev
In fact I could not wait to make the test...

So I installed the way you advice and I still get the same problem
with directories. The egg which is installed is:
Sphinx-0.5dev_20081119-py2.5.egg.

I also made some other tests with .svg and I found that the html
builder inserts code like:

<div class="figure">
<img alt="../../_images/toto.svg" src="../../_images/toto.svg" />
...
</div>

which does not allow to display svg file (at least for me), as far as
I understand after some "googling" and reading of svg/html tutorials.
I found that something like:

<div class="figure">
<object data="../../_images/toto.svg" type="image/svg+xml"></object>
...
</div>

works correctly. But since I'm not an expert there is perhaps
something that I miss (once again!)

Regards,

Laurent

On 19 nov, 01:18, "Yarko Tymciurak" <yark...@gmail.com> wrote:
> Hmmm.... are you using the trunk version of Sphinx?
> There was a problem w/ paths and * selection of image files which Georg
> fixed a short while back (few weeks).
>
> You can get a zip / tar.gz, or tar.bz2 fromhttp://www.bitbucket.org/birkenfeld/sphinx/
>
> (download in upper-right)

lpezard

unread,
Nov 19, 2008, 1:03:57 AM11/19/08
to sphinx-dev
I used the command:

hg clone http://bitbucket.org/birkenfeld/sphinx

which I found on

http://www.bitbucket.org/birkenfeld/sphinx/wiki/Home

to install Sphinx on the computer on which I did the trial yesterday.
It is pretty new (2008-11-17).

I'll try to install the way you recommend as soon as I get back to it,
and tell you if I got the same problem.

Thanks again!

BTW: what is the best way to uninstall old versions of Sphinx? I do
not want to "collect" them.

On 19 nov, 01:18, "Yarko Tymciurak" <yark...@gmail.com> wrote:
> Hmmm.... are you using the trunk version of Sphinx?
> There was a problem w/ paths and * selection of image files which Georg
> fixed a short while back (few weeks).
>
> You can get a zip / tar.gz, or tar.bz2 fromhttp://www.bitbucket.org/birkenfeld/sphinx/
>
> (download in upper-right)

Yarko Tymciurak

unread,
Nov 19, 2008, 12:08:45 PM11/19/08
to sphin...@googlegroups.com
I see that "object" is one method;  inline svg is another; "embed" what Adobe recommends, but not valid xhtml.

Here's links I glanced at:

Too bad there doesn't seem to be definitive answer.

Anybody have much experience deploying svg?

Georg Brandl

unread,
Nov 19, 2008, 12:22:56 PM11/19/08
to sphin...@googlegroups.com
lpezard schrieb:

> I used the command:
>
> hg clone http://bitbucket.org/birkenfeld/sphinx
>
> which I found on
>
> http://www.bitbucket.org/birkenfeld/sphinx/wiki/Home
>
> to install Sphinx on the computer on which I did the trial yesterday.
> It is pretty new (2008-11-17).
>
> I'll try to install the way you recommend as soon as I get back to it,
> and tell you if I got the same problem.
>
> Thanks again!
>
> BTW: what is the best way to uninstall old versions of Sphinx? I do
> not want to "collect" them.

Just deleting the directory under site-packages should be fine. For
checkouts, I recommend using "setup.py develop" which just installs
a link to the checkout in site-packages, so that you will always use
the newest version when you update. I've added that to the Wiki too.

cheers,
Georg

Eric

unread,
Jan 8, 2009, 1:24:11 PM1/8/09
to sphinx-dev
I'm happy to hack on the relevant code to get support for <object>
with
SVG images if someone can just point me to the right place to get
started.
...Eric
Reply all
Reply to author
Forward
0 new messages