From be5b1768f4f6169a51c0b7357f5bd2a0710e507f Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 13 Oct 2020 20:52:25 +0000 Subject: swfigure (13oct20) git-svn-id: svn://tug.org/texlive/trunk@56651 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/latex/swfigure/swfigure.dtx | 126 +++++++++++++++------ 1 file changed, 92 insertions(+), 34 deletions(-) (limited to 'Master/texmf-dist/source/latex') diff --git a/Master/texmf-dist/source/latex/swfigure/swfigure.dtx b/Master/texmf-dist/source/latex/swfigure/swfigure.dtx index d848cae2fae..4629fb398ce 100644 --- a/Master/texmf-dist/source/latex/swfigure/swfigure.dtx +++ b/Master/texmf-dist/source/latex/swfigure/swfigure.dtx @@ -20,7 +20,7 @@ this license is at: http://www.latex-project.org/lppl.txt This work is "maintained" -This work consists of files swfigure.dtx and READEME.txt, and the derived +This work consists of files swfigure.dtx and README.txt, and the derived files swfigure.sty and swfigure.pdf \endpostamble @@ -45,7 +45,7 @@ files swfigure.sty and swfigure.pdf %<+package>\ProvidesPackage{swfigure}% %<+readme>File README.txt for package swfigure %<*package|readme> - [2020-10-11 v.0.9.07 Managing large and spread wide figures] + [2020-10-13 v.0.9.08 Managing large and spread wide figures] % %<*driver> \documentclass[a4paper]{ltxdoc}\errorcontextlines=9 @@ -222,7 +222,7 @@ Managing large and spread wide figures} % with the following syntax: %\begin{ttsyntax} %\cs{DFimage}\oarg{display mode}\marg{image file name}\oarg{lof entry}\marg{caption}\oarg{label}\% -%\qquad\parg{heigth correction}\aarg{line correction} +%\qquad\parg{heigth correction}\aarg{line correction}|\meta{width test}| %\end{ttsyntax} % where: %\begin{description}[noitemsep] @@ -260,6 +260,16 @@ Managing large and spread wide figures} % little vertical space around the image and its caption; by examining % the document drafts it is possible to increase or decrease the % vertical space by any (integer) number of lines. +%\item[\meta{width test}] this further vertical bars delimited argument +% is used only when dealing with vertical slim images; when they are +% scaled down in order to fit in the available space, their width may +% become too small to allow a decently typeset caption underneath the +% image. A test is made to compare the scaled image width with a +% fraction of the text block width in order to skip the image insertion +% if the image width becomes too small; the default value for this +% \meta{width test} fraction is \texttt{0.25}, but the user can specify +% a different value, even zero; with the zero value the width test is +% skipped. %\end{description} % %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -323,17 +333,22 @@ Managing large and spread wide figures} % with different measure than normal text. Again it is up to the user % to chose where to insert the \cs{DFfigure} command. If the aspect % ratio of the image to include is lower than~2, this message is printed -% in the document where the image should appear (of course with |#2| replaced by the actual image file name): +% in the document where the image should appear (of course with |#1| +% replaced by the actual image file name):\\ +%\begin{minipage}{0.7\textwidth} %\begin{verbatim} % =========================================== -% Figure #2 is not tall enough. +% Figure #1 is not tall enough. % Consider using a display mode different % from VS; may be NF or RF are better suited. % =========================================== % Nothing done! % =========================================== %\end{verbatim} -%^^A +%\end{minipage}\\[2ex] +% A similar action and a similar message is output if the scaled image +% width becomes too small. +% %\end{description} % %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -348,6 +363,9 @@ Managing large and spread wide figures} % me to submit the result to the \TeX\ community, and here it is. % Heinrich did not want his name as an author, because he insists % that he was “just” a tester. He was precious and I warmly thank him. +% +% Thanks also to Benedict Wilde who spotted some errors and suggested +% the use of a specific setting for the PDF viewer. % %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\begin{thebibliography}{9} @@ -404,7 +422,6 @@ Managing large and spread wide figures} %\fi % \begin{macrocode} \RequirePackage{etoolbox} -\RequirePackage{xparse} \RequirePackage{xfp} \ExplSyntaxOn @@ -425,7 +442,14 @@ Managing large and spread wide figures} % we assign parameters relating to the page design. We also compute % the dimensions of the available spread space so as to have available % the elements to compare the aspect ratios of the images and of the -% available spaces. +% available spaces. The |\if@SWtmode| switch is used only by the |SW| +% display mode in order to save the typesetting mode that was active +% when the |\DFimage| command was used in the source file; if it was +% in text mode, the switch is set to |true| and no spaces should be +% present after the last argument of that macro; the result is that +% the |\SWfigure| service macro shifts to vertical mode, but as soon +% as it is completed the switch test restores the text mode. +% % \begin{macrocode} \newdimen\internalmargin \internalmargin=\dimexpr\oddsidemargin+1in+1bp\relax @@ -443,6 +467,7 @@ Managing large and spread wide figures} \newsavebox\RFbox \newdimen\VS@textwidth \newcount\VS@lines +\newif\if@SWtmode % \end{macrocode} % The following caption-like command recompiles the captions within @@ -494,7 +519,8 @@ Managing large and spread wide figures} % that implement the various mode displays. It outputs an error % message if the \meta{display mode} acronym was misspelt. % \begin{macrocode} -\NewDocumentEnvironment{DFimage}{O{SW} m O{#4} m o D(){0.8} D<>{0}}{% +\NewDocumentEnvironment{DFimage}{% + O{SW} m O{#4} m o D(){0.8} D<>{0} D||{0.25}}{% \ifstrequal{#1}{SW}% {% \SWfigure{#2}[#3]{#4}[#5]% @@ -509,7 +535,7 @@ Managing large and spread wide figures} }% {\ifstrequal{#1}{VS}% {% - \VSfigure{#2}[#3]{#4}[#5](#6)<#7>% + \VSfigure{#2}[#3]{#4}[#5](#6)<#7>|#8|% }% {\ifstrequal{#1}{HS} {% @@ -533,7 +559,7 @@ Managing large and spread wide figures} % In the following subsection the five specific display mode macros % are examined and commented. %^^A===================================== -% \subsection{The specific \cs{SWfigure} macro for Spread Wide images} +% \subsection{The \cs{SWfigure} macro for Spread Wide images} %^^A===================================== %The specific macro for spread-wide images has the following syntax: %\begin{ttsyntax} @@ -602,7 +628,10 @@ Managing large and spread wide figures} % spread page, rotated $90^\circ$ counterclockwise. % \begin{macrocode} \NewDocumentCommand\SWfigure{m O{#3} m o}{% -\unless\ifvmode +\ifvmode + \@SWtmodefalse +\else + \@SWtmodetrue \csuse{@bsphack}% \vadjust{\vspace{0pt plus1fill}\csuse{@esphack}\newpage}% \fi @@ -641,11 +670,11 @@ trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% \rotatebox[origin=tc]{90}{\DFcaption[#2]{#3}[#4]% % }}}}\vss}% -\end{figure}\clearpage} +\end{figure}\clearpage\if@SWtmode\noindent\fi} % \end{macrocode} %^^A======================================== -%\subsection{The specific \cs{NFfigure} macro for normal full +%\subsection{The \cs{NFfigure} macro for normal full % page figures} %^^A======================================== % This code is without surprises, except that it receives from the @@ -668,7 +697,7 @@ trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% % \end{macrocode} %^^A======================================== -% \subsection{The specific \cs{RFfigure} macro for rotated figures} +% \subsection{The \cs{RFfigure} macro for rotated figures} %^^A======================================== % There are no new comments to make about this almost standard % way of displaying a large figure, except, perhaps, the fact @@ -699,10 +728,10 @@ trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% % \end{macrocode} %^^A======================================== -% \subsection{The specific \cs{VSfigure} macro for tall and slim figures} +% \subsection{The \cs{VSfigure} macro for tall and slim figures} %^^A======================================== -% This is the most troublesome macro, because it needs to depend -% on the |wrapfig| package, in order to set the image with its +% This is the most critical macro (because it depends +% on the |wrapfig| package) in order to set the image with its % caption on the external side of the text block, with the text flowing % around it. Package |wrapfig| has several limitations concerning % the text that flows around the image. Nevertheless with a “normal” @@ -721,15 +750,30 @@ trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% % in the output document that informs the user and recommends to % use another \meta{display mode} acronym. % +% Furthermore, should the image be very slim and tall, the +% \meta{height correction} may conveniently reduce its height, +% but, in order to avoid changing its aspect ratio, it reduces +% also its width; eventually the withs is reduced to the point that +% beneath the image there would not be enough space for a decently +% typeset caption. A further optional delimited argument is available: +% its delimiting tokens are two vertical bars, \verb+| |+, and its +% default value is \texttt{0.25}. This means that if the scaled +% image becomes narrower than this coefficient times the text width, +% an other message is typeset in place of the figure. Depending of the +% various elements that influence these tests, the user can try +% different values for this coefficient, even reaching the value zero, +% that eliminates such test on the scaled image width. +% +% % \begin{macrocode} -\NewDocumentCommand\VSfigure{m O{#3} m o d() D<>{0}}{% +\NewDocumentCommand\VSfigure{m O{#3} m o 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 ===========================================\\ - Figure #2 is not tall enough.\\ + Image \textit{#1} is not tall enough.\\ Consider using a display mode different\\ from VS; may be NF or RF are better suited.\\ ===========================================\\ @@ -738,24 +782,38 @@ trim = \the\DFhalfwidth\space 0 0 0]}\x{#1}}% \end{center} }% {\edef\VS@factor{\fpeval{#5\textheight/\DFheight}}% - \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}}% -} + \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}% + }% + }% + }% % \end{macrocode} % %^^A===================================== -% \subsection{The specific \cs{HSfigure} macro for spread wide slim +% \subsection{The \cs{HSfigure} macro for spread wide slim % figures} %^^A===================================== % -- cgit v1.2.3