- Fix WrapBoxout.

- Migrate from wrapfig2 to wrapstuff.
- Miscellaneous improvements.
This commit is contained in:
2025-09-10 16:32:35 -05:00
parent d0e3687583
commit d1fd2fef22
7 changed files with 244 additions and 165 deletions

View File

@@ -9,7 +9,7 @@
\RequirePackage{PrimeTeX/packages/Color} \RequirePackage{PrimeTeX/packages/Color}
\RequirePackage{PrimeTeX/packages/CrossRef} %\RequirePackage{PrimeTeX/packages/CrossRef}
\RequirePackage{PrimeTeX/packages/DocProperties} \RequirePackage{PrimeTeX/packages/DocProperties}

View File

@@ -56,7 +56,7 @@
O{} O{}
% #4: Body, passed to @boxout. % #4: Body, passed to @boxout.
+b +b
}{% }{ \group_begin:
\keys_set:nn{Boxout}{#1} \keys_set:nn{Boxout}{#1}
\bool_if:nT \l_Boxout_warning_bool { \bool_if:nT \l_Boxout_warning_bool {
\colorlet{boxoutBG}{warningBG} \colorlet{boxoutBG}{warningBG}
@@ -75,7 +75,7 @@
#4\\ #4\\
\end{tblrBoxout} \end{tblrBoxout}
} }
}{} \group_end: }{}
\keys_define:nn{}{ \keys_define:nn{}{
BigBoxout .inherit:n = BigFloat, BigBoxout .inherit:n = BigFloat,
@@ -91,41 +91,84 @@
O{} O{}
% #4: Body, passed to Boxout. % #4: Body, passed to Boxout.
+b +b
}{ }{ \group_begin:
\keys_set:nn{BigBoxout}{#1} \keys_set:nn{BigBoxout}{#1}
\begin{BigFloat}[ \begin{BigFloat}[
type = generic, type = generic,
overhang = \l_BigFloat_overhang_dim, overhang = \l_BigFloat_overhang_dim,
placement:e = \l_Float_placement_clist, placement:e = \l_Float_placement_clist,
offset = \l_BigFloat_offset_fp, offset = \l_BigFloat_offset_fp,
]% ]
\begin{Boxout}[% \begin{Boxout}[
innerspec:e = \l_Boxout_innerspec_tl, innerspec:e = \l_Boxout_innerspec_tl,
warning:e = \bool_to_str:N \l_Boxout_warning_bool, warning:e = \bool_to_str:N \l_Boxout_warning_bool,
]{#2}[#3] ]{#2}[#3]
#4 #4
\end{Boxout} \end{Boxout}
\end{BigFloat} \end{BigFloat}
}{} \group_end: }{}
\str_const:Nn \c_WrapBoxout_position_str {o} \str_const:Nn \c_MarginBoxout_position_str {auto}
\dim_const:Nn \c_WrapBoxout_offset_dim {\marparwidth} \dim_const:Nn \c_MarginBoxout_width_dim {\marginparwidth}
\dim_const:Nn \c_WrapBoxout_width_dim {3in}
\keys_define:nn{}{
MarginBoxout .inherit:n = Boxout,
}
\keys_define:nn{MarginBoxout}{
position .choices:nn = {auto,reverse,left,right,nearest}{
\str_set:Ne \l_MarginBoxout_position_str {\l_keys_choice_tl}
},
position .initial:e = {\c_MarginBoxout_position_str},
width .dim_set:N = \l_MarginBoxout_width_dim,
width .initial:e = {\c_MarginBoxout_width_dim},
}
\NewDocumentEnvironment{MarginBoxout}{
% #1: Key-value options.
O{}
% #2: Label.
>{\TrimSpaces}m
% #3: Caption
O{}
% #4: Body.
+b
}{ \group_begin:
\keys_set:nn {MarginBoxout} {#1}
\marginalia[
width = \l_MarginBoxout_width_dim,
]{
\begin{Boxout}[
innerspec:e = \l_Boxout_innerspec_tl,
warning:e = \bool_to_str:N \l_Boxout_warning_bool,
]{#2}[#3]
#4
\end{Boxout}
}
\group_end: }{}
\tl_const:Nn \c_WrapBoxout_position_tl {o}
\tl_const:Ne \c_WrapBoxout_offset_tl {\marparwidth}
\tl_const:Nn \c_WrapBoxout_width_tl {3in}
\keys_define:nn{}{ \keys_define:nn{}{
WrapBoxout .inherit:n = Boxout, WrapBoxout .inherit:n = Boxout,
} }
\keys_define:nn{WrapBoxout}{ \keys_define:nn{WrapBoxout}{
position .choices:nn = {L,l,R,r,I,i,O,o}{ position .choices:nn = {l,r,c,i,o}{
\str_set:Nn \l_WrapBoxout_position_str {\l_keys_choice_tl} \tl_set:Nn \l_WrapBoxout_position_tl {\l_keys_choice_tl}
}, },
position .initial:e = {\c_WrapBoxout_position_str}, position .initial:e = {\c_WrapBoxout_position_tl},
position .default:e = {\c_WrapBoxout_position_tl},
offset .dim_set:N = \l_WrapBoxout_offset_dim, offset .tl_set:N = \l_WrapBoxout_offset_tl,
offset .initial:e = {\c_WrapBoxout_offset_dim}, offset .initial:e = {\c_WrapBoxout_offset_tl},
offset .default:e = {\c_WrapBoxout_offset_tl},
width .dim_set:N = \l_WrapBoxout_width_dim, width .tl_set:N = \l_WrapBoxout_width_tl,
width .initial:e = {\c_WrapBoxout_width_dim}, width .initial:e = {\c_WrapBoxout_width_tl},
width .default:e = {\c_WrapBoxout_width_tl},
} }
\NewDocumentEnvironment{WrapBoxout}{ \NewDocumentEnvironment{WrapBoxout}{
@@ -137,16 +180,20 @@
O{} O{}
% #4: Body. % #4: Body.
+b +b
}{% }{ \group_begin:
%\keys_set:nn{WrapBoxout}{position,offset,width}
\keys_set:nn{WrapBoxout}{#1} \keys_set:nn{WrapBoxout}{#1}
\begin{wrapfigure}{\l_WrapBoxout_position_str}[\l_WrapBoxout_offset_dim]% \expanded{\noexpand\begin{wrapstuff}[
\begin{minipage}{\l_WrapBoxout_width_dim}% \l_WrapBoxout_position_tl,
hoffset = \l_WrapBoxout_offset_tl,
]}%{\l_WrapBoxout_position_tl}[\l_WrapBoxout_offset_tl]}
\expanded{\noexpand\begin{minipage}{\l_WrapBoxout_width_tl}}
\begin{Boxout}[ \begin{Boxout}[
innerspec:e = \l_Boxout_innerspec_tl, innerspec:e = \l_Boxout_innerspec_tl,
warning:e = \bool_to_str:N \l_Boxout_warning_bool, warning:e = \bool_to_str:N \l_Boxout_warning_bool,
]{#2}[#3]% ]{#2}[#3]
#4% #4
\end{Boxout}% \end{Boxout}
\end{minipage}% \end{minipage}
\end{wrapfigure}% \end{wrapstuff}
}{} \group_end: }{}

View File

@@ -1,22 +1,24 @@
\NeedsTeXFormat{LaTeX2e} \NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{PrimeTeX/packages/Caption}[2025-08-20] \ProvidesExplPackage{PrimeTeX/packages/Caption}{2025-09-10}{1.0}{
Custom Caption commands.
\RequirePackage[
hypcap=true,
]{caption}
\captionsetup{
justification = Centering,
font = {
small,
color=caption,
},
} }
% \RequirePackage[
% hypcap=true,
% ]{caption}
% \captionsetup{
% justification = Centering,
% font = {
% small,
% color=caption,
% },
% }
% Define a justification style that is ragged on the side toward the outside of % Define a justification style that is ragged on the side toward the outside of
% the page. I. e. RaggedRight on % the page. I. e. RaggedRight on
% \RequirePackage{changepage} %\RequirePackage{changepage}
\DeclareCaptionJustification{RaggedOutside}{% \NewDocumentCommand{\RaggedOutside}{}{
\ifthenelse{\boolean{isElectronic}}{% \ifthenelse{\boolean{isElectronic}}{%
\RaggedRight% \RaggedRight%
}{% }{%
@@ -29,15 +31,24 @@
}% }%
} }
\ExplSyntaxOn \cs_new:Nn \__MyCaption_format_default: {\centering\small\color{caption}}
\keys_define:nn {MyCaption} { \keys_define:nn {MyCaption} {
before .bool_set:N = \l_MyCaption_before_bool,
before .initial:n = {false},
figure .code:n = {\str_set:Nn \l_MyCaption_type_str {figure}}, figure .code:n = {\str_set:Nn \l_MyCaption_type_str {figure}},
format .tl_set:N = \l_MyCaption_format_tl, format .cs_set_protected:Np = \__MyCaption_format:,
format .initial:n = {\Centering\small\color{caption}}, format .initial:n = {\__MyCaption_format_default:},
table .code:n = {\str_set:Nn \l_MyCaption_type_str {table}}, skip .tl_set:N = \l_MyCaption_skip_tl,
skip .initial:n = {\medskipamount},
table .code:n = {
\str_set:Nn \l_MyCaption_type_str {table}
\bool_set:Nn \l_MyCaption_before_bool {true}
},
type .choices:nn = {figure,table}{ type .choices:nn = {figure,table}{
\str_set:Ne \l_MyCaption_type_str {\l_keys_choice_tl} \str_set:Ne \l_MyCaption_type_str {\l_keys_choice_tl}
@@ -45,37 +56,52 @@
type .initial:n = {figure}, type .initial:n = {figure},
} }
\tl_new:N \l_MyCaption_label_tl \str_new:N \l_MyCaption_label_str
\tl_new:N \l_MyCaption_number_tl \str_new:N \l_MyCaption_number_str
\NewDocumentCommand{\MyCaption}{ \NewDocumentEnvironment{MyCaption}{
% #1: Key-value options. % #1: Key-value options.
O{} O{}
% #2: Label % #2: Label
m m
% #3: Caption % #3: Caption
m m
}{ \group_begin: }{
\keys_set:nn {MyCaption} {#1} \group_begin:
\str_case:en {\l_MyCaption_type_str} { \keys_set:nn {MyCaption} {#1}
{figure} { \str_case:en {\l_MyCaption_type_str} {
\addtocounter{figure}{1} {figure} {
\tl_set:Nn \l_MyCaption_label_tl {Figure} \refstepcounter{figure}
\tl_set:Nn \l_MyCaption_number_tl { \str_set:Nn \l_MyCaption_label_str {Figure}
\arabic{chapter}.\arabic{figure} \str_set:Ne \l_MyCaption_number_str {
\arabic{chapter}.\arabic{figure}
}
\addcontentsline{lof}{figure}{\protect\numberline{\l_MyCaption_number_str}\protect\ignorespaces~#3}
} }
\addcontentsline{lof}{figure}{\l_MyCaption_number_tl\numberline#3} {table} {
} \refstepcounter{table}
{table} { \str_set:Nn \l_MyCaption_label_str {Table}
\addtocounter{table}{1} \str_set:Ne \l_MyCaption_number_str {
\tl_set:Nn \l_MyCaption_label_tl {Table} \arabic{chapter}.\arabic{table}
\tl_set:Nn \l_MyCaption_number_tl { }
\arabic{chapter}.\arabic{table} \addcontentsline{lot}{table}{\protect\numberline{\l_MyCaption_number_str}\protect\ignorespaces~#3}
} }
\addcontentsline{lot}{table}{\l_MyCaption_number_tl\numberline#3}
} }
}
\l_MyCaption_format_tl \bool_if:NT \l_MyCaption_before_bool {
\l_MyCaption_label_tl~\l_MyCaption_number_tl :~#3 \__MyCaption_insert_caption:nn {#2} {#3}
\label{#2} }
\group_end: } }{
\bool_if:NF \l_MyCaption_before_bool {
\__MyCaption_insert_caption:nn {#2} {#3}
}
\group_end:
}
\cs_new:Nn \__MyCaption_insert_caption:nn {
\setlength{\parskip}{\l_MyCaption_skip_tl}\par
\__MyCaption_format:
\l_MyCaption_label_str{}~\l_MyCaption_number_str :~#2
\label{#1}
\par
}

View File

@@ -6,18 +6,12 @@
\RequirePackage{PrimeTeX/packages/Layout} \RequirePackage{PrimeTeX/packages/Layout}
% I think this redefines how float environments evaluate the placement argument,
% allowing a command in the argument to be expanded before it is used. Otherwise
% it thinks we are trying to use the literal command name as the placement.
\def\ExpEnvOption#1#2[#3]{
\expandafter\@expenvopt\expandafter{#3}{#1}{#2}
}
\def\@expenvopt#1#2#3{#2{#3}[#1]}
\RequirePackage{float} \RequirePackage{float}
\floatstyle{plain} \floatstyle{plain}
\newfloat{generic}{htpb}{lgf} \newfloat{generic}{htpb}{lgf}
%\floatplacement{figure}{htpb}
%\floatplacement{table}{htpb}
% Function for converting clists generated by multichoice keys into strings. % Function for converting clists generated by multichoice keys into strings.
\NewDocumentCommand{\clist_use_default:Nnnn}{ \NewDocumentCommand{\clist_use_default:Nnnn}{
@@ -95,8 +89,7 @@
\dim_set:Nn \l_BigFloat_workoverhang_dim { \dim_set:Nn \l_BigFloat_workoverhang_dim {
\dim_min:nn {\l_BigFloat_overhang_dim} {\l_BigFloat_maxoverhang_dim} \dim_min:nn {\l_BigFloat_overhang_dim} {\l_BigFloat_maxoverhang_dim}
} }
\ExpEnvOption \expanded{\noexpand\begin{\l_BigFloat_type_str}[\l_BigFloat_placement_str]}% float environment
\begin{\l_BigFloat_type_str}[\l_BigFloat_placement_str]% float environment
\begin{SmartAdjustWidth}{ \begin{SmartAdjustWidth}{
\fp_to_dim:n { \fp_to_dim:n {
-\l_BigFloat_workoverhang_dim -\l_BigFloat_workoverhang_dim
@@ -116,7 +109,7 @@
} }
\end{minipage} \end{minipage}
\end{SmartAdjustWidth} \end{SmartAdjustWidth}
\end{\l_BigFloat_type_str} \expanded{\noexpand\end{\l_BigFloat_type_str}}
\group_end: }{} \group_end: }{}
\clist_const:Nn \c_CenterFig_placement_clist {h, t, p, b} \clist_const:Nn \c_CenterFig_placement_clist {h, t, p, b}
@@ -141,12 +134,14 @@
\clist_use_default:Nnnn \l_CenterFig_placement_str \clist_use_default:Nnnn \l_CenterFig_placement_str
{\l_Float_placement_clist} {\l_Float_placement_clist}
{\c_Float_placement_clist} {\c_Float_placement_clist}
\ExpEnvOption %\ExpEnvOption
\begin{figure}[\l_CenterFig_placement_str] \expanded{\noexpand\begin{figure}[\l_CenterFig_placement_str]}
\Centering \begin{MyCaption}{fig:#4}{#5}
\includegraphics[keepaspectratio,#1]{#3} \Centering
\caption{#5} \includegraphics[keepaspectratio,#1]{#3}
\label{fig:#4} \end{MyCaption}
% \caption{#5}
% \label{fig:#4}
\end{figure} \end{figure}
\group_end: } \group_end: }
@@ -202,10 +197,12 @@
placement:e = \l_Float_placement_clist, placement:e = \l_Float_placement_clist,
offset = \l_BigFloat_offset_fp, offset = \l_BigFloat_offset_fp,
] ]
\captionsetup{type=figure} %\captionsetup{type=figure}
\includegraphics[keepaspectratio,width=\linewidth]{#2} \begin{MyCaption}{fig:#3}{#4}
\Centering\captionof{figure}{#4} \includegraphics[keepaspectratio,width=\linewidth]{#2}
\label{fig:#3} \end{MyCaption}
% \Centering\captionof{figure}{#4}
% \label{fig:#3}
\end{BigFloat} \end{BigFloat}
\group_end: } \group_end: }
@@ -242,7 +239,7 @@
\keys_set:nn{DoubleBigFig}{#1} \keys_set:nn{DoubleBigFig}{#1}
\begin{BigFloat}[ \begin{BigFloat}[
type = generic, type = figure,
overhang = \l_BigFloat_overhang_dim, overhang = \l_BigFloat_overhang_dim,
placement:e = \l_Float_placement_clist, placement:e = \l_Float_placement_clist,
offset = \l_BigFloat_offset_fp, offset = \l_BigFloat_offset_fp,
@@ -264,18 +261,13 @@
rightspace = 0pt, rightspace = 0pt,
}, },
} }
%\captionsetup{type=figure} \begin{MyCaption}{fig:#3}{#4}
\includegraphics[keepaspectratio,width=\textwidth]{#2} \includegraphics[keepaspectratio,width=\linewidth]{#2}
\par \end{MyCaption}
\MyCaption{fig:#3}{#4}\\ \\
% \Centering\captionof{figure}{#4} \begin{MyCaption}{fig:#6}{#7}
% \label{fig:#3}\\ \includegraphics[keepaspectratio,width=\linewidth]{#5}
%\captionsetup{type=figure} \end{MyCaption}
\includegraphics[keepaspectratio,width=\textwidth]{#5}
\par
\MyCaption{fig:#6}{#7}
% \Centering\captionof{figure}{#7}
% \label{fig:#6}
\end{tblr} \end{tblr}
\end{BigFloat} \end{BigFloat}
\group_end: } \group_end: }
@@ -326,7 +318,7 @@
\keys_set:nn{TwinFig}{#1} \keys_set:nn{TwinFig}{#1}
\begin{BigFloat}[ \begin{BigFloat}[
type = {generic}, type = {figure},
overhang = \l_BigFloat_overhang_dim, overhang = \l_BigFloat_overhang_dim,
placement:e = \l_Float_placement_clist, placement:e = \l_Float_placement_clist,
offset = \l_BigFloat_offset_fp, offset = \l_BigFloat_offset_fp,
@@ -349,21 +341,25 @@
}, },
} }
\vfill \vfill
\captionsetup{type=figure} %\captionsetup{type=figure}
\includegraphics[ \begin{MyCaption}{fig:#3}{#4}
keepaspectratio,width=\l_TwinFig_width_dim \includegraphics[
]{#2} keepaspectratio,width=\l_TwinFig_width_dim
\captionof{figure}{#4} ]{#2}
\label{fig:#3} \end{MyCaption}
% \captionof{figure}{#4}
% \label{fig:#3}
\vfill \vfill
& &
\vfill \vfill
\captionsetup{type=figure} % \captionsetup{type=figure}
\includegraphics[ \begin{MyCaption}{fig:#6}{#7}
keepaspectratio,width=\l_TwinFig_width_dim \includegraphics[
]{#5} keepaspectratio,width=\l_TwinFig_width_dim
\captionof{figure}{#7} ]{#5}
\label{fig:#6} \end{MyCaption}
% \captionof{figure}{#7}
% \label{fig:#6}
\vfill \vfill
\\ \\
\end{tblr} \end{tblr}

View File

@@ -7,7 +7,7 @@
\RequirePackage{calc} \RequirePackage{calc}
\RequirePackage{wrapfig2} \RequirePackage{wrapstuff}
\dim_const:Nn \c_Graphics_icon_dim {0.25in} \dim_const:Nn \c_Graphics_icon_dim {0.25in}
@@ -44,40 +44,41 @@
\includegraphics[keepaspectratio,#1]{#2}% \includegraphics[keepaspectratio,#1]{#2}%
} }
\NewDocumentCommand{\@wrapfigbody}{m m m m}{ \str_const:Nn \c_WrapFig_placement_str {o}
\captionsetup{type=figure}% \dim_const:Nn \c_WrapFig_hoffset_dim {\marparwidth}
\capstart%
\includegraphics[% \keys_define:nn {WrapFig} {
keepaspectratio,% placement .choices:nn = {l,r,c,i,o}{
#2% \str_set:Ne \l_WrapFig_placement_str {\l_keys_choice_tl}
]{#1}% },
\Centering\captionof{figure}{#4}% placement .initial:e = {\c_WrapFig_placement_str},
\label{fig:#3}%
hoffset .dim_set:N = \l_WrapFig_hoffset_dim,
hoffset .initial:e = {\c_WrapFig_hoffset_dim},
} }
\NewDocumentCommand{\wrapfig}{ \NewDocumentCommand{\WrapFig}{
% #1: alignment [l,r,i,o] % #1: Key-value options
O{O}
% #2: horizontal_offset
O{\marparwidth}
% #3: graphic_file
m
% #4: (width|height)=lengthvalue
O{} O{}
% #5: label % #2: graphic_file
m
% #3: Options passed to \includegraphics
O{}
% #4: label
>{\TrimSpaces}m >{\TrimSpaces}m
% #6: caption % #5: caption
m% m
% #7: indented lines override }{ \group_begin:
o \keys_set:nn {WrapFig} {#1}
}{% \expanded{\noexpand\begin{wrapstuff}[
\IfNoValueTF{#7}{% \l_WrapFig_placement_str,
\begin{wrapfigure}{#1}[#2]% hoffset = \l_WrapFig_hoffset_dim,
\@wrapfigbody{#3}{#4}{#5}{#6}% ]}
\end{wrapfigure}% \begin{MyCaption}{fig:#4}{#5}
}{% \includegraphics[%
\begin{wrapfigure}[#7]{#1}[#2]% keepaspectratio,%
\@wrapfigbody{#3}{#4}{#5}{#6}% #3%
\end{wrapfigure}% ]{#2}%
}% \end{MyCaption}
} \end{wrapstuff}
\group_end: }

View File

@@ -95,7 +95,12 @@
% N.B.: floatpagefraction MUST be less than topfraction !! % N.B.: floatpagefraction MUST be less than topfraction !!
\renewcommand{\dblfloatpagefraction}{0.8} % require fuller float pages \renewcommand{\dblfloatpagefraction}{0.8} % require fuller float pages
\NewDocumentEnvironment{SmartAdjustWidth}{O{\boolean{isElectronic}} m m +b}{% \NewDocumentEnvironment{SmartAdjustWidth}{
O{\boolean{isElectronic}}
m
m
+b
}{%
\ifthenelse{#1}{% \ifthenelse{#1}{%
\begin{adjustwidth}{#2}{#3}% \begin{adjustwidth}{#2}{#3}%
#4% #4%

View File

@@ -79,12 +79,16 @@
\strut% \strut%
\marginalia{% \marginalia{%
\MarginHyperSetup% \MarginHyperSetup%
\captionsetup{% % \captionsetup{%
type = figure,% % type = figure,%
justification = RaggedOutside,% % justification = RaggedOutside,%
}% % }%
\Centering\includegraphics[keepaspectratio,#1]{#2}\par% \begin{MyCaption}[
\noindent\captionof{figure}{#4}% format={\RaggedOutside\small\color{caption}}
\label{fig:#3}% ]{fig:#3}{#4}
\Centering\includegraphics[keepaspectratio,#1]{#2}%
\end{MyCaption}
% \noindent\captionof{figure}{#4}%
% \label{fig:#3}%
}% }%
} }