| 1 |
% \iffalse |
| 2 |
%<*gobble> |
| 3 |
% $Id: rviewport.dtx,v 1.2 2011-08-27 22:53:32 boris Exp $ |
| 4 |
% |
| 5 |
% Copyright 2011, Boris Veytsman <[email protected]> |
| 6 |
% This work may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either |
| 8 |
% version 1.3 of this license or (at your option) any |
| 9 |
% later version. |
| 10 |
% The latest version of the license is in |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% and version 1.3 or later is part of all distributions of |
| 13 |
% LaTeX version 2003/06/01 or later. |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The Current Maintainer of this work is Boris Veytsman |
| 18 |
% |
| 19 |
% This work consists of the file rviewport.dtx and the |
| 20 |
% derived files rviewport.sty, rviewport.dtx. |
| 21 |
% |
| 22 |
% \fi |
| 23 |
% \CheckSum{110} |
| 24 |
% |
| 25 |
% |
| 26 |
%% \CharacterTable |
| 27 |
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 28 |
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 29 |
%% Digits \0\1\2\3\4\5\6\7\8\9 |
| 30 |
%% Exclamation \! Double quote \" Hash (number) \# |
| 31 |
%% Dollar \$ Percent \% Ampersand \& |
| 32 |
%% Acute accent \' Left paren \( Right paren \) |
| 33 |
%% Asterisk \* Plus \+ Comma \, |
| 34 |
%% Minus \- Point \. Solidus \/ |
| 35 |
%% Colon \: Semicolon \; Less than \< |
| 36 |
%% Equals \= Greater than \> Question mark \? |
| 37 |
%% Commercial at \@ Left bracket \[ Backslash \\ |
| 38 |
%% Right bracket \] Circumflex \^ Underscore \_ |
| 39 |
%% Grave accent \` Left brace \{ Vertical bar \| |
| 40 |
%% Right brace \} Tilde \~} |
| 41 |
% |
| 42 |
%\iffalse |
| 43 |
% \begin{macrocode} |
| 44 |
\documentclass{ltxdoc} |
| 45 |
\usepackage{array,graphicx} |
| 46 |
\usepackage{url,amsmath,hypdoc} |
| 47 |
\usepackage{rviewport} |
| 48 |
\newcommand\progname[1]{\textsl{#1}} |
| 49 |
\DoNotIndex{\NeedsTeXFormat, \ProvidesPackage, \def, \hspace} |
| 50 |
\DoNotIndex{\futurelet, \@gobble, \ifx, \else, \fi, \relax} |
| 51 |
\DoNotIndex{\ifmmode, \fi, \allowbreak} |
| 52 |
\PageIndex |
| 53 |
\CodelineIndex |
| 54 |
\RecordChanges |
| 55 |
\EnableCrossrefs |
| 56 |
\begin{document} |
| 57 |
\DocInput{rviewport.dtx} |
| 58 |
\end{document} |
| 59 |
% \end{macrocode} |
| 60 |
%</gobble> |
| 61 |
% \fi |
| 62 |
% \MakeShortVerb{|} |
| 63 |
% |
| 64 |
%\GetFileInfo{rviewport.sty} |
| 65 |
% \title{Relative Viewport for Graphics Inclusion\thanks{\copyright |
| 66 |
% Boris Veytsman, 2011. E-mail: \texttt{[email protected]}}} |
| 67 |
% \author{Boris Veytsman\thanks{This work was partially supported by |
| 68 |
% The Food and Agriculture Organization of the United Nations}} |
| 69 |
% \date{\filedate, \fileversion} |
| 70 |
% \maketitle |
| 71 |
% |
| 72 |
% \begin{abstract} |
| 73 |
% The package adds a new keyword |rviewport| to the |
| 74 |
% \progname{graphicx} package specifiying Relative Viewport for |
| 75 |
% graphics inclusion: a window defined by the given fractions of the |
| 76 |
% natural width and height of the image. |
| 77 |
% \end{abstract} |
| 78 |
% |
| 79 |
% \tableofcontents |
| 80 |
% |
| 81 |
% \clearpage |
| 82 |
% |
| 83 |
%\section{User Interface} |
| 84 |
%\label{sec:interface} |
| 85 |
% |
| 86 |
% Package \progname{graphicx} provides a useful keyword |viewport| |
| 87 |
% which allows to show just a part of an image. However, one needs to |
| 88 |
% put there the actual coordinates of the viewport window. Sometimes |
| 89 |
% it is useful to have relative coordinates as fractions of |
| 90 |
% natural size. For example, one may want to print a large image on a |
| 91 |
% spread, putting a half on a verso page, and another half on the next |
| 92 |
% recto page. For this one would need a viewport occupying exactly |
| 93 |
% one half of the file's bounding box, whatever the actual width of the |
| 94 |
% image may be. |
| 95 |
% |
| 96 |
% Here we define the new option |rviewport| for |
| 97 |
% Relative Viewport. It works like this. Suppose the image has the |
| 98 |
% bounding box $x_{ll}$, $y_{ll}$, $x_{ur}$, $y_{ur}$. We give four |
| 99 |
% numbers $\xi_{ll}$, $\eta_{ll}$, $\xi_{ur}$, $\eta_{ur}$, and the viewport |
| 100 |
% coordinates become |
| 101 |
% \begin{align*} |
| 102 |
% x'_{ll} &= x_{ll} + \xi_{ll}\Delta_x\\ |
| 103 |
% y'_{ll} &= y_{ll} + \eta_{ll}\Delta_y\\ |
| 104 |
% x'_{ur} &= x_{ll} + \xi_{ur}\Delta_x\\ |
| 105 |
% y'_{ur} &= y_{ll} + \eta_{ur}\Delta_y |
| 106 |
% \end{align*} |
| 107 |
% where |
| 108 |
% \begin{align*} |
| 109 |
% \Delta_x &= x_{ur} - x_{ll}\\ |
| 110 |
% \Delta_y &= y_{ur} - y_{ll} |
| 111 |
% \end{align*} |
| 112 |
% This means that the left half of the image can be defined as |
| 113 |
% |rviewport = 0 0 0.5 1|, |
| 114 |
% and the right half can be defined as |rviewport = 0.5 0 1 1|. |
| 115 |
% |
| 116 |
% The package may be loaded before or after \progname{graphicx} |
| 117 |
% package. |
| 118 |
% |
| 119 |
% |
| 120 |
%\section{Examples} |
| 121 |
%\label{sec:examples} |
| 122 |
% |
| 123 |
% |
| 124 |
% \def\Example#1{% |
| 125 |
% \begin{center} |
| 126 |
% \includegraphics[rviewport=#1,clip]{vitruvian}\\* |
| 127 |
% \cmd{\includegraphics}[rviewport=#1,clip]\texttt{\{vitruvian\}} |
| 128 |
% \end{center}} |
| 129 |
% |
| 130 |
% \Example{0 0 1 1} |
| 131 |
% \Example{0 0 0.5 1} |
| 132 |
% \Example{0.5 0 1 1} |
| 133 |
% \Example{0 0 0.5 0.5} |
| 134 |
% \Example{0 0.5 1 1} |
| 135 |
% \Example{0 0 1 0.5} |
| 136 |
% \Example{0.4 0.6 0.6 0.9} |
| 137 |
% |
| 138 |
% |
| 139 |
%\StopEventually{} |
| 140 |
% |
| 141 |
% \clearpage |
| 142 |
% |
| 143 |
% \section{Implementation} |
| 144 |
% \label{sec:implementation} |
| 145 |
% |
| 146 |
% |
| 147 |
%\subsection{Declarations} |
| 148 |
%\label{sec:decl} |
| 149 |
% |
| 150 |
% We start with declaration, who we are: |
| 151 |
% |
| 152 |
% |
| 153 |
% \begin{macrocode} |
| 154 |
%<*style> |
| 155 |
\NeedsTeXFormat{LaTeX2e} |
| 156 |
\ProvidesPackage{rviewport} |
| 157 |
[2011/08/27 v1.0 Relative viewport for graphics inclusion] |
| 158 |
% \end{macrocode} |
| 159 |
% |
| 160 |
% The package \progname{graphicx} loads \progname{keyval}, but in case |
| 161 |
% we are loaded before \progname{graphicx} we require it here: |
| 162 |
% \begin{macrocode} |
| 163 |
\RequirePackage{keyval} |
| 164 |
% \end{macrocode} |
| 165 |
% |
| 166 |
% |
| 167 |
%\subsection{The New Key} |
| 168 |
%\label{sec:key} |
| 169 |
% |
| 170 |
% We add a new key for the \progname{graphicx} package: |
| 171 |
% \begin{macrocode} |
| 172 |
\define@key{Gin}{rviewport} |
| 173 |
{\let\Gin@viewport@code\Gin@rviewport\Gread@parse@rvp#1 \\} |
| 174 |
% \end{macrocode} |
| 175 |
% |
| 176 |
% |
| 177 |
% \begin{macro}{\Gread@parse@rvp} |
| 178 |
% We parse four numbers into the corresponding macros: |
| 179 |
% \begin{macrocode} |
| 180 |
\def\Gread@parse@rvp#1 #2 #3 #4 #5\\{% |
| 181 |
\def\Gin@vllx{#1}% |
| 182 |
\def\Gin@vlly{#2}% |
| 183 |
\def\Gin@vurx{#3}% |
| 184 |
\def\Gin@vury{#4}}% |
| 185 |
% \end{macrocode} |
| 186 |
% |
| 187 |
% \end{macro} |
| 188 |
% |
| 189 |
% \begin{macro}{\Gin@rviewport} |
| 190 |
% And the viewport code. Note that |pdftex.def| relies on |
| 191 |
% the values of |\Gin@v...| macros, so we redefine them as well. |
| 192 |
% \begin{macrocode} |
| 193 |
\def\Gin@rviewport{% |
| 194 |
\let\Gin@ollx\Gin@llx |
| 195 |
\let\Gin@olly\Gin@lly |
| 196 |
\let\Gin@ourx\Gin@urx |
| 197 |
\let\Gin@oury\Gin@ury |
| 198 |
\Gin@nat@width\Gin@urx\p@ |
| 199 |
\advance\Gin@nat@width-\Gin@llx\p@ |
| 200 |
\Gin@nat@height\Gin@ury\p@ |
| 201 |
\advance\Gin@nat@height-\Gin@lly\p@ |
| 202 |
\dimen@\Gin@vurx\Gin@nat@width |
| 203 |
\edef\Gin@vurx{\strip@pt\dimen@}% |
| 204 |
\advance\dimen@\Gin@llx\p@ |
| 205 |
\edef\Gin@urx{\strip@pt\dimen@}% |
| 206 |
\dimen@\Gin@vury\Gin@nat@height |
| 207 |
\edef\Gin@vury{\strip@pt\dimen@}% |
| 208 |
\advance\dimen@\Gin@lly\p@ |
| 209 |
\edef\Gin@ury{\strip@pt\dimen@}% |
| 210 |
\dimen@\Gin@vllx\Gin@nat@width |
| 211 |
\edef\Gin@vllx{\strip@pt\dimen@}% |
| 212 |
\advance\dimen@\Gin@llx\p@ |
| 213 |
\edef\Gin@llx{\strip@pt\dimen@}% |
| 214 |
\dimen@\Gin@vlly\Gin@nat@height |
| 215 |
\edef\Gin@vlly{\strip@pt\dimen@}% |
| 216 |
\advance\dimen@\Gin@lly\p@ |
| 217 |
\edef\Gin@lly{\strip@pt\dimen@}} |
| 218 |
% \end{macrocode} |
| 219 |
% |
| 220 |
% \end{macro} |
| 221 |
% |
| 222 |
% |
| 223 |
% |
| 224 |
%\subsection{The Last Words} |
| 225 |
%\label{sec:last} |
| 226 |
% |
| 227 |
% |
| 228 |
% |
| 229 |
% \begin{macrocode} |
| 230 |
%</style> |
| 231 |
% \end{macrocode} |
| 232 |
%\Finale |
| 233 |
%\clearpage |
| 234 |
% |
| 235 |
%\PrintChanges |
| 236 |
%\clearpage |
| 237 |
%\PrintIndex |
| 238 |
% |
| 239 |
\endinput |