From 0e68ac723daf89cd30bf2c9bff6ffd07794ddca1 Mon Sep 17 00:00:00 2001 From: Joshua Lucas Date: Thu, 11 Sep 2025 16:42:59 -0500 Subject: [PATCH] - Improve wrap objects. - Debug. --- commonincludes.def | 11 +++-- packages/Boxout.sty | 55 +++++++++---------------- packages/Caption.sty | 6 +-- packages/Floats.sty | 42 ++++++++----------- packages/Graphics.sty | 90 +++++++++++++++++++++++++++++++++++------ packages/Marginalia.sty | 28 +++++-------- 6 files changed, 130 insertions(+), 102 deletions(-) diff --git a/commonincludes.def b/commonincludes.def index df4c0be..261f266 100644 --- a/commonincludes.def +++ b/commonincludes.def @@ -1,5 +1,10 @@ \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. \RequirePackage{PrimeTeX/packages/Layout} @@ -9,16 +14,10 @@ \RequirePackage{PrimeTeX/packages/Color} -%\RequirePackage{PrimeTeX/packages/CrossRef} - \RequirePackage{PrimeTeX/packages/DocProperties} \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/Glossary} diff --git a/packages/Boxout.sty b/packages/Boxout.sty index fda4429..18c6f72 100644 --- a/packages/Boxout.sty +++ b/packages/Boxout.sty @@ -23,16 +23,13 @@ vlines = {0pt,boxoutBG}, vline{1,Z} = {\boxoutrule,boxoutFG}, } -% \SetTblrOuter[tblrBoxout]{ -% expand+ = \l_Boxout_body_tl, -% } \tl_const:Nn \c_Boxout_innerspec_tl {colspec={X[l,h]}} \bool_const:Nn \c_Boxout_warning_bool {\c_false_bool} \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 .initial:e = {\c_Boxout_innerspec_tl}, innerspec .default:e = {\c_Boxout_innerspec_tl}, @@ -42,11 +39,6 @@ warning .default:e = {true}, } -% \NewExpandableDocumentCommand{\__Boxout_body:Nnn}{m +m +m}{ -% %\message{boxout~body~start} - -% } - \NewDocumentEnvironment{Boxout}{ % #1: Key-value options. O{} @@ -78,8 +70,7 @@ \group_end: }{} \keys_define:nn{}{ - BigBoxout .inherit:n = BigFloat, - BigBoxout .inherit:n = Boxout, + BigBoxout .inherit:n = {BigFloat, Boxout}, } \NewDocumentEnvironment{BigBoxout}{ @@ -148,27 +139,15 @@ } \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} +\dim_const:Nn \c_WrapBoxout_width_dim {3in} \keys_define:nn{}{ - WrapBoxout .inherit:n = Boxout, + WrapBoxout .inherit:n = {WrapFig, Boxout}, } \keys_define:nn{WrapBoxout}{ - 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_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}, + width .dim_set:N = \l_WrapBoxout_width_dim, + width .initial:e = {\c_WrapBoxout_width_dim}, + width .default:e = {\c_WrapBoxout_width_dim}, } \NewDocumentEnvironment{WrapBoxout}{ @@ -181,19 +160,25 @@ % #4: Body. +b }{ \group_begin: - %\keys_set:nn{WrapBoxout}{position,offset,width} \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}[ - \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}} + \l_WrapFig_placement_str, + hoffset = {\dim_use:N \l_WrapFig_hoffset_dim}, + \l_WrapFig_passed_keys_str, + ]} + %\begin{minipage}{\l_WrapBoxout_width_dim} \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, ]{#2}[#3] #4 \end{Boxout} - \end{minipage} + %\end{minipage} \end{wrapstuff} \group_end: }{} \ No newline at end of file diff --git a/packages/Caption.sty b/packages/Caption.sty index 4dc473f..a69c1e3 100644 --- a/packages/Caption.sty +++ b/packages/Caption.sty @@ -40,7 +40,7 @@ figure .code:n = {\str_set:Nn \l_MyCaption_type_str {figure}}, 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 .initial:n = {\medskipamount}, @@ -63,7 +63,7 @@ % #1: Key-value options. O{} % #2: Label - m + >{\TrimSpaces}m % #3: Caption m }{ @@ -100,7 +100,7 @@ \cs_new:Nn \__MyCaption_insert_caption:nn { \setlength{\parskip}{\l_MyCaption_skip_tl}\par - \__MyCaption_format: + \__MyCaption_format_default: \__MyCaption_format: \l_MyCaption_label_str{}~\l_MyCaption_number_str :~#2 \label{#1} \par diff --git a/packages/Floats.sty b/packages/Floats.sty index 314aeb8..6e2e63c 100644 --- a/packages/Floats.sty +++ b/packages/Floats.sty @@ -10,8 +10,8 @@ \floatstyle{plain} \newfloat{generic}{htpb}{lgf} -%\floatplacement{figure}{htpb} -%\floatplacement{table}{htpb} +\floatplacement{figure}{htpb} +\floatplacement{table}{htpb} % Function for converting clists generated by multichoice keys into strings. \NewDocumentCommand{\clist_use_default:Nnnn}{ @@ -134,14 +134,11 @@ \clist_use_default:Nnnn \l_CenterFig_placement_str {\l_Float_placement_clist} {\c_Float_placement_clist} - %\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: } @@ -197,12 +194,9 @@ placement:e = \l_Float_placement_clist, offset = \l_BigFloat_offset_fp, ] - %\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: } @@ -279,6 +273,8 @@ \ProvideLength{\TwinFigWidth}[\dim_use:N \c_TwinFig_width_dim] +\fp_new:N \l_TwinFig_valign_offset_fp + \keys_define:nn {} { TwinFig .inherit:n = {BigFloat}, } @@ -315,7 +311,6 @@ % 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. \addtocounter{figure}{-2} - \keys_set:nn{TwinFig}{#1} \begin{BigFloat}[ type = {figure}, @@ -324,7 +319,8 @@ offset = \l_BigFloat_offset_fp, ] \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}, hlines = {0pt}, hborder{1-Z} = { @@ -340,27 +336,21 @@ rightspace = \l_TwinFig_space_dim, }, } - \vfill - %\captionsetup{type=figure} \begin{MyCaption}{fig:#3}{#4} \includegraphics[ - keepaspectratio,width=\l_TwinFig_width_dim + keepaspectratio, + align = c, + width = \l_TwinFig_width_dim, ]{#2} \end{MyCaption} - % \captionof{figure}{#4} - % \label{fig:#3} - \vfill & - \vfill - % \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 + \begin{MyCaption}{fig:#6}{#7} + \includegraphics[ + keepaspectratio, + align = c, + width = \l_TwinFig_width_dim, + ]{#5} + \end{MyCaption} \\ \end{tblr} \end{BigFloat} diff --git a/packages/Graphics.sty b/packages/Graphics.sty index 56aee7c..de43bf9 100644 --- a/packages/Graphics.sty +++ b/packages/Graphics.sty @@ -44,17 +44,35 @@ \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} -\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} { - 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} }, - placement .initial:e = {\c_WrapFig_placement_str}, + placement.initial:e = {\c_WrapFig_placement_str}, - hoffset .dim_set:N = \l_WrapFig_hoffset_dim, - hoffset .initial:e = {\c_WrapFig_hoffset_dim}, + unknown.code:n = { + \str_put_right:Ne \l_WrapFig_passed_keys_str {\l_keys_key_str=\l_keys_value_tl,} + } } \NewDocumentCommand{\WrapFig}{ @@ -68,17 +86,63 @@ >{\TrimSpaces}m % #5: caption m + % #6: Options passed to wrapstuff + O{} }{ \group_begin: \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}[ \l_WrapFig_placement_str, - hoffset = \l_WrapFig_hoffset_dim, + hoffset = {\dim_use:N \l_WrapFig_hoffset_dim}, + #6 ]} - \begin{MyCaption}{fig:#4}{#5} - \includegraphics[% - keepaspectratio,% - #3% - ]{#2}% - \end{MyCaption} + \sbox{\__WrapFig_graphic:}{ + \includegraphics[ + keepaspectratio, + #3 + ]{#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{minipage} \end{wrapstuff} -\group_end: } \ No newline at end of file +\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}} + } +} \ No newline at end of file diff --git a/packages/Marginalia.sty b/packages/Marginalia.sty index 1995051..d3481e0 100644 --- a/packages/Marginalia.sty +++ b/packages/Marginalia.sty @@ -61,34 +61,24 @@ }% } -\NewDocumentCommand{\marginfig}{O{} m m +m}{% - % Syntax: - % \marginfig[ - % (width|height)=lengthvalue, or any other optional \includegraphics - % parameters - % ]{ - % graphic_file_name - % }{ - % label - % }{ - % caption - % } - % +\NewDocumentCommand{\marginfig}{ + % #1: Options passed to \includegraphics. + O{} + % #2: Graphic file name. + m + % #3: Label. + >{\TrimSpaces}m + +m +}{% % This strut ensures that the margin figure is counted as part of the % following paragraph and is vertically aligned with it. \strut% \marginalia{% \MarginHyperSetup% - % \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