From d1fd2fef22e5a146a97b36b7c13d2d27e1a67cd8 Mon Sep 17 00:00:00 2001 From: Joshua Lucas Date: Wed, 10 Sep 2025 16:32:35 -0500 Subject: [PATCH] - Fix WrapBoxout. - Migrate from wrapfig2 to wrapstuff. - Miscellaneous improvements. --- commonincludes.def | 2 +- packages/Boxout.sty | 97 +++++++++++++++++++++++++--------- packages/Caption.sty | 112 +++++++++++++++++++++++++--------------- packages/Floats.sty | 90 +++++++++++++++----------------- packages/Graphics.sty | 69 +++++++++++++------------ packages/Layout.sty | 7 ++- packages/Marginalia.sty | 32 +++++++----- 7 files changed, 244 insertions(+), 165 deletions(-) diff --git a/commonincludes.def b/commonincludes.def index ab18a87..df4c0be 100644 --- a/commonincludes.def +++ b/commonincludes.def @@ -9,7 +9,7 @@ \RequirePackage{PrimeTeX/packages/Color} -\RequirePackage{PrimeTeX/packages/CrossRef} +%\RequirePackage{PrimeTeX/packages/CrossRef} \RequirePackage{PrimeTeX/packages/DocProperties} diff --git a/packages/Boxout.sty b/packages/Boxout.sty index 98390a5..fda4429 100644 --- a/packages/Boxout.sty +++ b/packages/Boxout.sty @@ -56,7 +56,7 @@ O{} % #4: Body, passed to @boxout. +b -}{% +}{ \group_begin: \keys_set:nn{Boxout}{#1} \bool_if:nT \l_Boxout_warning_bool { \colorlet{boxoutBG}{warningBG} @@ -75,7 +75,7 @@ #4\\ \end{tblrBoxout} } -}{} +\group_end: }{} \keys_define:nn{}{ BigBoxout .inherit:n = BigFloat, @@ -91,41 +91,84 @@ O{} % #4: Body, passed to Boxout. +b -}{ +}{ \group_begin: \keys_set:nn{BigBoxout}{#1} \begin{BigFloat}[ type = generic, overhang = \l_BigFloat_overhang_dim, placement:e = \l_Float_placement_clist, offset = \l_BigFloat_offset_fp, - ]% - \begin{Boxout}[% + ] + \begin{Boxout}[ innerspec:e = \l_Boxout_innerspec_tl, warning:e = \bool_to_str:N \l_Boxout_warning_bool, ]{#2}[#3] #4 \end{Boxout} \end{BigFloat} -}{} +\group_end: }{} -\str_const:Nn \c_WrapBoxout_position_str {o} -\dim_const:Nn \c_WrapBoxout_offset_dim {\marparwidth} -\dim_const:Nn \c_WrapBoxout_width_dim {3in} +\str_const:Nn \c_MarginBoxout_position_str {auto} +\dim_const:Nn \c_MarginBoxout_width_dim {\marginparwidth} + +\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{}{ WrapBoxout .inherit:n = Boxout, } \keys_define:nn{WrapBoxout}{ - position .choices:nn = {L,l,R,r,I,i,O,o}{ - \str_set:Nn \l_WrapBoxout_position_str {\l_keys_choice_tl} + position .choices:nn = {l,r,c,i,o}{ + \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 .initial:e = {\c_WrapBoxout_offset_dim}, + offset .tl_set:N = \l_WrapBoxout_offset_tl, + offset .initial:e = {\c_WrapBoxout_offset_tl}, + offset .default:e = {\c_WrapBoxout_offset_tl}, - width .dim_set:N = \l_WrapBoxout_width_dim, - width .initial:e = {\c_WrapBoxout_width_dim}, + width .tl_set:N = \l_WrapBoxout_width_tl, + width .initial:e = {\c_WrapBoxout_width_tl}, + width .default:e = {\c_WrapBoxout_width_tl}, } \NewDocumentEnvironment{WrapBoxout}{ @@ -137,16 +180,20 @@ O{} % #4: Body. +b -}{% +}{ \group_begin: + %\keys_set:nn{WrapBoxout}{position,offset,width} \keys_set:nn{WrapBoxout}{#1} - \begin{wrapfigure}{\l_WrapBoxout_position_str}[\l_WrapBoxout_offset_dim]% - \begin{minipage}{\l_WrapBoxout_width_dim}% + \expanded{\noexpand\begin{wrapstuff}[ + \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}[ innerspec:e = \l_Boxout_innerspec_tl, warning:e = \bool_to_str:N \l_Boxout_warning_bool, - ]{#2}[#3]% - #4% - \end{Boxout}% - \end{minipage}% - \end{wrapfigure}% -}{} \ No newline at end of file + ]{#2}[#3] + #4 + \end{Boxout} + \end{minipage} + \end{wrapstuff} +\group_end: }{} \ No newline at end of file diff --git a/packages/Caption.sty b/packages/Caption.sty index 6c6fccb..4dc473f 100644 --- a/packages/Caption.sty +++ b/packages/Caption.sty @@ -1,22 +1,24 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{PrimeTeX/packages/Caption}[2025-08-20] - -\RequirePackage[ - hypcap=true, -]{caption} -\captionsetup{ - justification = Centering, - font = { - small, - color=caption, - }, +\ProvidesExplPackage{PrimeTeX/packages/Caption}{2025-09-10}{1.0}{ + Custom Caption commands. } -% Define a justification style that is ragged on the side toward the outside of -% the page. I. e. RaggedRight on -% \RequirePackage{changepage} +% \RequirePackage[ +% hypcap=true, +% ]{caption} +% \captionsetup{ +% justification = Centering, +% font = { +% small, +% color=caption, +% }, +% } -\DeclareCaptionJustification{RaggedOutside}{% +% Define a justification style that is ragged on the side toward the outside of +% the page. I. e. RaggedRight on +%\RequirePackage{changepage} + +\NewDocumentCommand{\RaggedOutside}{}{ \ifthenelse{\boolean{isElectronic}}{% \RaggedRight% }{% @@ -29,15 +31,24 @@ }% } -\ExplSyntaxOn +\cs_new:Nn \__MyCaption_format_default: {\centering\small\color{caption}} \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}}, - format .tl_set:N = \l_MyCaption_format_tl, - format .initial:n = {\Centering\small\color{caption}}, + format .cs_set_protected:Np = \__MyCaption_format:, + 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}{ \str_set:Ne \l_MyCaption_type_str {\l_keys_choice_tl} @@ -45,37 +56,52 @@ type .initial:n = {figure}, } -\tl_new:N \l_MyCaption_label_tl -\tl_new:N \l_MyCaption_number_tl +\str_new:N \l_MyCaption_label_str +\str_new:N \l_MyCaption_number_str -\NewDocumentCommand{\MyCaption}{ +\NewDocumentEnvironment{MyCaption}{ % #1: Key-value options. O{} % #2: Label m % #3: Caption m -}{ \group_begin: - \keys_set:nn {MyCaption} {#1} - \str_case:en {\l_MyCaption_type_str} { - {figure} { - \addtocounter{figure}{1} - \tl_set:Nn \l_MyCaption_label_tl {Figure} - \tl_set:Nn \l_MyCaption_number_tl { - \arabic{chapter}.\arabic{figure} +}{ + \group_begin: + \keys_set:nn {MyCaption} {#1} + \str_case:en {\l_MyCaption_type_str} { + {figure} { + \refstepcounter{figure} + \str_set:Nn \l_MyCaption_label_str {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} { - \addtocounter{table}{1} - \tl_set:Nn \l_MyCaption_label_tl {Table} - \tl_set:Nn \l_MyCaption_number_tl { - \arabic{chapter}.\arabic{table} + {table} { + \refstepcounter{table} + \str_set:Nn \l_MyCaption_label_str {Table} + \str_set:Ne \l_MyCaption_number_str { + \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 - \l_MyCaption_label_tl~\l_MyCaption_number_tl :~#3 - \label{#2} -\group_end: } \ No newline at end of file + + \bool_if:NT \l_MyCaption_before_bool { + \__MyCaption_insert_caption:nn {#2} {#3} + } +}{ + \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 +} \ No newline at end of file diff --git a/packages/Floats.sty b/packages/Floats.sty index a2e7171..314aeb8 100644 --- a/packages/Floats.sty +++ b/packages/Floats.sty @@ -6,18 +6,12 @@ \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} \floatstyle{plain} \newfloat{generic}{htpb}{lgf} +%\floatplacement{figure}{htpb} +%\floatplacement{table}{htpb} % Function for converting clists generated by multichoice keys into strings. \NewDocumentCommand{\clist_use_default:Nnnn}{ @@ -95,8 +89,7 @@ \dim_set:Nn \l_BigFloat_workoverhang_dim { \dim_min:nn {\l_BigFloat_overhang_dim} {\l_BigFloat_maxoverhang_dim} } - \ExpEnvOption - \begin{\l_BigFloat_type_str}[\l_BigFloat_placement_str]% float environment + \expanded{\noexpand\begin{\l_BigFloat_type_str}[\l_BigFloat_placement_str]}% float environment \begin{SmartAdjustWidth}{ \fp_to_dim:n { -\l_BigFloat_workoverhang_dim @@ -116,7 +109,7 @@ } \end{minipage} \end{SmartAdjustWidth} - \end{\l_BigFloat_type_str} + \expanded{\noexpand\end{\l_BigFloat_type_str}} \group_end: }{} \clist_const:Nn \c_CenterFig_placement_clist {h, t, p, b} @@ -141,12 +134,14 @@ \clist_use_default:Nnnn \l_CenterFig_placement_str {\l_Float_placement_clist} {\c_Float_placement_clist} - \ExpEnvOption - \begin{figure}[\l_CenterFig_placement_str] - \Centering - \includegraphics[keepaspectratio,#1]{#3} - \caption{#5} - \label{fig:#4} + %\ExpEnvOption + \expanded{\noexpand\begin{figure}[\l_CenterFig_placement_str]} + \begin{MyCaption}{fig:#4}{#5} + \Centering + \includegraphics[keepaspectratio,#1]{#3} + \end{MyCaption} + % \caption{#5} + % \label{fig:#4} \end{figure} \group_end: } @@ -202,10 +197,12 @@ placement:e = \l_Float_placement_clist, offset = \l_BigFloat_offset_fp, ] - \captionsetup{type=figure} - \includegraphics[keepaspectratio,width=\linewidth]{#2} - \Centering\captionof{figure}{#4} - \label{fig:#3} + %\captionsetup{type=figure} + \begin{MyCaption}{fig:#3}{#4} + \includegraphics[keepaspectratio,width=\linewidth]{#2} + \end{MyCaption} + % \Centering\captionof{figure}{#4} + % \label{fig:#3} \end{BigFloat} \group_end: } @@ -242,7 +239,7 @@ \keys_set:nn{DoubleBigFig}{#1} \begin{BigFloat}[ - type = generic, + type = figure, overhang = \l_BigFloat_overhang_dim, placement:e = \l_Float_placement_clist, offset = \l_BigFloat_offset_fp, @@ -264,18 +261,13 @@ rightspace = 0pt, }, } - %\captionsetup{type=figure} - \includegraphics[keepaspectratio,width=\textwidth]{#2} - \par - \MyCaption{fig:#3}{#4}\\ - % \Centering\captionof{figure}{#4} - % \label{fig:#3}\\ - %\captionsetup{type=figure} - \includegraphics[keepaspectratio,width=\textwidth]{#5} - \par - \MyCaption{fig:#6}{#7} - % \Centering\captionof{figure}{#7} - % \label{fig:#6} + \begin{MyCaption}{fig:#3}{#4} + \includegraphics[keepaspectratio,width=\linewidth]{#2} + \end{MyCaption} + \\ + \begin{MyCaption}{fig:#6}{#7} + \includegraphics[keepaspectratio,width=\linewidth]{#5} + \end{MyCaption} \end{tblr} \end{BigFloat} \group_end: } @@ -326,7 +318,7 @@ \keys_set:nn{TwinFig}{#1} \begin{BigFloat}[ - type = {generic}, + type = {figure}, overhang = \l_BigFloat_overhang_dim, placement:e = \l_Float_placement_clist, offset = \l_BigFloat_offset_fp, @@ -349,21 +341,25 @@ }, } \vfill - \captionsetup{type=figure} - \includegraphics[ - keepaspectratio,width=\l_TwinFig_width_dim - ]{#2} - \captionof{figure}{#4} - \label{fig:#3} + %\captionsetup{type=figure} + \begin{MyCaption}{fig:#3}{#4} + \includegraphics[ + keepaspectratio,width=\l_TwinFig_width_dim + ]{#2} + \end{MyCaption} + % \captionof{figure}{#4} + % \label{fig:#3} \vfill & \vfill - \captionsetup{type=figure} - \includegraphics[ - keepaspectratio,width=\l_TwinFig_width_dim - ]{#5} - \captionof{figure}{#7} - \label{fig:#6} + % \captionsetup{type=figure} + \begin{MyCaption}{fig:#6}{#7} + \includegraphics[ + keepaspectratio,width=\l_TwinFig_width_dim + ]{#5} + \end{MyCaption} + % \captionof{figure}{#7} + % \label{fig:#6} \vfill \\ \end{tblr} diff --git a/packages/Graphics.sty b/packages/Graphics.sty index 3ed412e..56aee7c 100644 --- a/packages/Graphics.sty +++ b/packages/Graphics.sty @@ -7,7 +7,7 @@ \RequirePackage{calc} -\RequirePackage{wrapfig2} +\RequirePackage{wrapstuff} \dim_const:Nn \c_Graphics_icon_dim {0.25in} @@ -44,40 +44,41 @@ \includegraphics[keepaspectratio,#1]{#2}% } -\NewDocumentCommand{\@wrapfigbody}{m m m m}{ - \captionsetup{type=figure}% - \capstart% - \includegraphics[% - keepaspectratio,% - #2% - ]{#1}% - \Centering\captionof{figure}{#4}% - \label{fig:#3}% +\str_const:Nn \c_WrapFig_placement_str {o} +\dim_const:Nn \c_WrapFig_hoffset_dim {\marparwidth} + +\keys_define:nn {WrapFig} { + placement .choices:nn = {l,r,c,i,o}{ + \str_set:Ne \l_WrapFig_placement_str {\l_keys_choice_tl} + }, + placement .initial:e = {\c_WrapFig_placement_str}, + + hoffset .dim_set:N = \l_WrapFig_hoffset_dim, + hoffset .initial:e = {\c_WrapFig_hoffset_dim}, } -\NewDocumentCommand{\wrapfig}{ - % #1: alignment [l,r,i,o] - O{O} - % #2: horizontal_offset - O{\marparwidth} - % #3: graphic_file - m - % #4: (width|height)=lengthvalue +\NewDocumentCommand{\WrapFig}{ + % #1: Key-value options O{} - % #5: label + % #2: graphic_file + m + % #3: Options passed to \includegraphics + O{} + % #4: label >{\TrimSpaces}m - % #6: caption - m% - % #7: indented lines override - o -}{% - \IfNoValueTF{#7}{% - \begin{wrapfigure}{#1}[#2]% - \@wrapfigbody{#3}{#4}{#5}{#6}% - \end{wrapfigure}% - }{% - \begin{wrapfigure}[#7]{#1}[#2]% - \@wrapfigbody{#3}{#4}{#5}{#6}% - \end{wrapfigure}% - }% -} \ No newline at end of file + % #5: caption + m +}{ \group_begin: + \keys_set:nn {WrapFig} {#1} + \expanded{\noexpand\begin{wrapstuff}[ + \l_WrapFig_placement_str, + hoffset = \l_WrapFig_hoffset_dim, + ]} + \begin{MyCaption}{fig:#4}{#5} + \includegraphics[% + keepaspectratio,% + #3% + ]{#2}% + \end{MyCaption} + \end{wrapstuff} +\group_end: } \ No newline at end of file diff --git a/packages/Layout.sty b/packages/Layout.sty index 26fe73d..3979f3d 100644 --- a/packages/Layout.sty +++ b/packages/Layout.sty @@ -95,7 +95,12 @@ % N.B.: floatpagefraction MUST be less than topfraction !! \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}{% \begin{adjustwidth}{#2}{#3}% #4% diff --git a/packages/Marginalia.sty b/packages/Marginalia.sty index f418f9e..1995051 100644 --- a/packages/Marginalia.sty +++ b/packages/Marginalia.sty @@ -9,9 +9,9 @@ ysep = {\parskip}, ysep page bottom = { - 1in % Top gutter - + \paperheight - - \voffset - - \topmargin + + \paperheight + - \voffset + - \topmargin - \headheight - \headsep - \textheight @@ -29,7 +29,7 @@ } } -% Put a glossary definition in a margin paragraph. +% Put a glossary definition in a margin paragraph. \NewDocumentCommand{\mdef}{O{} m m}{% \index{\glsentryname{#2}}% Add a reference to this in the index. \strong{#3{#2}}% This is the text that appears on the page. @@ -64,7 +64,7 @@ \NewDocumentCommand{\marginfig}{O{} m m +m}{% % Syntax: % \marginfig[ - % (width|height)=lengthvalue, or any other optional \includegraphics + % (width|height)=lengthvalue, or any other optional \includegraphics % parameters % ]{ % graphic_file_name @@ -74,17 +74,21 @@ % 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. - \strut% + \strut% \marginalia{% \MarginHyperSetup% - \captionsetup{% - type = figure,% - justification = RaggedOutside,% - }% - \Centering\includegraphics[keepaspectratio,#1]{#2}\par% - \noindent\captionof{figure}{#4}% - \label{fig:#3}% + % \captionsetup{% + % type = figure,% + % justification = RaggedOutside,% + % }% + \begin{MyCaption}[ + format={\RaggedOutside\small\color{caption}} + ]{fig:#3}{#4} + \Centering\includegraphics[keepaspectratio,#1]{#2}% + \end{MyCaption} + % \noindent\captionof{figure}{#4}% + % \label{fig:#3}% }% } \ No newline at end of file