- Improve wrap objects.

- Debug.
This commit is contained in:
2025-09-11 16:42:59 -05:00
parent d1fd2fef22
commit 0e68ac723d
6 changed files with 130 additions and 102 deletions

View File

@@ -1,5 +1,10 @@
\ProvidesFile{commonincludes.def}[2025-09-02 v1.0] \ProvidesFile{commonincludes.def}[2025-09-02 v1.0]
% Load graphicx first because the menukeys package (in Fonts.sty) causes a conflict.
% Graphics package for including images
\RequirePackage[final]{graphicx}
\RequirePackage{graphbox}
% A lot of other packages require Layout, so load it first. % A lot of other packages require Layout, so load it first.
\RequirePackage{PrimeTeX/packages/Layout} \RequirePackage{PrimeTeX/packages/Layout}
@@ -9,16 +14,10 @@
\RequirePackage{PrimeTeX/packages/Color} \RequirePackage{PrimeTeX/packages/Color}
%\RequirePackage{PrimeTeX/packages/CrossRef}
\RequirePackage{PrimeTeX/packages/DocProperties} \RequirePackage{PrimeTeX/packages/DocProperties}
\RequirePackage{PrimeTeX/packages/Floats} \RequirePackage{PrimeTeX/packages/Floats}
% Load graphicx before Fonts because the menukeys package causes a conflict.
% Graphics package for including images
\RequirePackage[final]{graphicx}
\RequirePackage{PrimeTeX/packages/Fonts} \RequirePackage{PrimeTeX/packages/Fonts}
\RequirePackage{PrimeTeX/packages/Glossary} \RequirePackage{PrimeTeX/packages/Glossary}

View File

@@ -23,16 +23,13 @@
vlines = {0pt,boxoutBG}, vlines = {0pt,boxoutBG},
vline{1,Z} = {\boxoutrule,boxoutFG}, vline{1,Z} = {\boxoutrule,boxoutFG},
} }
% \SetTblrOuter[tblrBoxout]{
% expand+ = \l_Boxout_body_tl,
% }
\tl_const:Nn \c_Boxout_innerspec_tl {colspec={X[l,h]}} \tl_const:Nn \c_Boxout_innerspec_tl {colspec={X[l,h]}}
\bool_const:Nn \c_Boxout_warning_bool {\c_false_bool} \bool_const:Nn \c_Boxout_warning_bool {\c_false_bool}
\tl_new:N \l_Boxout_title_tl \tl_new:N \l_Boxout_title_tl
\keys_define:nn{Boxout}{ \keys_define:nn {Boxout} {
innerspec .tl_set_e:N= \l_Boxout_innerspec_tl, innerspec .tl_set_e:N= \l_Boxout_innerspec_tl,
innerspec .initial:e = {\c_Boxout_innerspec_tl}, innerspec .initial:e = {\c_Boxout_innerspec_tl},
innerspec .default:e = {\c_Boxout_innerspec_tl}, innerspec .default:e = {\c_Boxout_innerspec_tl},
@@ -42,11 +39,6 @@
warning .default:e = {true}, warning .default:e = {true},
} }
% \NewExpandableDocumentCommand{\__Boxout_body:Nnn}{m +m +m}{
% %\message{boxout~body~start}
% }
\NewDocumentEnvironment{Boxout}{ \NewDocumentEnvironment{Boxout}{
% #1: Key-value options. % #1: Key-value options.
O{} O{}
@@ -78,8 +70,7 @@
\group_end: }{} \group_end: }{}
\keys_define:nn{}{ \keys_define:nn{}{
BigBoxout .inherit:n = BigFloat, BigBoxout .inherit:n = {BigFloat, Boxout},
BigBoxout .inherit:n = Boxout,
} }
\NewDocumentEnvironment{BigBoxout}{ \NewDocumentEnvironment{BigBoxout}{
@@ -148,27 +139,15 @@
} }
\group_end: }{} \group_end: }{}
\tl_const:Nn \c_WrapBoxout_position_tl {o} \dim_const:Nn \c_WrapBoxout_width_dim {3in}
\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 = {WrapFig, Boxout},
} }
\keys_define:nn{WrapBoxout}{ \keys_define:nn{WrapBoxout}{
position .choices:nn = {l,r,c,i,o}{ width .dim_set:N = \l_WrapBoxout_width_dim,
\tl_set:Nn \l_WrapBoxout_position_tl {\l_keys_choice_tl} width .initial:e = {\c_WrapBoxout_width_dim},
}, width .default:e = {\c_WrapBoxout_width_dim},
position .initial:e = {\c_WrapBoxout_position_tl},
position .default:e = {\c_WrapBoxout_position_tl},
offset .tl_set:N = \l_WrapBoxout_offset_tl,
offset .initial:e = {\c_WrapBoxout_offset_tl},
offset .default:e = {\c_WrapBoxout_offset_tl},
width .tl_set:N = \l_WrapBoxout_width_tl,
width .initial:e = {\c_WrapBoxout_width_tl},
width .default:e = {\c_WrapBoxout_width_tl},
} }
\NewDocumentEnvironment{WrapBoxout}{ \NewDocumentEnvironment{WrapBoxout}{
@@ -181,19 +160,25 @@
% #4: Body. % #4: Body.
+b +b
}{ \group_begin: }{ \group_begin:
%\keys_set:nn{WrapBoxout}{position,offset,width}
\keys_set:nn{WrapBoxout}{#1} \keys_set:nn{WrapBoxout}{#1}
\__WrapFig_process_options:
% \message{
% WrapBoxout:~
% placement:~\l_WrapFig_placement_str,~
% hoffset:~\dim_use:N \l_WrapFig_hoffset_dim,~
% warning:~\bool_to_str:N \l_Boxout_warning_bool}
\expanded{\noexpand\begin{wrapstuff}[ \expanded{\noexpand\begin{wrapstuff}[
\l_WrapBoxout_position_tl, \l_WrapFig_placement_str,
hoffset = \l_WrapBoxout_offset_tl, hoffset = {\dim_use:N \l_WrapFig_hoffset_dim},
]}%{\l_WrapBoxout_position_tl}[\l_WrapBoxout_offset_tl]} \l_WrapFig_passed_keys_str,
\expanded{\noexpand\begin{minipage}{\l_WrapBoxout_width_tl}} ]}
%\begin{minipage}{\l_WrapBoxout_width_dim}
\begin{Boxout}[ \begin{Boxout}[
innerspec:e = \l_Boxout_innerspec_tl, innerspec:e = {\l_Boxout_innerspec_tl,columns={\dim_use:N \l_WrapBoxout_width_dim}},
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{wrapstuff} \end{wrapstuff}
\group_end: }{} \group_end: }{}

View File

@@ -40,7 +40,7 @@
figure .code:n = {\str_set:Nn \l_MyCaption_type_str {figure}}, figure .code:n = {\str_set:Nn \l_MyCaption_type_str {figure}},
format .cs_set_protected:Np = \__MyCaption_format:, format .cs_set_protected:Np = \__MyCaption_format:,
format .initial:n = {\__MyCaption_format_default:}, format .initial:n = {},%{\__MyCaption_format_default:},
skip .tl_set:N = \l_MyCaption_skip_tl, skip .tl_set:N = \l_MyCaption_skip_tl,
skip .initial:n = {\medskipamount}, skip .initial:n = {\medskipamount},
@@ -63,7 +63,7 @@
% #1: Key-value options. % #1: Key-value options.
O{} O{}
% #2: Label % #2: Label
m >{\TrimSpaces}m
% #3: Caption % #3: Caption
m m
}{ }{
@@ -100,7 +100,7 @@
\cs_new:Nn \__MyCaption_insert_caption:nn { \cs_new:Nn \__MyCaption_insert_caption:nn {
\setlength{\parskip}{\l_MyCaption_skip_tl}\par \setlength{\parskip}{\l_MyCaption_skip_tl}\par
\__MyCaption_format: \__MyCaption_format_default: \__MyCaption_format:
\l_MyCaption_label_str{}~\l_MyCaption_number_str :~#2 \l_MyCaption_label_str{}~\l_MyCaption_number_str :~#2
\label{#1} \label{#1}
\par \par

View File

@@ -10,8 +10,8 @@
\floatstyle{plain} \floatstyle{plain}
\newfloat{generic}{htpb}{lgf} \newfloat{generic}{htpb}{lgf}
%\floatplacement{figure}{htpb} \floatplacement{figure}{htpb}
%\floatplacement{table}{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}{
@@ -134,14 +134,11 @@
\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
\expanded{\noexpand\begin{figure}[\l_CenterFig_placement_str]} \expanded{\noexpand\begin{figure}[\l_CenterFig_placement_str]}
\begin{MyCaption}{fig:#4}{#5} \begin{MyCaption}{fig:#4}{#5}
\Centering \Centering
\includegraphics[keepaspectratio,#1]{#3} \includegraphics[keepaspectratio,#1]{#3}
\end{MyCaption} \end{MyCaption}
% \caption{#5}
% \label{fig:#4}
\end{figure} \end{figure}
\group_end: } \group_end: }
@@ -197,12 +194,9 @@
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}
\begin{MyCaption}{fig:#3}{#4} \begin{MyCaption}{fig:#3}{#4}
\includegraphics[keepaspectratio,width=\linewidth]{#2} \includegraphics[keepaspectratio,width=\linewidth]{#2}
\end{MyCaption} \end{MyCaption}
% \Centering\captionof{figure}{#4}
% \label{fig:#3}
\end{BigFloat} \end{BigFloat}
\group_end: } \group_end: }
@@ -279,6 +273,8 @@
\ProvideLength{\TwinFigWidth}[\dim_use:N \c_TwinFig_width_dim] \ProvideLength{\TwinFigWidth}[\dim_use:N \c_TwinFig_width_dim]
\fp_new:N \l_TwinFig_valign_offset_fp
\keys_define:nn {} { \keys_define:nn {} {
TwinFig .inherit:n = {BigFloat}, TwinFig .inherit:n = {BigFloat},
} }
@@ -315,7 +311,6 @@
% The following is a hack to keep the figure counter from incrementing by 4 % The following is a hack to keep the figure counter from incrementing by 4
% instead of 2. Replace it with a proper solution if you find one. % instead of 2. Replace it with a proper solution if you find one.
\addtocounter{figure}{-2} \addtocounter{figure}{-2}
\keys_set:nn{TwinFig}{#1} \keys_set:nn{TwinFig}{#1}
\begin{BigFloat}[ \begin{BigFloat}[
type = {figure}, type = {figure},
@@ -324,7 +319,8 @@
offset = \l_BigFloat_offset_fp, offset = \l_BigFloat_offset_fp,
] ]
\begin{tblr}{ \begin{tblr}{
colspec = {*{2}{Q[c,wd=\l_TwinFig_width_dim]}}, colspec = {*{2}{Q[c,wd=\l_TwinFig_width_dim,]}},
cells = {font=\mdseries},
rows:e = {\l_TwinFig_valign_str}, rows:e = {\l_TwinFig_valign_str},
hlines = {0pt}, hlines = {0pt},
hborder{1-Z} = { hborder{1-Z} = {
@@ -340,27 +336,21 @@
rightspace = \l_TwinFig_space_dim, rightspace = \l_TwinFig_space_dim,
}, },
} }
\vfill
%\captionsetup{type=figure}
\begin{MyCaption}{fig:#3}{#4} \begin{MyCaption}{fig:#3}{#4}
\includegraphics[ \includegraphics[
keepaspectratio,width=\l_TwinFig_width_dim keepaspectratio,
align = c,
width = \l_TwinFig_width_dim,
]{#2} ]{#2}
\end{MyCaption} \end{MyCaption}
% \captionof{figure}{#4}
% \label{fig:#3}
\vfill
& &
\vfill
% \captionsetup{type=figure}
\begin{MyCaption}{fig:#6}{#7} \begin{MyCaption}{fig:#6}{#7}
\includegraphics[ \includegraphics[
keepaspectratio,width=\l_TwinFig_width_dim keepaspectratio,
align = c,
width = \l_TwinFig_width_dim,
]{#5} ]{#5}
\end{MyCaption} \end{MyCaption}
% \captionof{figure}{#7}
% \label{fig:#6}
\vfill
\\ \\
\end{tblr} \end{tblr}
\end{BigFloat} \end{BigFloat}

View File

@@ -44,17 +44,35 @@
\includegraphics[keepaspectratio,#1]{#2}% \includegraphics[keepaspectratio,#1]{#2}%
} }
\dim_const:Nn \c_WrapFig_hoffset_dim {0in}
\dim_const:Nn \c_WrapFig_im_hoffset_dim {1in}
\dim_const:Nn \c_WrapFig_om_hoffset_dim {\marparwidth}
\str_const:Nn \c_WrapFig_placement_str {o} \str_const:Nn \c_WrapFig_placement_str {o}
\dim_const:Nn \c_WrapFig_hoffset_dim {\marparwidth}
\dim_new:N \l_WrapFig_width_dim
\str_new:N \l_WrapFig_passed_keys_str
\tl_new:N \l_WrapFig_format_tl
\newsavebox{\__WrapFig_graphic:}
\keys_define:nn {WrapFig} { \keys_define:nn {WrapFig} {
placement .choices:nn = {l,r,c,i,o}{ hoffset.dim_set:N = \l_WrapFig_hoffset_dim,
hoffset.initial:e = {\c_WrapFig_hoffset_dim},
margin.choices:nn = {none,inside,outside,} {
\str_set:Ne \l_WrapFig_margin_str {\l_keys_choice_tl}
},
margin.initial:n = {none},
margin.default:n = {none},
placement.choices:nn= {c,i,l,o,r} {
\str_set:Ne \l_WrapFig_placement_str {\l_keys_choice_tl} \str_set:Ne \l_WrapFig_placement_str {\l_keys_choice_tl}
}, },
placement .initial:e = {\c_WrapFig_placement_str}, placement.initial:e = {\c_WrapFig_placement_str},
hoffset .dim_set:N = \l_WrapFig_hoffset_dim, unknown.code:n = {
hoffset .initial:e = {\c_WrapFig_hoffset_dim}, \str_put_right:Ne \l_WrapFig_passed_keys_str {\l_keys_key_str=\l_keys_value_tl,}
}
} }
\NewDocumentCommand{\WrapFig}{ \NewDocumentCommand{\WrapFig}{
@@ -68,17 +86,63 @@
>{\TrimSpaces}m >{\TrimSpaces}m
% #5: caption % #5: caption
m m
% #6: Options passed to wrapstuff
O{}
}{ \group_begin: }{ \group_begin:
\keys_set:nn {WrapFig} {#1} \keys_set:nn {WrapFig} {#1}
\__WrapFig_process_options:
\message{
WrapFig:~#4,~
placement:~\l_WrapFig_placement_str,~
hoffset:~\dim_use:N \l_WrapFig_hoffset_dim,
passed_keys:~\l_WrapFig_passed_keys_str}
\expanded{\noexpand\begin{wrapstuff}[ \expanded{\noexpand\begin{wrapstuff}[
\l_WrapFig_placement_str, \l_WrapFig_placement_str,
hoffset = \l_WrapFig_hoffset_dim, hoffset = {\dim_use:N \l_WrapFig_hoffset_dim},
#6
]} ]}
\begin{MyCaption}{fig:#4}{#5} \sbox{\__WrapFig_graphic:}{
\includegraphics[% \includegraphics[
keepaspectratio,% keepaspectratio,
#3% #3
]{#2}% ]{#2}
}
\settowidth{\l_WrapFig_width_dim}{\usebox{\__WrapFig_graphic:}}
\begin{minipage}{\l_WrapFig_width_dim}
\begin{MyCaption}[format=\l_WrapFig_format_tl]{fig:#4}{#5}
\usebox{\__WrapFig_graphic:}
\end{MyCaption} \end{MyCaption}
\end{minipage}
\end{wrapstuff} \end{wrapstuff}
\group_end: } \group_end: }
\cs_new:Nn \__WrapFig_process_options: {
\str_case:en \l_WrapFig_margin_str {
{inside} {
\dim_set:Nn \l_WrapFig_hoffset_dim {\c_WrapFig_im_hoffset_dim}
\str_set:Nn \l_WrapFig_placement_str {i}
}
{outside} {
\dim_set:Nn \l_WrapFig_hoffset_dim {\c_WrapFig_om_hoffset_dim}
\str_set:Nn \l_WrapFig_placement_str {o}
}
}
\ifthenelse{\boolean{isElectronic}}{
\str_replace_all:Nnn \l_WrapFig_placement_str {i} {l}
\str_replace_all:Nnn \l_WrapFig_placement_str {o} {r}
}{
\checkoddpage
\ifoddpage
\str_replace_all:Nnn \l_WrapFig_placement_str {i} {l}
\str_replace_all:Nnn \l_WrapFig_placement_str {o} {r}
\else
\str_replace_all:Nnn \l_WrapFig_placement_str {i} {r}
\str_replace_all:Nnn \l_WrapFig_placement_str {o} {l}
\fi
}
\str_case:en \l_WrapFig_placement_str {
{c} {\tl_set:Nn \l_WrapFig_format_tl {\Centering}}
{l} {\tl_set:Nn \l_WrapFig_format_tl {\RaggedLeft}}
{r} {\tl_set:Nn \l_WrapFig_format_tl {\RaggedRight}}
}
}

View File

@@ -61,34 +61,24 @@
}% }%
} }
\NewDocumentCommand{\marginfig}{O{} m m +m}{% \NewDocumentCommand{\marginfig}{
% Syntax: % #1: Options passed to \includegraphics.
% \marginfig[ O{}
% (width|height)=lengthvalue, or any other optional \includegraphics % #2: Graphic file name.
% parameters m
% ]{ % #3: Label.
% graphic_file_name >{\TrimSpaces}m
% }{ +m
% label }{%
% }{
% caption
% }
%
% This strut ensures that the margin figure is counted as part of the % This strut ensures that the margin figure is counted as part of the
% following paragraph and is vertically aligned with it. % following paragraph and is vertically aligned with it.
\strut% \strut%
\marginalia{% \marginalia{%
\MarginHyperSetup% \MarginHyperSetup%
% \captionsetup{%
% type = figure,%
% justification = RaggedOutside,%
% }%
\begin{MyCaption}[ \begin{MyCaption}[
format={\RaggedOutside\small\color{caption}} format={\RaggedOutside\small\color{caption}}
]{fig:#3}{#4} ]{fig:#3}{#4}
\Centering\includegraphics[keepaspectratio,#1]{#2}% \Centering\includegraphics[keepaspectratio,#1]{#2}%
\end{MyCaption} \end{MyCaption}
% \noindent\captionof{figure}{#4}%
% \label{fig:#3}%
}% }%
} }