%%
%% This is file `figureversions.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% figureversions.dtx  (with options: `package')
%% 
%% Copyright (c) 2025 by Michael Ummels <michael@ummels.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   https://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Michael Ummels.
%% 
%% This work consists of the files figureversions.dtx, figureversions.ins and
%% the derived file figureversions.sty.
%% 
\NeedsTeXFormat{LaTeX2e}[2024-11-01]
\ProvidesExplPackage {figureversions} {2025-04-29} {1.0.1} {Figure versions}
\str_const:Nn \c__figureversions_text_str {text}
\str_const:Nn \c__figureversions_lining_str {lining}
\str_const:Nn \c__figureversions_proportional_str {proportional}
\str_const:Nn \c__figureversions_tabular_str {tabular}
\str_const:Nn \c__figureversions_normal_str {normal}
\str_const:Nn \c__figureversions_bold_str {bold}
\str_const:Nn \c__figureversions_lf_str {LF}
\str_const:Nn \c__figureversions_osf_str {OsF}
\str_const:Nn \c__figureversions_tlf_str {TLF}
\str_const:Nn \c__figureversions_tosf_str {TOsF}
\bool_new:N \g__figureversions_fontspec_bool
\str_new:N \l__figureversions_fontbasefamily_str
\str_new:N \l__figureversions_fontfigurestyle_str
\str_new:N \l__figureversions_fontfigurealignment_str
\str_set:Nn \l__figureversions_fontbasefamily_str {cmr}
\str_set_eq:NN \l__figureversions_fontfigurestyle_str \c__figureversions_lining_str
\str_set_eq:NN \l__figureversions_fontfigurealignment_str \c__figureversions_proportional_str
\prop_new:N \g__figureversions_figurestyles_proportional_prop
\prop_new:N \g__figureversions_figurestyles_tabular_prop
\prop_new:N \g__figureversions_figureversions_prop
\str_new:N \l__figureversions_mathweight_str
\str_new:N \l__figureversions_mathalign_str
\msg_new:nnn { figureversions } { unknown-figurestyle }
  { Ignoring~unknown~figure~style~`#1'~\msg_line_context: }
\msg_new:nnn { figureversions } { unknown-figurealignment }
  { Ignoring~unknown~figure~alignment~`#1'~\msg_line_context: }
\msg_new:nnn { figureversions } { unknown-mathweight }
  { Ignoring~unknown~math~weight~`#1'~\msg_line_context: }
\msg_new:nnn { figureversions } { unknown-mathfigurealignment }
  { Ignoring~unknown~math~figure~alignment~`#1'~\msg_line_context: }
\msg_new:nnn { figureversions } { unknown-figureversion }
  { Ignoring~unknown~figure~version~`#1'~\msg_line_context: }
\cs_new:Nn \__figureversions_warning:nn
  { \msg_warning:nnn {figureversions} {#1} {#2} }
\prg_new_protected_conditional:Nnn \__figureversions_if_family_exists:n { TF }
  {
    \group_begin:
    \fontfamily {#1}
    \try@load@fontshape
    \cs_if_eq:cNTF \curr@fontshape \relax
      { \group_insert_after:N \prg_return_false: }
      { \group_insert_after:N \prg_return_true: }
    \group_end:
  }
\prg_new_protected_conditional:Nnn \__figureversions_split_family:nNN { TF }
  { \__figureversions_split_family_aux:w #1 - - \q_stop #2 #3 }
\prg_generate_conditional_variant:Nnn \__figureversions_split_family:nNN { V } { TF }
\cs_new_protected:Npn \__figureversions_split_family_aux:w #1-#2-#3 \q_stop #4 #5
  {
    \tl_if_empty:nTF {#2}
      { \prg_return_false: }
      {
        \str_set:Nn #4 {#1}
        \str_set:Nn #5 {#2}
        \prg_return_true:
      }
  }
\cs_new_protected:Nn \__figureversions_copy_mathversion_if_undefined:nn
  {
    \cs_if_exist:cF {mv@#1}
      {
        \DeclareMathVersion {#1}
        \cs_set_eq:cc {mv@#1} {mv@#2}
      }
  }
\cs_new_protected:Nn \__figureversions_encode_suffix_proportional:N
  {
    \seq_clear:N #1
    \prop_get:NVN \g__figureversions_figurestyles_proportional_prop
      \l__figureversions_fontfigurestyle_str \l_tmpa_clist
    \tl_if_eq:NNF \l_tmpa_clist \q_no_value
      {
        \clist_map_inline:Nn \l_tmpa_clist
          { \seq_if_in:NnF #1 {##1} { \seq_put_right:Nn #1 {##1} }  }
      }
    \prop_get:NVN \g__figureversions_figurestyles_tabular_prop
      \l__figureversions_fontfigurestyle_str \l_tmpa_clist
    \tl_if_eq:NNF \l_tmpa_clist \q_no_value
      {
        \clist_map_inline:Nn \l_tmpa_clist
          { \seq_if_in:NnF #1 {##1} { \seq_put_right:Nn #1 {##1} }  }
      }
      \seq_if_in:NVF #1 \c__figureversions_lf_str { \seq_put_right:NV #1 \c__figureversions_lf_str }
      \seq_if_in:NVF #1 \c__figureversions_osf_str { \seq_put_right:NV #1 \c__figureversions_osf_str }
      \seq_if_in:NVF #1 \c__figureversions_tlf_str { \seq_put_right:NV #1 \c__figureversions_tlf_str }
      \seq_if_in:NVF #1 \c__figureversions_tosf_str { \seq_put_right:NV #1 \c__figureversions_tosf_str }
  }
\cs_new_protected:Nn \__figureversions_encode_suffix_tabular:N
  {
    \seq_clear:N #1
    \prop_get:NVN \g__figureversions_figurestyles_tabular_prop
      \l__figureversions_fontfigurestyle_str \l_tmpa_clist
    \tl_if_eq:NNF \l_tmpa_clist \q_no_value
      {
        \clist_map_inline:Nn \l_tmpa_clist
          { \seq_if_in:NnF #1 {##1} { \seq_put_right:Nn #1 {##1} }  }
      }
    \prop_get:NVN \g__figureversions_figurestyles_proportional_prop
      \l__figureversions_fontfigurestyle_str \l_tmpa_clist
    \tl_if_eq:NNF \l_tmpa_clist \q_no_value
      {
        \clist_map_inline:Nn \l_tmpa_clist
          { \seq_if_in:NnF #1 {##1} { \seq_put_right:Nn #1 {##1} }  }
      }
      \seq_if_in:NVF #1 \c__figureversions_tlf_str { \seq_put_right:NV #1 \c__figureversions_tlf_str }
      \seq_if_in:NVF #1 \c__figureversions_tosf_str { \seq_put_right:NV #1 \c__figureversions_tosf_str }
      \seq_if_in:NVF #1 \c__figureversions_lf_str { \seq_put_right:NV #1 \c__figureversions_lf_str }
      \seq_if_in:NVF #1 \c__figureversions_osf_str { \seq_put_right:NV #1 \c__figureversions_osf_str }
  }
\cs_new_protected:Nn \__figureversions_encode_suffix:N
  {
    \str_if_eq:NNTF \l__figureversions_fontfigurealignment_str \c__figureversions_tabular_str
      { \__figureversions_encode_suffix_tabular:N #1 }
      { \__figureversions_encode_suffix_proportional:N #1 }
  }
\cs_new_protected:Nn \__figureversions_encode_suffix_alt:N
  {
    \str_if_eq:NNTF \l__figureversions_fontfigurestyle_str \c__figureversions_text_str
      { \str_set:Nn #1 {j} }
      { \str_set:Nn #1 {x} }
  }
\cs_new_protected:Nn \__figureversions_set_fontfamily:
  {
    \bool_set_false:N \l_tmpa_bool
    \__figureversions_encode_suffix:N \l_tmpa_seq
    \seq_map_inline:Nn \l_tmpa_seq
      {
        \__figureversions_if_family_exists:nTF { \l__figureversions_fontbasefamily_str-##1 }
          {
            \fontfamily { \l__figureversions_fontbasefamily_str-##1 }
            \seq_map_break:n { \bool_set_true:N \l_tmpa_bool }
          }
      }
    \bool_if:NF \l_tmpa_bool
      {
        \__figureversions_encode_suffix_alt:N \l_tmpa_str
        \__figureversions_if_family_exists:nTF { \l__figureversions_fontbasefamily_str\l_tmpa_str }
          { \fontfamily { \l__figureversions_fontbasefamily_str\l_tmpa_str } }
          { \fontfamily \l__figureversions_fontbasefamily_str }
      }
  }
\cs_new_protected:Nn \__figureversions_set_mathversion:
  {
    \str_clear:N \l_tmpa_str
    \str_if_eq:NNT \l__figureversions_mathweight_str \c__figureversions_bold_str
      { \str_put_right:Nn \l_tmpa_str { bold } }
    \str_if_eq:NNT \l__figureversions_mathalign_str \c__figureversions_tabular_str
      { \str_put_right:Nn \l_tmpa_str { tabular } }
    \str_if_empty:NTF \l_tmpa_str
      { \mathversion { normal } }
      { \mathversion { \l_tmpa_str } }
  }
\cs_new_protected:Nn \__figureversions_decode_suffix:n
  {
    \str_set:Nn \l_tmpa_str {#1}
    \bool_set_false:N \l_tmpa_bool
    \prop_map_inline:Nn \g__figureversions_figurestyles_proportional_prop
      {
        \clist_if_in:nVT {##2} \l_tmpa_str
          {
            \str_set:Nn \l__figureversions_fontfigurestyle_str {##1}
            \prop_get:NnNTF \g__figureversions_figurestyles_tabular_prop {##1} \l_tmpa_clist
              {
                \clist_if_in:NVF \l_tmpa_clist \l_tmpa_str
                  {
                    \str_set_eq:NN \l__figureversions_fontfigurealignment_str
                      \c__figureversions_proportional_str
                  }
              }
              {
                \str_set_eq:NN \l__figureversions_fontfigurealignment_str
                      \c__figureversions_proportional_str
              }
            \prop_map_break:n { \bool_set_true:N \l_tmpa_bool }
          }
      }
    \bool_if:NF \l_tmpa_bool
      {
        \prop_map_inline:Nn \g__figureversions_figurestyles_tabular_prop
          {
            \clist_if_in:nVT {##2} \l_tmpa_str
              {
                \str_set:Nn \l__figureversions_fontfigurestyle_str {##1}
                \str_set_eq:NN \l__figureversions_fontfigurealignment_str
                  \c__figureversions_tabular_str
                \prop_map_break:
              }
          }
      }
  }
\cs_generate_variant:Nn \__figureversions_decode_suffix:n { V }
\cs_new_protected:Nn \__figureversions_decode_fontfamily_alt:n
  {
    \str_set:Nn \l__figureversions_fontbasefamily_str {#1}
    \__figureversions_decode_fontfamily_alt_aux:w #1 \q_stop
  }
\cs_generate_variant:Nn \__figureversions_decode_fontfamily_alt:n { V }
\cs_new_protected:Npn \__figureversions_decode_fontfamily_alt_aux:w #1#2#3#4 \q_stop
  {
    \str_if_eq:nnT {#4} {x}
      {
        \str_set:Nn \l__figureversions_fontbasefamily_str { #1#2#3 }
        \str_set_eq:NN \l__figureversions_fontfigurestyle_str \c__figureversions_lining_str
      }
    \str_if_eq:nnT {#4} {j}
      {
        \str_set:Nn \l__figureversions_fontbasefamily_str { #1#2#3 }
        \str_set_eq:NN \l__figureversions_fontfigurestyle_str \c__figureversions_text_str
      }
  }
\cs_new_protected:Nn \__figureversions_get_fontfamily:
  {
    \__figureversions_split_family:VNNTF \f@family \l__figureversions_fontbasefamily_str \l_tmpa_str
      { \__figureversions_decode_suffix:V \l_tmpa_str }
      { \__figureversions_decode_fontfamily_alt:V \f@family }
  }
\cs_new_protected:Nn \__figureversions_get_mathversion:
  {
    \str_if_in:NnTF \math@version { bold }
      { \str_set_eq:NN \l__figureversions_mathweight_str \c__figureversions_bold_str }
      { \str_set_eq:NN \l__figureversions_mathweight_str \c__figureversions_normal_str }
    \str_if_in:NnTF \math@version { tabular }
      { \str_set_eq:NN \l__figureversions_mathalign_str \c__figureversions_tabular_str }
      { \str_set_eq:NN \l__figureversions_mathalign_str \c__figureversions_proportional_str }
  }
\ProvideDocumentCommand \fontfigurestyle {m}
  { \__figureversions_fontfigurestyle:e {#1} }
\cs_new_protected:Nn \__figureversions_fontfigurestyle:n
  {
    \bool_if:nTF
      {
        \prop_if_in_p:Nn \g__figureversions_figurestyles_proportional_prop {#1} ||
        \prop_if_in_p:Nn \g__figureversions_figurestyles_tabular_prop {#1}
      }
      {
        \__figureversions_get_fontfamily:
        \str_set:Nn \l__figureversions_fontfigurestyle_str {#1}
        \__figureversions_set_fontfamily:
      }
      {
        \__figureversions_warning:nn { unknown-figurestyle } {#1}
      }
  }
\cs_generate_variant:Nn \__figureversions_fontfigurestyle:n { e }
\ProvideDocumentCommand \fontfigurealignment {m}
  { \__figureversions_fontfigurealignment:e {#1} }
\cs_new_protected:Nn \__figureversions_fontfigurealignment:n
  {
    \bool_if:nTF
      {
        \str_if_eq_p:Vn \c__figureversions_proportional_str {#1} ||
        \str_if_eq_p:Vn \c__figureversions_tabular_str {#1}
      }
      {
        \__figureversions_get_fontfamily:
        \str_set:Nn \l__figureversions_fontfigurealignment_str {#1}
        \__figureversions_set_fontfamily:
      }
      {
        \__figureversions_warning:nn { unknown-figurealignment } {#1}
      }
  }
\cs_generate_variant:Nn \__figureversions_fontfigurealignment:n { e }
\ProvideDocumentCommand \fontbasefamily {m}
  {
    \__figureversions_get_fontfamily:
    \str_set:Ne \l__figureversions_fontbasefamily_str {#1}
    \__figureversions_set_fontfamily:
  }
\ProvideDocumentCommand \mathweight {m}
  { \__figureversions_mathweight:e {#1} }
\cs_new_protected:Nn \__figureversions_mathweight:n
  {
    \bool_if:nTF
      {
        \str_if_eq_p:Vn \c__figureversions_normal_str {#1} ||
        \str_if_eq_p:Vn \c__figureversions_bold_str {#1}
      }
      {
        \__figureversions_get_mathversion:
        \str_set:Nn \l__figureversions_mathweight_str {#1}
        \__figureversions_set_mathversion:
      }
      {
        \__figureversions_warning:nn { unknown-mathweight } {#1}
      }
  }
\cs_generate_variant:Nn \__figureversions_mathweight:n { e }
\ProvideDocumentCommand \mathfigurealignment {m}
  { \__figureversions_mathfigurealignment:e {#1} }
\cs_new_protected:Nn \__figureversions_mathfigurealignment:n
  {
    \bool_if:nTF
      {
        \str_if_eq_p:Vn \c__figureversions_proportional_str {#1} ||
        \str_if_eq_p:Vn \c__figureversions_tabular_str {#1}
      }
      {
        \__figureversions_get_mathversion:
        \str_set:Nn \l__figureversions_mathalign_str {#1}
        \__figureversions_set_mathversion:
      }
      {
        \__figureversions_warning:nn { unknown-mathfigurealignment } {#1}
      }
  }
\cs_generate_variant:Nn \__figureversions_mathfigurealignment:n { e }
\ProvideDocumentCommand \txfigures {}
  {
    \@nomath \txfigures
    \bool_if:NTF \g__figureversions_fontspec_bool
      { \addfontfeature{ Numbers = OldStyle } }
      {
        \fontfigurestyle { \c__figureversions_text_str }
        \selectfont
      }
  }
\ProvideDocumentCommand \lnfigures {}
  {
    \@nomath \lnfigures
    \bool_if:NTF \g__figureversions_fontspec_bool
      { \addfontfeature{ Numbers = Lining } }
      {
        \fontfigurestyle { \c__figureversions_lining_str }
        \selectfont
      }
  }
\ProvideDocumentCommand \prfigures {}
  {
    \@nomath\prfigures
    \bool_if:NTF \g__figureversions_fontspec_bool
      { \addfontfeature{ Numbers = Proportional } }
      {
        \fontfigurealignment { \c__figureversions_proportional_str }
        \selectfont
      }
  }
\ProvideDocumentCommand \tbfigures {}
  {
    \@nomath\tbfigures
    \bool_if:NTF \g__figureversions_fontspec_bool
      { \addfontfeature{ Numbers = Monospaced } }
      {
        \fontfigurealignment { \c__figureversions_tabular_str }
        \selectfont
      }
  }
\RenewDocumentCommand \boldmath {}
  {
    \@nomath \boldmath
    \mathweight { \c__figureversions_bold_str }
  }
\RenewDocumentCommand \unboldmath {}
  {
    \@nomath \unboldmath
    \mathweight { \c__figureversions_normal_str }
  }
\ProvideDocumentCommand \proportionalmath {}
  {
    \@nomath \proportionalmath
    \mathfigurealignment { \c__figureversions_proportional_str }
  }
\ProvideDocumentCommand \tabularmath {}
  {
    \@nomath \tabularmath
    \mathfigurealignment { \c__figureversions_tabular_str }
  }
\DeclareTextFontCommand {\textfigures} {\txfigures}
\DeclareTextFontCommand {\liningfigures }{\lnfigures}
\DeclareTextFontCommand {\tabularfigures} {\tbfigures\tabularmath}
\DeclareTextFontCommand {\proportionalfigures} {\prfigures\proportionalmath}
\ProvideDocumentCommand \figureversion {m}
  {
    \clist_set:Ne \l_tmpa_clist {#1}
    \clist_map_inline:Nn \l_tmpa_clist
      {
        \prop_get:NnNTF \g__figureversions_figureversions_prop {##1} \l_tmpa_tl
          { \tl_use:N \l_tmpa_tl }
          { \__figureversions_warning:nn { unknown-figureversion } {##1} }
      }
  }
\cs_new_protected:Nn \__figureversions_new_figurestyle_proportional:nn
  {
    \clist_set:Ne \l_tmpa_clist { \tl_to_str:n {#2} }
    \clist_if_empty:NF \l_tmpa_clist
      {
        \prop_gput_if_not_in:NnV \g__figureversions_figurestyles_proportional_prop {#1}
          \l_tmpa_clist
      }
  }
\cs_new_protected:Nn \__figureversions_new_figurestyle_tabular:nn
  {
    \clist_set:Ne \l_tmpa_clist { \tl_to_str:n {#2} }
    \clist_if_empty:NF \l_tmpa_clist
      {
        \prop_gput_if_not_in:NnV \g__figureversions_figurestyles_tabular_prop {#1}
          \l_tmpa_clist
      }
  }
\cs_new_protected:Nn \figureversions_new_figurestyle:nnn
  {
    \__figureversions_new_figurestyle_proportional:nn {#1} {#2}
    \__figureversions_new_figurestyle_tabular:nn {#1} {#3}
  }
\cs_generate_variant:Nn \figureversions_new_figurestyle:nnn { V }
\cs_new_protected:Nn \figureversions_new_figureversion:nn
  { \prop_gput_if_not_in:Nnn \g__figureversions_figureversions_prop {#1} {#2} }
\figureversions_new_figurestyle:Vnn \c__figureversions_text_str { OsF  } { TOsF }
\figureversions_new_figurestyle:Vnn \c__figureversions_lining_str { LF } { TLF }
\figureversions_new_figureversion:nn { text } { \txfigures }
\figureversions_new_figureversion:nn { osf } { \txfigures }
\figureversions_new_figureversion:nn { lining } { \lnfigures }
\figureversions_new_figureversion:nn { lf } { \lnfigures }
\figureversions_new_figureversion:nn { tabular }
  { \tbfigures \tabularmath }
\figureversions_new_figureversion:nn { tab }
  { \tbfigures \tabularmath }
\figureversions_new_figureversion:nn { proportional }
  { \prfigures \proportionalmath }
\figureversions_new_figureversion:nn { prop }
  { \prfigures \proportionalmath }
\AtBeginDocument
  {
    \__figureversions_copy_mathversion_if_undefined:nn { tabular } { normal }
    \__figureversions_copy_mathversion_if_undefined:nn { boldtabular } { bold }
    \IfPackageLoadedT { fontspec }
      { \bool_gset_true:N \g__figureversions_fontspec_bool }
    \IfPackageLoadedT { hyperref }
      {
        \pdfstringdefDisableCommands
          {
            \cs_set_eq:NN \figureversion \use_none:n
            \cs_set_eq:NN \fontfigurestyle \use_none:n
            \cs_set_eq:NN \fontfigurealignment \use_none:n
            \cs_set_eq:NN \fontbasefamily \use_none:n
            \cs_set_eq:NN \mathweight \use_none:n
            \cs_set_eq:NN \mathfigurealignment \use_none:n
            \cs_set_eq:NN \txfigures \relax
            \cs_set_eq:NN \lnfigures \relax
            \cs_set_eq:NN \prfigures \relax
            \cs_set_eq:NN \tbfigures \relax
            \cs_set_eq:NN \proportionalmath \relax
            \cs_set_eq:NN \tabularmath \relax
            \cs_set_eq:NN \textfigures \use:n
            \cs_set_eq:NN \liningfigures \use:n
            \cs_set_eq:NN \tabularfigures \use:n
            \cs_set_eq:NN \proportionalfigures \use:n
          }
      }
  }
%% 
%%
%% End of file `figureversions.sty'.
