| 1 |
% |
| 2 |
% dblatex - Contains miscellaneous latex macros |
| 3 |
% |
| 4 |
% |
| 5 |
|
| 6 |
%% |
| 7 |
%% Redefine the `float' behaviour so that it can split over pages. |
| 8 |
%% Actually there's nothing floating anymore, but the float style is preserved. |
| 9 |
%% The XSLT templates must be redefined to call this macro instead. |
| 10 |
%% - #1: float name |
| 11 |
%% - #2: caption material (including the \caption macro call) |
| 12 |
%% |
| 13 |
%% It assumes that floats are created with \newfloat and it |
| 14 |
%% uses some internal macros of float.sty to emulate the same environment. |
| 15 |
%% It is compatible with \caption redefined by caption.sty. |
| 16 |
%% |
| 17 |
\newenvironment{longfloat}[2]{ |
| 18 |
\@nameuse{fst@#1}% |
| 19 |
\def\@captype{#1}\setbox\@floatcapt=\vbox{}% |
| 20 |
\def\@capcontent{#2} % caption material |
| 21 |
\vspace{2\parskip}\pagebreak[3] |
| 22 |
\@parboxrestore% |
| 23 |
\@fs@pre\@fs@iftopcapt% |
| 24 |
\@capcontent% |
| 25 |
\ifvoid\@floatcapt\else\unvbox\@floatcapt\par\@fs@mid\fi% |
| 26 |
\else\fi% |
| 27 |
}{ |
| 28 |
\@fs@iftopcapt\else% |
| 29 |
\@capcontent% |
| 30 |
\ifvoid\@floatcapt\else\par\@fs@mid\unvbox\@floatcapt\fi |
| 31 |
\fi\par\@fs@post\vskip\z@% |
| 32 |
\vspace{2mm} |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
%% |
| 37 |
%% New listing environment based upon the fancyvrb environment. Its role |
| 38 |
%% is to handle the specific `scale' option. |
| 39 |
%% |
| 40 |
%% Author: Jean-Côme Charpentier. |
| 41 |
%% |
| 42 |
\RequirePackage{fancyvrb} |
| 43 |
\lstset{fancyvrb=true} |
| 44 |
|
| 45 |
\newbox\lstbox |
| 46 |
\newlength{\lstwidthw} |
| 47 |
|
| 48 |
|
| 49 |
%%% New listing option to scale the listing to fit the page width |
| 50 |
\lst@Key{scale}{true}[t]{\lstKV@SetIf{#1}\lst@ifscale} |
| 51 |
|
| 52 |
%%% Remember the original fancyvrb macro to handle options |
| 53 |
\let\FV@UseKeyValuesOrig\FV@UseKeyValues |
| 54 |
|
| 55 |
\def\code{\FV@Environment{}{lstcode}} |
| 56 |
\def\FVB@lstcode{% |
| 57 |
% Just dump the listing into a file, skip the options used later |
| 58 |
\let\FV@UseKeyValues\relax |
| 59 |
\FVB@VerbatimOut{lst.tmp}} |
| 60 |
|
| 61 |
\def\FVE@lstcode{% |
| 62 |
\FVE@VerbatimOut |
| 63 |
\let\FV@UseKeyValues\FV@UseKeyValuesOrig |
| 64 |
% Now, apply the passed options |
| 65 |
\expandafter\lstset\expandafter{\FV@KeyValues} |
| 66 |
% Is there any scaling required? |
| 67 |
\lst@ifscale |
| 68 |
\lst@ifbreaklines |
| 69 |
\lstwidthw=\lst@linewidth |
| 70 |
\else |
| 71 |
% Force the style to perform a valid fontsize scaling |
| 72 |
\lstset{basicstyle=\ttfamily} |
| 73 |
\begin{lrbox}{\lstbox} |
| 74 |
\lstinputlisting{lst.tmp}% |
| 75 |
\end{lrbox} |
| 76 |
\settowidth{\lstwidthw}{\usebox{\lstbox}} |
| 77 |
\fi |
| 78 |
\ifdim\lstwidthw>\linewidth |
| 79 |
% Compute real width with basic font to perform consistent scaling |
| 80 |
\lst@ifbreaklines |
| 81 |
\setlength{\lstwidthw}{\lstwidthw*% |
| 82 |
\ratio{\lstcharwidthb}{\lstcharwidth}} |
| 83 |
\fi |
| 84 |
\lstset{basicstyle=\ttfamily} |
| 85 |
\typeout{Listing width <\the\lstwidthw> scaled to fit in <\the\linewidth>} |
| 86 |
% Compute the width ratio |
| 87 |
\edef\r@tio{\the\numexpr \linewidth/(\lstwidthw/1000)-1}% |
| 88 |
\begingroup |
| 89 |
\@tempdima\f@size pt |
| 90 |
\typeout{\the\@tempdima} |
| 91 |
\@tempdima 0.\r@tio\@tempdima |
| 92 |
\typeout{\the\@tempdima} |
| 93 |
% interlignage = 1.2 x font size |
| 94 |
\@tempdimb 1.2\@tempdima |
| 95 |
% Redefine the fontsize to apply |
| 96 |
\fontsize{\@tempdima}{\@tempdimb}% |
| 97 |
% Print out the listing with this new size |
| 98 |
\lstinputlisting[linewidth=\linewidth]{lst.tmp}% |
| 99 |
\endgroup |
| 100 |
\else |
| 101 |
% The listing fits in the available width, do nothing special |
| 102 |
\lstinputlisting{lst.tmp}% |
| 103 |
\fi |
| 104 |
\else |
| 105 |
% No scaling, do as usual |
| 106 |
\lstinputlisting{lst.tmp} |
| 107 |
\fi |
| 108 |
%\strut |
| 109 |
} |
| 110 |
\DefineVerbatimEnvironment{lstcode}{lstcode}{} |
| 111 |
|
| 112 |
% Redefine \lst@DeInit to disable page break after the listing |
| 113 |
\def\lst@DeInit{% |
| 114 |
\lst@XPrintToken |
| 115 |
\lst@EOLUpdate |
| 116 |
\global\advance\lst@newlines\m@ne |
| 117 |
\lst@ifshowlines |
| 118 |
\lst@DoNewLines |
| 119 |
\else |
| 120 |
\setbox\@tempboxa\vbox{\lst@DoNewLines}% |
| 121 |
\fi |
| 122 |
\lst@ifdisplaystyle |
| 123 |
\par\nobreak |
| 124 |
\removelastskip |
| 125 |
\fi |
| 126 |
\lsthk@ExitVars |
| 127 |
\everypar{}% |
| 128 |
\lsthk@DeInit |
| 129 |
\normalbaselines |
| 130 |
\normalcolor |
| 131 |
\lst@MakeCaption b% |
| 132 |
\lst@ifbox |
| 133 |
\egroup |
| 134 |
$% |
| 135 |
\hss |
| 136 |
\egroup |
| 137 |
\vrule\@width\lst@maxwidth\@height\z@\@depth\z@ |
| 138 |
\else |
| 139 |
\lst@ifdisplaystyle |
| 140 |
\@tempdima\lst@belowskip |
| 141 |
\ifdim\@tempdima<\z@ |
| 142 |
\par\nobreak |
| 143 |
\vspace{-\@tempdima}% |
| 144 |
\else |
| 145 |
\par\penalty-50 |
| 146 |
\vspace\lst@belowskip |
| 147 |
\fi |
| 148 |
\fi |
| 149 |
\fi |
| 150 |
\ifx\lst@multicols\@empty\else |
| 151 |
\def\lst@next{\global\let\@checkend\@gobble |
| 152 |
\endmulticols |
| 153 |
\global\let\@checkend\lst@@checkend |
| 154 |
}% |
| 155 |
\expandafter\lst@next |
| 156 |
\fi |
| 157 |
\ifx\lst@float\relax\else |
| 158 |
\expandafter\lst@endfloat |
| 159 |
\fi |
| 160 |
\endgroup |
| 161 |
} %$ |
| 162 |
|