%% %% This is file `swfigure.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% swfigure.dtx (with options: `package') %% %% Copyright (C) 2020 Claudio Beccari all rights reserved. %% License information appended %% \NeedsTeXFormat{LaTeX2e}[2020/01/01] \ProvidesPackage{swfigure}% [2020-11-10 v.0.9.14 Managing large and spread wide figures] \RequirePackage{etoolbox} \RequirePackage{xfp} \ExplSyntaxOn \ProvideExpandableDocumentCommand\CompStrings{m m}{% \str_if_eq_p:nn{#1}{#2}} \ProvideExpandableDocumentCommand\fptest{m m m}{% \fp_compare:nTF{#1}{#2}{#3}} \ProvideExpandableDocumentCommand\SetList{m m}{% \seq_clear_new:N #1 \seq_set_from_clist:Nn \DisplayModeList {#2}} \ProvideExpandableDocumentCommand\TestList{m m m m}{% \seq_if_in:NnTF #1 {#2}{#3}{#4}} \ExplSyntaxOff \RequirePackage{trace} \RequirePackage{graphicx} \RequirePackage{afterpage} \RequirePackage{wrapfig} \newdimen\internalmargin \internalmargin=\dimexpr\oddsidemargin+1in+1bp\relax \newdimen\externalmargin \externalmargin=\dimexpr\evensidemargin+1in \newdimen\spreadwidth \spreadwidth=\dimexpr 2\textwidth+2\internalmargin\relax \newdimen\DFwidth \newdimen\DFheight \newdimen\DFhalfwidth \newdimen\DFheight \newdimen\DFhalfheight \newdimen\FigSpace \def\SWcaptionShift{1em}% \def\FScaptionShift{2em}% \newsavebox\DFtotalimage \newsavebox\DFimageI \newsavebox\DFimageII \newsavebox\RFbox \newdimen\VS@textwidth \newcount\VS@lines \newif\if@SWtmode \NewDocumentCommand\DFcaption{O{#2} m o}{\refstepcounter{figure}% \vtop to 0pt{\hsize=\textheight\parindent=0pt\leavevmode Figure \thefigure\quad #2\vss}% \addcontentsline{lof}{figure}{\protect\numberline{\thefigure}#1} \IfValueT{#3}{\label{#3}}\relax% } \NewDocumentCommand\DFcaptionP{O{#2} m o D!!{black}}% {\refstepcounter{figure}% \vbox to 0pt{\vss\hsize=\textheight\parindent=0pt\leavevmode #4\relax Figure \thefigure\quad #2}% \addcontentsline{lof}{figure}{\protect\numberline{\thefigure}#1} \IfValueT{#3}{\label{#3}}\relax% } \newcommand\set@tmode@newpage{% \ifvmode \@SWtmodefalse \else \unskip\@SWtmodetrue\linebreak \vadjust{\vspace{0pt plus1fill}\newpage}% \fi} \newcommand\reset@tmode{\if@SWtmode\expandafter\noindent\ignorespaces\fi} \newcommand\cleartoeven[1]{% \set@tmode@newpage\clearpage \ifodd\c@page\afterpage{#1}\else#1\fi% } \NewDocumentEnvironment{DFimage}% {O{SW} m O{#4} m o D(){0.8} D<>{0} D||{0.25} D!!{}}% {% \SetList{\DisplayModeList}{SW,HS,VS,FS,NF,RF}% \TestList{\DisplayModeList}{#1}% {\csuse{#1figure}{#2}[#3]{#4}[#5](#6)<#7>|#8|!#9!% \fptest{\CompStrings{\@currenv}{DFimage}}{}{\reset@tmode}% }% {% \DFwarning[#1]{#2}[#3]{#4} }% }% {% \aftergroup\reset@tmode }% \NewDocumentCommand\DFwarning{ o m o m o d() d<> d|| d!!}% {\PackageWarning{swfigure}% {********************************************\MessageBreak Option #1\space is not valid. Nothing done \MessageBreak \MessageBreak Image #2 was not processed \MessageBreak *******************************************\MessageBreak }% } \NewDocumentCommand\SWfigure{m o m o d() d<> d|| d!!}{% \setbox\DFtotalimage=\hbox{\includegraphics{#1}}% \DFwidth=\wd\DFtotalimage \DFhalfwidth=0.5\DFwidth \DFheight=\ht\DFtotalimage \FigSpace=\dimexpr\textwidth+\internalmargin\relax \setbox\DFimageI\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = 0 0 \the\DFhalfwidth\space 0]}\x{#1}}% \setbox\DFimageII\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% \fptest{\DFheight/\DFhalfwidth > \textheight/\FigSpace}% {\edef\DFscalefactor{\fpeval{\textheight/\DFheight}}}% {\edef\DFscalefactor{\fpeval{\FigSpace/\DFhalfwidth}}}% \setbox\DFimageI=\hbox{\scalebox{\DFscalefactor}{\usebox{\DFimageI}}}% \setbox\DFimageII=\hbox{\scalebox{\DFscalefactor}{\usebox{\DFimageII}}}% \cleartoeven{% \begin{figure}[p]% \vbox to\textheight{\vss\hsize=\textwidth% \makebox[\hsize][l]{\makebox[\FigSpace][r]{\box\DFimageI}}\vss}% \end{figure}\newpage \begin{figure}[p]% \vbox to\textheight{\vss\hsize=\textwidth \makebox[\hsize][r]{\makebox[\FigSpace][l]{\box\DFimageII}% \makebox(0,0)[lb]{\hspace*{\SWcaptionShift}\raisebox{0.5\textheight}{% \rotatebox[origin=tc]{90}{\DFcaption[#2]{#3}[#4]% % }}}}\vss}% \end{figure}% }\clearpage\reset@tmode} \NewDocumentCommand\NFfigure{m o m o d() d<> d|| d!!}{% \begin{figure}[p] \includegraphics[width=\linewidth, height=#5\textheight, keepaspectratio]{#1}% \caption[#2]{#3}% \IfValueT{#4}{\label{#4}}\relax \end{figure} } \NewDocumentCommand\RFfigure{m o m o d() d<> d|| d!!}{% \dimen8=\textwidth\dimen10=\textheight \figure[p]\setbox\RFbox=\hbox{% \rotatebox[origin=cc]{90}{\parbox[b][\dimen8][c]{\dimen10}% {\centering\includegraphics[width=\dimen10, height=\dimen8, keepaspectratio]{#1}% \caption[#2]{#3}% \IfValueT{#4}{\label{#4}}\relax% }}}% \edef\RFx{\fpeval{\ht\RFbox/\textheight}}% \edef\RFy{\fpeval{\wd\RFbox/\textwidth}}% \fptest{\RFx > \RFy}% {\scalebox{\RFx}{\box\RFbox}}% {\scalebox{\RFy}{\box\RFbox}}% \endfigure} \NewDocumentCommand\VSfigure{m o m o d() d<> d|| d!!}{% \setbox\DFtotalimage=\hbox{\includegraphics{#1}} \DFwidth=\wd\DFtotalimage \DFheight=\ht\DFtotalimage \edef\VS@aspectratio{\fpeval{\DFheight/\DFwidth}} \fptest{ \VS@aspectratio < 2 }% {\begin{center}\ttfamily ===========================================\\ Image \textit{#1} is not tall enough.\\ Consider using a display mode different\\ from VS; may be NF or RF are better suited.\\ ===========================================\\ Nothing done!\\ =========================================== \end{center} }% {\edef\VS@factor{\fpeval{#5\textheight/\DFheight}}% \fptest{\VS@factor>1 || \VS@factor\DFwidth < #7\textwidth}% {% \begin{center}\ttfamily =================================================\\ The scaled image \textit{#1} is too slim. \\ Maybe directly using the wrapfig package might \\ solve this problem. \\ =================================================\\ Nothing done!\\ ================================================= \end{center} }% {\setbox\DFtotalimage= \hbox{\scalebox{\VS@factor}{\box\DFtotalimage}}% \edef\VS@width{\fpeval{\VS@factor*\DFwidth}\p@}% \setbox\DFtotalimage=\vbox{\hsize=\VS@width% \def\@captype{figure}\box\DFtotalimage \caption[#2]{#3}% \IfValueT{#4}{\label{#4}}\relax} \VS@lines= \fpeval{round(\ht\DFtotalimage/\baselineskip,0)+#6}% \begin{wrapfigure}[\VS@lines]{o}[0pt]{\VS@width}% \box\DFtotalimage \end{wrapfigure}% }% }% }% \NewDocumentCommand\HSfigure{m o m o d() d<> d|| d!!}{% \setbox\DFtotalimage=\hbox{\includegraphics{#1}}% \DFwidth=\wd\DFtotalimage \DFhalfwidth=0.5\DFwidth \FigSpace=0.5\spreadwidth% \setbox\DFimageI\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = 0 0 \the\DFhalfwidth\space 0]}\x{#1}}% \setbox\DFimageII\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% \edef\DFscalefactor{\fpeval{\FigSpace/\DFhalfwidth}}% \setbox\DFimageI=\hbox{% \scalebox{\DFscalefactor}{\usebox{\DFimageI}}}% \setbox\DFimageII=\hbox{% \scalebox{\DFscalefactor}{\usebox{\DFimageII}}}% \setbox\DFimageII= \hbox{\dimen10=\linewidth\dimen8\internalmargin \vbox{\hsize\DFhalfwidth\parindent\z@ \box\DFimageII\par \leavevmode\hspace*{\dimen8}% \vtop{\hsize\dimen10\parindent\z@ \textwidth=\hsize \DFcaption[#2]{#3}[#4]% }\vspace*{2\baselineskip}% }% }% \setbox\DFimageI=\vbox to\ht\DFimageII{\box\DFimageI\vss}% \cleartoeven{% \hb@xt@\textwidth{% \makebox[\DFhalfwidth][l]{\box\DFimageI}\hss}% \afterpage{\hb@xt@\textwidth{% \hss\makebox[\DFhalfwidth][r]{\box\DFimageII}}% }% }% } \NewDocumentCommand\FSfigure{m o m o d() d<> d|| d!!}{% \fptest{\CompStrings{\@currenv}{DFimage}}{}{\bgroup}% \pagestyle{empty}% \setbox\DFtotalimage=\hbox{\includegraphics{#1}}% \DFwidth=\wd\DFtotalimage \DFheight=\ht\DFtotalimage \ifdim \DFheight < \DFwidth \DFhalfwidth=0.5\DFwidth \setbox\DFimageI\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = 0 0 \the\DFhalfwidth\space 0]}\x{#1}}% \setbox\DFimageII\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% \DFwidth=\DFhalfwidth \DFheight=\ht\DFtotalimage \else \DFhalfheight=0.5\DFheight \setbox\DFimageII\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = 0 0 0 \the\DFhalfheight\space]}\x{#1}}% bottom half \setbox\DFimageI\hbox{\bgroup \edef\x{\egroup\noexpand\includegraphics*[% trim = 0 \the\DFhalfheight\space 0 0]}\x{#1}}% tophalf \setbox\DFimageI=\hbox{\rotatebox[origin=cc]{90}{\box\DFimageI}} \setbox\DFimageII=\hbox{\rotatebox[origin=cc]{90}{\box\DFimageII}} \DFwidth=\DFhalfheight \DFheight=\wd\DFtotalimage \fi \fptest{\DFheight/\DFwidth > \paperheight/\paperwidth}% {\edef\DFscalefactor{\fpeval{\paperheight/\DFheight}}}% {\edef\DFscalefactor{\fpeval{\paperwidth/\DFwidth}}}% \setbox\DFimageI=\hbox{\scalebox{\DFscalefactor}{\usebox{\DFimageI}}}% \setbox\DFimageII=\hbox{\scalebox{\DFscalefactor}{\usebox{\DFimageII}}}% \cleartoeven{% \begin{figure}[p]% \vbox to\textheight{\vss\hsize=\textwidth% vbox 1 \hbox to\hsize{\hspace*{-\externalmargin}% hbox 1 \vbox to\paperheight{\vss% vbox 2 \hbox to\paperwidth{\hss\box\DFimageI}% hbox 2 end hbox 2 \vss}% end vbox 2 \hss}% end hbox 1 \vss}% end vbox 1 \end{figure}\newpage \begin{figure}[p]% \vbox to\textheight{\vss\hsize=\textwidth% vbox 1 \hbox to\hsize{\hspace*{-\internalmargin}% hbox 1 \vbox to\paperheight{\vss% vbox 2 \hbox to\paperwidth{% hbox 2 \box\DFimageII\makebox(0,0)[lb]{% mbox 3 \hspace*{-\FScaptionShift}% \raisebox{0.5\textheight}{% raisebox \rotatebox[origin=bc]{90}{% rotatebox \DFcaptionP[#2]{#3}[#4]!#8!% }% end rotatebox }% end raisebox }% end mbox 3 }% end hbox 2 \vss}% end vbox 2 \hss}% end hbox 1 \vss}% end vbox 1 \end{figure}% }\clearpage \fptest{\CompStrings{\@currenv}{DFimage}}{}{\egroup}% \reset@tmode} %% %% Distributable under the LaTeX Project Public License, %% version 1.3c or higher (your choice). The latest version of %% this license is at: http://www.latex-project.org/lppl.txt %% %% This work is "maintained" %% %% This work consists of files swfigure.dtx and README.txt, and the derived %% files swfigure.sty and swfigure.pdf %% %% %% End of file `swfigure.sty'.