%--------------------------------------------------------------------------- % Copyright 2015 Daan Leijen, Microsoft Corporation. % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 % of this license or (at your option) any later version. % The latest version of this license is in % http://www.latex-project.org/lppl.txt % and version 1.3 or later is part of all distributions of LaTeX % version 2005/12/01 or later. %--------------------------------------------------------------------------- \NeedsTeXFormat{LaTeX2e}[1995/12/01] \ProvidesPackage{longfbox}[2015/12/01, Daan Leijen, Provides long fbox that can break over pages] \RequirePackage{options} \RequirePackage{longbox} \RequirePackage{pict2e} \RequirePackage{ellipse} % -------------------------------------------------------- % Dimension calulations % -------------------------------------------------------- % dimmin/dimmax return minimum or maximum dimension \providecommand\dim@min[2]{\ifdim#1>#2#2\else #1\fi} \providecommand\dim@max[2]{\ifdim#1>#2#1\else #2\fi} \newcommand*\option@dimmin[2]{\dim@min{\option{#1}}{\option{#2}}} \newcommand*\option@dimmax[2]{\dim@max{\option{#1}}{\option{#2}}} % -------------------------------------------------------- % Add a new 'sides' option type % -------------------------------------------------------- \options{ /handlers/new sides/.new handler = []{ \ifblank{#2}% {\option@def{#1/@cmd@sides}##1##2##3##4{\optionsalso{#1-top={##1}, #1-right={##2}, #1-bottom={##3}, #1-left={##4}}}}% {\option@def{#1/@cmd@sides}##1##2##3##4{\optionsalso{#2}}}% \optionsalso{ #1/.new cmdx = {##1,##2,##3,##4,##5\relax}{,,,,\relax}{% \ifblank{##2##3##4}{\option{#1/@cmd@sides}{##1}{##1}{##1}{##1}}% {\ifblank{##3##4}{\option{#1/@cmd@sides}{##1}{##2}{##1}{##2}}% {\ifblank{##4}{\option{#1/@cmd@sides}{##1}{##2}{##3}{##2}}% {\option{#1/@cmd@sides}{##1}{##2}{##3}{##4}}% }% }% }, #1/.type = sides, }% },% } \newcommand*\optionlengthlimit[3]{% len, min, max \letoption{#1}\opt@temp \ifdim\opt@temp<\dimexpr#2\relax \option@invoke{#1}{#2}% \else\ifdim\opt@temp>\dimexpr#3\relax \option@invoke{#1}{#3}% \fi\fi } \newcommand*\optionradiuslimit[4]{% r1, r2, min, max \letoption{#1}\opt@tempa \letoption{#2}\opt@tempb \ifdim\opt@tempa<\dimexpr#3\relax\option@invoke{#1}{#3}\fi \ifdim\opt@tempb<\dimexpr#3\relax\option@invoke{#2}{#3}\fi \ifdim\dimexpr\opt@tempa + \opt@tempb\relax=\z@\relax\else \ifdim\dimexpr\opt@tempa+\opt@tempb\relax>\dimexpr#4\relax \edef\opt@perc{\the\numexpr(\number\dimexpr#4\relax)/% (\number\dimexpr(\opt@tempa+\opt@tempb)/100\relax)}% %\typeout{scale:\the\opt@tempa,\the\opt@tempb, by \opt@perc percent to make \the\dimexpr#4\relax}% \edef\opt@temp{\dimexpr\opt@perc\dimexpr\the\opt@tempa\relax / 100\relax}% \option@einvoke{#1}{\opt@temp}% \option@einvoke{#2}{\dimexpr#4 - \opt@temp\relax}% %\typeout{ scaled to: \the\opt@temp,\the\dimexpr#4 - \opt@temp\relax}% \fi \fi } % \begin{macro}{\trig@atantan} % \marg{a}\marg{b}\marg{$\alpha$}{dimen$_\mathit{reg}$}\\ % Assigns $\atan_2(\frac{\sin(\alpha)}{b},\frac{\cos(\alpha)}{a})$ to dimension register \textit{dimen$_\mathit{reg}$}, % where $a$ and $b$ are dimensions. % Returns $\alpha$ when $a = b$, or when $a=0$ or $b=0$. % \begin{macrocode} \newcommand*\trig@atantan[4]{% %\typeout{ atantan:(\the#1,\the#2,\the#3, #4)}% \@tempdima\dimexpr#1\relax \@tempdimb\dimexpr#2\relax % \end{macrocode} % If $a = b$, we have a circle and the result is $\alpha$. % \begin{macrocode} \ifdim\@tempdima=\@tempdimb #4\dimexpr#3\relax \else\ifdim\@tempdima=\z@ #4\dimexpr#3\relax \else\ifdim\@tempdimb=\z@ #4\dimexpr#3\relax \else \edef\trig@temp{\strip@pt\dimexpr#3\relax}% \CalculateSin{\trig@temp}\CalculateCos{\trig@temp}% \@tempdimc\dimexpr1\p@ * \dimexpr\UseSin{\trig@temp}\p@\relax/\@tempdimb\relax \@tempdimd\dimexpr1\p@ * \dimexpr\UseCos{\trig@temp}\p@\relax/\@tempdima\relax \pIIe@atantwo{\@tempdimc}{\@tempdimd}\dimen@ \ifdim\dimen@<\z@ \ifdim\dimexpr#3\relax<\z@\else\advance\dimen@360\p@\fi \fi \@tempdima\dimexpr#3 - \dimen@\relax \ifdim\@tempdima<\z@\@tempdima-\@tempdima\fi \ifdim\@tempdima<360\p@\else\advance\dimen@360\p@\fi %\typeout{atan: \the\dimexpr#3\relax versus. \the\dimen@ }% #4\dimen@ \fi\fi\fi } % \end{macrocode} % \end{macro} % rough approximation of the perimeter; % if |radius-x == radius-y| = 0 (a circle), the approximation is precise. % otherwise, works best when |angle2-angle1| <= 45 and gets worse from there on. \newcommand*\ellip@letarcperimeter[5]{% 'radius-x', 'radius-y', 'angle-1', 'angle-2', '\result' \@tempdima\dimexpr#3\relax \@tempdimb\dimexpr#4\relax \@tempdimc\dimexpr\@tempdima - \@tempdimb\relax \ifdim\@tempdimc<\z@\@tempdimc-\@tempdimc\fi \ifdim#1=#2\relax% circle? \edef\@tempa{\strip@pt\@tempdimc}% angle difference delta as factor \dimen@\@tempa\dimexpr#1\relax% r*delta \dimen@0.017453\dimen@% (2*pi/360) * r * delta = 2*pi*r * (delta/360) \else% ellipse: take the distance between the points on the ellipse, works pretty good if delta <= 45, and ok'ish for delta <= 90 \@ovro\dimexpr#1\relax \@ovri\dimexpr#2\relax \edef\fbox@tempa{\strip@pt\@tempdima}% \edef\fbox@tempb{\strip@pt\@tempdimb}% \pIIe@ellip@sincost{\fbox@tempa}{\fbox@tempb}% \@tempdima\@ellipcosone\@ovro \@tempdimb\@ellipsinone\@ovri \@tempdimc\@ellipcostwo\@ovro \@tempdimd\@ellipsintwo\@ovri \advance\@tempdimc by -\@tempdima% \advance\@tempdimd by -\@tempdimb% \pIIe@ellip@csqrt{\@tempdimc}{\@tempdimd}{\dimen@}% %\typeout{ distance: \the\dimen@, from (x,y)=(\the\@tempdimc,\the\@tempdimd), radii=(\the#1,\the#2), angles=(\the#3,\the#4)}% \fi \edef#5{\the\dimen@}% } % ------------------------------------------------------------------------------ % Borders using the picture environment % ------------------------------------------------------------------------------ \newcommand*\fbox@border@pict{% \ifnum\option{/fbox/render/@ord}=2\relax% \begingroup \hbox{% \unitlength\p@ \begin{picture}(0,0)(0,\optionunit{/fbox/@border-box-height})% bottom-left is origin % markers \ontoggle{/fbox/show-markers}{% \linethickness{\option{/fbox/marker-width}}% \optioncolor{/fbox/marker-color}% \fbox@rect{0pt}{0pt}{\option{/fbox/@border-box-width}}{\option{/fbox/@border-box-height}}% \fbox@rect{\option{/fbox/border-left-width}}{\option{/fbox/border-\fbox@bottom-width}}% {\option{/fbox/@border-box-width}-\option{/fbox/border-right-width}}% {\option{/fbox/@border-box-height}-\option{/fbox/border-\fbox@top-width}}%S }% %compute corner coordinates \fbox@border@calccorners %put down the background color \fbox@border@colorbackground \option{/fbox/picture-insert-before}% %put down the sides \fbox@border@side{3}{-2}{0}%top \fbox@border@side{5}{-4}{3}%left \fbox@border@side{-6}{7}{2}%bottom \fbox@border@side{-8}{1}{1}%right \end{picture}% }% \endgroup \fi } \newcommand*\fbox@border@pict@after{% \ifnum\option{/fbox/render/@ord}=2\relax% \letoption{/fbox/picture-insert-after}\fbox@insertafter \eifblank{\fbox@insertafter}{}{% \begingroup \hbox{% \begin{picture}(0,0)(0,0)% bottom-left is origin \fbox@insertafter \end{picture}% }% \endgroup }% \fi } \newcommand*\fbox@border@side[3]{% \fbox@setoct@angles{#1}% \edef\fbox@style{\option{/fbox/border-\fbox@side-style}}% \optioncolor{/fbox/border-\fbox@side-color}% \option{/fbox/picture-side-insert-before}% \ifcsdef{fbox@border@pict@\fbox@style}% {\csuse{fbox@border@pict@\fbox@style}{#1}{#2}{#3}}% {\PackageWarning{longfbox}{Unknown style "\fbox@style". Using "solid" instead.}% \fbox@border@pict@solid{#1}{#2}{#3}}% \option{/fbox/picture-side-insert-after}% } % ------------------------------------------------------------------------------ % Define standard border styles for the picture environment % % a style has the form \fbox@border@pict@