mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
This commit is contained in:
parent
358f5e08ef
commit
67fe3d6da0
@ -867,23 +867,27 @@
|
|||||||
\raggedright}
|
\raggedright}
|
||||||
{\end{list}}
|
{\end{list}}
|
||||||
|
|
||||||
% Re-define \includegraphics to resize images larger than the line width
|
% Redefine \includegraphics to resize images larger than the line width,
|
||||||
% if the size is not specified.
|
% except if height or width option present.
|
||||||
|
%
|
||||||
|
% If scale is present, rescale before fitting to line width. (since 1.5)
|
||||||
|
%
|
||||||
% Warning: future version of Sphinx will not modify original \includegraphics,
|
% Warning: future version of Sphinx will not modify original \includegraphics,
|
||||||
% Below custom code will be direct definition of \sphinxincludegraphics, with
|
% below code will be definition only of \sphinxincludegraphics.
|
||||||
% \py@Oldincludegraphics replaced by direct use of original \includegraphics.
|
|
||||||
\let\py@Oldincludegraphics\includegraphics
|
\let\py@Oldincludegraphics\includegraphics
|
||||||
\newbox\spx@image@box
|
\newbox\spx@image@box
|
||||||
\renewcommand*{\includegraphics}[2][\@empty]{%
|
\renewcommand*{\includegraphics}[2][]{%
|
||||||
\ifx\@empty #1% attention, #1 could be bb.., bad if first after \ifx
|
\in@{height}{#1}\ifin@\else\in@{width}{#1}\fi
|
||||||
\setbox\spx@image@box=\hbox{\py@Oldincludegraphics{#2}}%
|
\ifin@ % height or width present
|
||||||
\ifdim \wd\spx@image@box>\linewidth
|
|
||||||
\py@Oldincludegraphics[width=\linewidth]{#2}%
|
|
||||||
\else
|
|
||||||
\leavevmode\box\spx@image@box
|
|
||||||
\fi
|
|
||||||
\else
|
|
||||||
\py@Oldincludegraphics[#1]{#2}%
|
\py@Oldincludegraphics[#1]{#2}%
|
||||||
|
\else % no height nor width (but #1 may be "scale=...")
|
||||||
|
\setbox\spx@image@box\hbox{\py@Oldincludegraphics[#1,draft]{#2}}%
|
||||||
|
\ifdim \wd\spx@image@box>\linewidth
|
||||||
|
\setbox\spx@image@box\box\voidb@x % clear memory
|
||||||
|
\py@Oldincludegraphics[#1,width=\linewidth]{#2}%
|
||||||
|
\else
|
||||||
|
\py@Oldincludegraphics[#1]{#2}%
|
||||||
|
\fi
|
||||||
\fi
|
\fi
|
||||||
}
|
}
|
||||||
% Writer will put \sphinxincludegraphics in LaTeX source, and with this,
|
% Writer will put \sphinxincludegraphics in LaTeX source, and with this,
|
||||||
|
@ -1400,11 +1400,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
post = []
|
post = []
|
||||||
include_graphics_options = []
|
include_graphics_options = []
|
||||||
is_inline = self.is_inline(node)
|
is_inline = self.is_inline(node)
|
||||||
if 'scale' in attrs:
|
|
||||||
# Could also be done with ``scale`` option to
|
|
||||||
# ``\includegraphics``; doing it this way for consistency.
|
|
||||||
pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
|
|
||||||
post.append('}')
|
|
||||||
if 'width' in attrs:
|
if 'width' in attrs:
|
||||||
w = self.latex_image_length(attrs['width'])
|
w = self.latex_image_length(attrs['width'])
|
||||||
if w:
|
if w:
|
||||||
@ -1413,6 +1408,17 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
h = self.latex_image_length(attrs['height'])
|
h = self.latex_image_length(attrs['height'])
|
||||||
if h:
|
if h:
|
||||||
include_graphics_options.append('height=%s' % h)
|
include_graphics_options.append('height=%s' % h)
|
||||||
|
if 'scale' in attrs:
|
||||||
|
if include_graphics_options:
|
||||||
|
# unfortunately passing "height=1cm,scale=2.0" to \includegraphics
|
||||||
|
# does not result in a height of 2cm. We must scale afterwards.
|
||||||
|
pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
|
||||||
|
post.append('}')
|
||||||
|
else:
|
||||||
|
# if no "width" nor "height", \sphinxincludegraphics will fit
|
||||||
|
# to the available text width if oversized after rescaling.
|
||||||
|
include_graphics_options.append('scale=%s'
|
||||||
|
% (float(attrs['scale']) / 100.0))
|
||||||
if 'align' in attrs:
|
if 'align' in attrs:
|
||||||
align_prepost = {
|
align_prepost = {
|
||||||
# By default latex aligns the top of an image.
|
# By default latex aligns the top of an image.
|
||||||
|
Loading…
Reference in New Issue
Block a user