The images in the Latex are too big for my needs. I'd like to modulate
their scale with a global value.
Specificaly, I'd like a switch in the conf.py to change the '100.0' of
sphinx/writers/latex.py, line 842 into something else that I can control,
and (if there is no 'scale', to include a line of this type).
If this make things clearer, here are the modifications I did to my local
copy:
diff -r 692b4cc330f7 sphinx/writers/latex.py
--- a/sphinx/writers/latex.py Sun May 17 19:35:19 2009 +0200
+++ b/sphinx/writers/latex.py Mon May 18 23:00:06 2009 +0200
@@ -839,7 +839,10 @@
if attrs.has_key('scale'):
# Could also be done with ``scale`` option to
# ``\includegraphics``; doing it this way for consistency.
- pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
+ pre.append('\\scalebox{%f}{' % (0.8*attrs['scale'] /
100.0,))
+ post.append('}')
+ else:
+ pre.append('\\scalebox{%f}{' % (0.8))
post.append('}')
if attrs.has_key('width'):
w = self.latex_image_length(attrs['width'])
I'd like the '0.8' not to be hard coded, but set in the conf.py.
Thanks for all your work, Georg,
Gaël
> The images in the Latex are too big for my needs. I'd like to modulate
> their scale with a global value.
> Specificaly, I'd like a switch in the conf.py to change the '100.0' of
> sphinx/writers/latex.py, line 842 into something else that I can control,
> and (if there is no 'scale', to include a line of this type).
> I'd like the '0.8' not to be hard coded, but set in the conf.py.
I fear this leads to "configuritis".
Are you sure that there is no other sensible way like
* setting the printing resolution in the image or using smaller images,
* setting the scale for the images individually,
* using a stylesheet and re-defining the scalebox command::
\let\oldscalebox\scalebox
\renewcommand{\scalebox}[2]{\oldscalebox{0.8}{#2}}
(use fixed sizes instead of scaling if you want to set an individual image
size or use some LaTeX calculation to compute the product of 0.8 and #1).
Günter
Possibly, but on every single sphinx document I manage, I feel the pdf
has too large pages.
> Are you sure that there is no other sensible way like
> * setting the printing resolution in the image or using smaller images,
The images are pngs, so there is no printing resolution. Smaller images
will screw up HTML rendering, which is our main output. Currently, I
choose the size of the images so that it renders well in HTML, and as a
result the PDF doesn't look right. One of the big deals with sphinx is to
be able to produce high-quality HTML and PDF from the same source.
> * setting the scale for the images individually,
Tedious, and will affect HTML, which I don't want.
> * using a stylesheet and re-defining the scalebox command::
> \let\oldscalebox\scalebox
> \renewcommand{\scalebox}[2]{\oldscalebox{0.8}{#2}}
That's an option, althought it feels like a gludge. For this to work
however, the part of my patch that adds a scalebox to every image should
be added. I do think this is not right, for two reasons: the first is
that scalebox might be used not only for images, the second is that the
scale specified by the user gets killed.
My 2 cents,
Gaėl
This is, fortunately, not correct: PNG files do carry information about
the printing resolution, and pdflatex obeys this specification. It can be
changed with eg. PIL,
>>> img = Image.open('foo.png')
>>> img.save('foo.png', 'PNG', dpi=(300, 300))
I think also matplotlib sets the DPI on saving.
However, this is kind of obscure and hard to discover (eg. Gimp doesn't
seem to offer a way to set this when saving), so I wonder if this is the
right solution.
Cheers,
Pauli
> Tue, 19 May 2009 09:17:04 +0200, Gael Varoquaux kirjoitti:
> [clip]
> > The images are pngs, so there is no printing resolution.
> This is, fortunately, not correct: PNG files do carry information about
> the printing resolution, and pdflatex obeys this specification. It can be
> changed with eg. PIL,
> >>> img = Image.open('foo.png')
> >>> img.save('foo.png', 'PNG', dpi=(300, 300))
> I think also matplotlib sets the DPI on saving.
Interesting. In the case of the Mayavi documentation, most of my images
are created by VTK, so I'll have to check out to see if I can specify
DPI. Googling tells me that jpegs also have this setting.
I still would like an override, because many tool chains used to create
images do not expose this functionnality in an obvious way to the user (I
guess I am saying the same thing than you).
Gaël
>> I fear this leads to "configuritis".
> Possibly, but on every single sphinx document I manage, I feel the pdf
> has too large pages.
>> Are you sure that there is no other sensible way like
>> * setting the printing resolution in the image or using smaller images,
My Gimp has a "Image > Set Print Resolution" menu item (actually in German,
so the translation might be incorrect).
>> * setting the scale for the images individually,
> Tedious, and will affect HTML, which I don't want.
So, rather set a fixed size (width, say).
(I tend to set the image size for all images, so maybe this is why I do
not see the urge for this additional option).
>> * using a stylesheet and re-defining the \scalebox command
...
> That's an option, althought it feels like a gludge.
Alternative: re-define the \includegraphics command (in the graphicx
version, it has a "scale" key-option that you might give a default
value).
Günter
>>> * using a stylesheet and re-defining the \scalebox command
> ...
>> That's an option, althought it feels like a gludge.
I found "the right way" in grfguide.pdf:
4.6 Global setting of keys
Most of the keyval keys used in the graphicx package may also be set
using the command \setkeys provided by the keyval package.
For instance, suppose you wanted all the files to be included in the
current document to be scaled to 75% of the width of the lines of text,
then one could issue the following command:
\setkeys{Gin}{width=0.75\textwidth} Here ‘Gin’ is the name used for the
keyval keys associated with ‘Graphics inclusion’. All following
\includegraphics commands (within the same group or environment) will
act as if [width=0.75\textwidth] had been specified, in addition to any
other key settings actually given in the optional argument.
Similarly to make all \rotatebox arguments take an argument in radians,
one just needs to specify: \setkeys{Grot}{units=6.28318}
so for your scaling, the default value can be set with::
\usepackage{graphicx}
\setkeys{Gin}{scale=0.75}
Günter
> On 2009-05-19, Guenter Milde wrote:
> > On 2009-05-19, Gael Varoquaux wrote:
> >> On Tue, May 19, 2009 at 05:50:59AM +0000, Guenter Milde wrote:
> >>> * using a stylesheet and re-defining the \scalebox command
> > ...
> >> That's an option, althought it feels like a gludge.
> I found "the right way" in grfguide.pdf:
> [snip]
> \usepackage{graphicx}
> \setkeys{Gin}{scale=0.75}
Sounds better. It will also have an impact on the cover image. I guess I
can set it after the table of content.
OK, I am happy :).
Gaël
> On Tue, May 19, 2009 at 11:26:03AM +0000, Guenter Milde wrote:
>> On 2009-05-19, Guenter Milde wrote:
>> > On 2009-05-19, Gael Varoquaux wrote:
>> >> On Tue, May 19, 2009 at 05:50:59AM +0000, Guenter Milde wrote:
>> >>> * using a stylesheet and re-defining the \scalebox command
>> > ...
>> >> That's an option, althought it feels like a gludge.
>> I found "the right way" in grfguide.pdf:
>> [snip]
>> \usepackage{graphicx}
>> \setkeys{Gin}{scale=0.75}
> Sounds better. It will also have an impact on the cover image. I guess I
> can set it after the table of content.
You can override it for the cover image or set with "raw" latex in the
document.
> OK, I am happy :).
Fine.
Günter
Hi, I've just tried this and it doesn't seems to work. What I want is to
scale all the images generated by the graphviz extension. Is this supposed
to work only with PNG images (graphviz ext generates PDFs for the latex
writer)? I've added it to the latex_preamble config option, should I add
it elsewhere?
Thanks!
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
- Mire, don Inodoro! Una paloma con un anillo en la pata! Debe ser
mensajera y cayó aquí!
- Y... si no es mensajera es coqueta... o casada.
-- Mendieta e Inodoro Pereyra
>> Most of the keyval keys used in the graphicx package may also be set
>> using the command \setkeys provided by the keyval package.
>> so for your scaling, the default value can be set with::
>> \usepackage{graphicx}
>> \setkeys{Gin}{scale=0.75}
> Hi, I've just tried this and it doesn't seems to work. What I want is to
> scale all the images generated by the graphviz extension. Is this supposed
> to work only with PNG images (graphviz ext generates PDFs for the latex
> writer)?
Strange. It should work for all supported graphics formats.
> I've added it to the latex_preamble config option, should I add
> it elsewhere?
Seems correct.
Please send a minimal example (tex file).
Günter
Ok, attached .tex + pdf image. In the small example image I noticed this
warning:
pdfTeX warning: pdflatex (file ./image.pdf): PDF inclusion: Page Group
detected which pdfTeX can't handle. Ignoring it.
>] (./example.aux) )</usr/share/texmf-texlive/fonts/type1/bluesky/cm/cmr10.pfb>
Maybe that has something to do with it?
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Ingeniero Juanjo Charlante, Linux es como una mermelada?
>> >> Most of the keyval keys used in the graphicx package may also be set
>> >> using the command \setkeys provided by the keyval package.
>> >> so for your scaling, the default value can be set with::
>> >> \usepackage{graphicx}
>> >> \setkeys{Gin}{scale=0.75}
>> > Hi, I've just tried this and it doesn't seems to work.
It did not work in my tests here too (independent of the graphic format).
However, it works (here) for a global image width:
\documentclass{article}
\usepackage{graphicx}
%\setkeys{Gin}{scale=0.5}
\setkeys{Gin}{width=0.25\textwidth}
\begin{document}
\includegraphics{image.pdf}
\includegraphics[scale=0.5]{image.pdf}
\end{document}
Asking in comp.text.tex brought me a partial explanation:
might be beause they are handled differently, the width is saved in a
macro, scale is not.
have a look in the source in graphicx.sty
So available options for scaling pictures differently in HTML and PDF
via LaTeX would be:
1. set a printing resolution in the image,
2. set a global default image width in the style sheet/preamble with ::
\usepackage{graphicx}
\setkeys{Gin}{width=0.25\textwidth}
3. specify the width argument using the unit 'px' and specify a global
resolution in the style sheet/preamble with ::
\pdfpxdimen=1in % 1 DPI
\divide\pdfpxdimen by 92 % 92 DPI
(substitute 92 with the desired resolution) or any translation to an
absolute length like e.g. ::
\pdfpxdimen=0.1mm % 10 px = 1 mm
Günter
Thanks for the answer. I finally scaled the images myself (they were
graphviz generated diagrams).