diff options
Diffstat (limited to 'macros/latex/contrib/fontscale/fontscale.sty')
-rw-r--r-- | macros/latex/contrib/fontscale/fontscale.sty | 264 |
1 files changed, 159 insertions, 105 deletions
diff --git a/macros/latex/contrib/fontscale/fontscale.sty b/macros/latex/contrib/fontscale/fontscale.sty index c9356b566c..01c9c8e8e4 100644 --- a/macros/latex/contrib/fontscale/fontscale.sty +++ b/macros/latex/contrib/fontscale/fontscale.sty @@ -8,8 +8,8 @@ \NeedsTeXFormat{LaTeX2e}[2023-11-01] \ProvidesExplPackage {fontscale} - {2024-09-06} - {2.3.0} + {2024-09-10} + {2.4.0} {A flexible interface for setting font sizes} % l3kernel version 2023-10-10 added many 'e'-variants. @@ -142,19 +142,12 @@ \q_stop } \cs_generate_variant:Nn \__fontscale_skip_set_default_pt:Nn { c } -% Similar to \@setfontsize. Used to define \tiny to \Huge. Need \dim_use:N for -% compatibility with the microtype package. +% Used to define \tiny to \Huge. Sets \@currsize only for compatibility. Need +% \dim_use:N only for compatibility with the microtype package. \cs_new_protected:Npn \__fontscale_fontsize:NNN #1#2#3 { - \mode_if_math:TF - { - \msg_warning:nne { fontscale } { math-mode-warning } - { \token_to_str:N #1 } - } - { - \cs_set_eq:NN \@currsize #1 - \fontsize { \dim_use:N #2 } #3 \selectfont - } + \cs_set_eq:NN \@currsize #1 + \fontsize { \dim_use:N #2 } #3 \selectfont } % Similar to \fontsize + \selectfont, except that it: % (1) Takes dimen and skip expressions as arguments. @@ -238,20 +231,12 @@ The~ font~ size~ set~ by~ the~ key~ '#1 / scale'~ has~ been~ overwritten~ by~ the~ key~ '#1 / size'~ \msg_line_context:. } -\msg_new:nnn { fontscale } { key-font-sizes-out-of-order } +\msg_new:nnn { fontscale } { font-sizes-out-of-order } { - The~ font~ sizes~ - are~ not~ in~ the~ correct~ order~ \msg_line_context:. \\ + The~ font~ sizes~ are~ not~ in~ the~ correct~ order~ \msg_line_context:. \\ The~ lengths~ of~ the~ font~ sizes~ should~ be~ ordered~ from~ \iow_char:N \\tiny~ to~ \iow_char:N \\Huge. } -\msg_new:nnn { fontscale } { key-font-baselineskips-out-of-order } - { - The~ font~ baselineskips~ - are~ not~ in~ the~ correct~ order~ \msg_line_context:. \\ - The~ lengths~ of~ the~ font~ baselineskips~ - should~ be~ ordered~ from~ \iow_char:N \\tiny~ to~ \iow_char:N \\Huge. - } \msg_new:nnn { fontscale } { math-mode-warning } { '#1'~ does~ nothing~ if~ used~ in~ math~ mode~ \msg_line_context:. } @@ -323,6 +308,14 @@ , notes .int_set:N = \l__fontscale_musical_notes_int , notes .value_required:n = true } +\keys_define:nn { fontscale / normalsize } + { + size .tl_set:N = \l__fontscale_normalsize_size_tl + , size .value_required:n = true + + , baselineskip .tl_set:N = \l__fontscale_normalsize_baselineskip_tl + , baselineskip .value_required:n = true + } \keys_define:nn { fontscale / tiny } { scale .tl_set:N = \l__fontscale_tiny_scale_tl @@ -367,14 +360,6 @@ , baselineskip .tl_set:N = \l__fontscale_small_baselineskip_tl , baselineskip .value_required:n = true } -\keys_define:nn { fontscale / normalsize } - { - size .tl_set:N = \l__fontscale_normalsize_size_tl - , size .value_required:n = true - - , baselineskip .tl_set:N = \l__fontscale_normalsize_baselineskip_tl - , baselineskip .value_required:n = true - } \keys_define:nn { fontscale / large } { scale .tl_set:N = \l__fontscale_large_scale_tl @@ -466,7 +451,8 @@ % INITIALIZE AND PRE-COMPILE KEYS % Pre-compiles the keys with their initial values and then sets the keys to -% their initial values. This is done by hand for speed. +% their initial values. This is significantly faster than using .initial:n and +% \keys_precompile:nnN. \cs_new_protected:Npn \__fontscale_keys_set_initial: { \fp_set:Nn \l__fontscale_baselineskip_size_ratio_fp { 1.2 } @@ -475,37 +461,41 @@ \fp_set:Nn \l__fontscale_musical_ratio_fp { 2 } \int_set:Nn \l__fontscale_musical_notes_int { 5 } - \tl_set:Nn \l__fontscale_tiny_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_scriptsize_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_footnotesize_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_small_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_large_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Large_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_LARGE_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_huge_scale_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Huge_scale_tl { \q_no_value } - - \tl_set:Nn \l__fontscale_tiny_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_scriptsize_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_footnotesize_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_small_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_normalsize_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_large_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Large_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_LARGE_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_huge_size_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Huge_size_tl { \q_no_value } - - \tl_set:Nn \l__fontscale_tiny_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_scriptsize_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_footnotesize_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_small_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_normalsize_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_large_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Large_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_LARGE_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_huge_baselineskip_tl { \q_no_value } - \tl_set:Nn \l__fontscale_Huge_baselineskip_tl { \q_no_value } + \tl_map_inline:nn + { + \l__fontscale_tiny_scale_tl + \l__fontscale_scriptsize_scale_tl + \l__fontscale_footnotesize_scale_tl + \l__fontscale_small_scale_tl + \l__fontscale_large_scale_tl + \l__fontscale_Large_scale_tl + \l__fontscale_LARGE_scale_tl + \l__fontscale_huge_scale_tl + \l__fontscale_Huge_scale_tl + + \l__fontscale_tiny_size_tl + \l__fontscale_scriptsize_size_tl + \l__fontscale_footnotesize_size_tl + \l__fontscale_small_size_tl + \l__fontscale_normalsize_size_tl + \l__fontscale_large_size_tl + \l__fontscale_Large_size_tl + \l__fontscale_LARGE_size_tl + \l__fontscale_huge_size_tl + \l__fontscale_Huge_size_tl + + \l__fontscale_tiny_baselineskip_tl + \l__fontscale_scriptsize_baselineskip_tl + \l__fontscale_footnotesize_baselineskip_tl + \l__fontscale_small_baselineskip_tl + \l__fontscale_normalsize_baselineskip_tl + \l__fontscale_large_baselineskip_tl + \l__fontscale_Large_baselineskip_tl + \l__fontscale_LARGE_baselineskip_tl + \l__fontscale_huge_baselineskip_tl + \l__fontscale_Huge_baselineskip_tl + } + { \tl_set:Nn ##1 { \q_no_value } } } \__fontscale_keys_set_initial: @@ -766,8 +756,7 @@ { \use:c { l__fontscale_#1_baselineskip_tl } } } } -% Issues a warning if the font sizes or font baselineskips are not in the -% correct order. +% Issues a warning if the font sizes are not in the correct order. \cs_new_protected:Npn \__fontscale_keys_process_check_order: { \dim_compare:nF @@ -783,74 +772,152 @@ < \l_fontscale_huge_size_dim < \l_fontscale_Huge_size_dim } - { \msg_warning:nn { fontscale } { key-font-sizes-out-of-order } } - \dim_compare:nF - { - \l_fontscale_tiny_baselineskip_skip - < \l_fontscale_scriptsize_baselineskip_skip - < \l_fontscale_footnotesize_baselineskip_skip - < \l_fontscale_small_baselineskip_skip - < \l_fontscale_normalsize_baselineskip_skip - < \l_fontscale_large_baselineskip_skip - < \l_fontscale_Large_baselineskip_skip - < \l_fontscale_LARGE_baselineskip_skip - < \l_fontscale_huge_baselineskip_skip - < \l_fontscale_Huge_baselineskip_skip - } - { \msg_warning:nn { fontscale } { key-font-baselineskips-out-of-order } } + { \msg_warning:nn { fontscale } { font-sizes-out-of-order } } } % DOCUMENT COMMANDS % Defines the standard LaTeX font size commands from \tiny to \Huge and -% initializes to \normalsize. +% initializes to \normalsize. The corresponding internal functions are not used +% elsewhere in the code for compatibility with hooks such as +% \AddToHook{cmd/<font size command>/after}{<code>}. \DeclareDocumentCommand \tiny { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \tiny } + } + { \__fontscale_tiny: } + } +\cs_new_protected:Npn \__fontscale_tiny: + { \__fontscale_fontsize:NNN \tiny \l_fontscale_tiny_size_dim \l_fontscale_tiny_baselineskip_skip } \DeclareDocumentCommand \scriptsize { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \scriptsize } + } + { \__fontscale_scriptsize: } + } +\cs_new_protected:Npn \__fontscale_scriptsize: + { \__fontscale_fontsize:NNN \scriptsize \l_fontscale_scriptsize_size_dim \l_fontscale_scriptsize_baselineskip_skip } \DeclareDocumentCommand \footnotesize { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \footnotesize } + } + { \__fontscale_footnotesize: } + } +\cs_new_protected:Npn \__fontscale_footnotesize: + { \__fontscale_fontsize:NNN \footnotesize \l_fontscale_footnotesize_size_dim \l_fontscale_footnotesize_baselineskip_skip } \DeclareDocumentCommand \small { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \small } + } + { \__fontscale_small: } + } +\cs_new_protected:Npn \__fontscale_small: + { \__fontscale_fontsize:NNN \small \l_fontscale_small_size_dim \l_fontscale_small_baselineskip_skip } \DeclareDocumentCommand \normalsize { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \normalsize } + } + { \__fontscale_normalsize: } + } +\cs_new_protected:Npn \__fontscale_normalsize: + { \__fontscale_fontsize:NNN \normalsize \l_fontscale_normalsize_size_dim \l_fontscale_normalsize_baselineskip_skip } \DeclareDocumentCommand \large { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \large } + } + { \__fontscale_large: } + } +\cs_new_protected:Npn \__fontscale_large: + { \__fontscale_fontsize:NNN \large \l_fontscale_large_size_dim \l_fontscale_large_baselineskip_skip } \DeclareDocumentCommand \Large { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \Large } + } + { \__fontscale_Large: } + } +\cs_new_protected:Npn \__fontscale_Large: + { \__fontscale_fontsize:NNN \Large \l_fontscale_Large_size_dim \l_fontscale_Large_baselineskip_skip } \DeclareDocumentCommand \LARGE { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \LARGE } + } + { \__fontscale_LARGE: } + } +\cs_new_protected:Npn \__fontscale_LARGE: + { \__fontscale_fontsize:NNN \LARGE \l_fontscale_LARGE_size_dim \l_fontscale_LARGE_baselineskip_skip } \DeclareDocumentCommand \huge { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \huge } + } + { \__fontscale_huge: } + } +\cs_new_protected:Npn \__fontscale_huge: + { \__fontscale_fontsize:NNN \huge \l_fontscale_huge_size_dim \l_fontscale_huge_baselineskip_skip } \DeclareDocumentCommand \Huge { } { + \mode_if_math:TF + { + \msg_warning:nne { fontscale } { math-mode-warning } + { \token_to_str:N \Huge } + } + { \__fontscale_Huge: } + } +\cs_new_protected:Npn \__fontscale_Huge: + { \__fontscale_fontsize:NNN \Huge \l_fontscale_Huge_size_dim \l_fontscale_Huge_baselineskip_skip } @@ -1139,11 +1206,11 @@ } { \token_to_str:c {##1} \@ \c_colon_str \c_space_tl - step ~=~ \fp_use:c { c_fontscale_##1_step_fp } ,~ - scale ~=~ \str_if_eq:nnTF {##1} { normalsize } + step~ =~ \fp_use:c { c_fontscale_##1_step_fp } ,~ + scale~ =~ \str_if_eq:nnTF {##1} { normalsize } { 1 } { \fp_use:c { l_fontscale_##1_scale_fp } } ,~ - size ~=~ \dim_use:c { l_fontscale_##1_size_dim } ,~ - baselineskip ~=~ \skip_use:c { l_fontscale_##1_baselineskip_skip } + size~ =~ \dim_use:c { l_fontscale_##1_size_dim } ,~ + baselineskip~ =~ \skip_use:c { l_fontscale_##1_baselineskip_skip } \str_if_eq:nnF {##1} { Huge } { \newline } } } @@ -1201,25 +1268,12 @@ % TEXT PURIFY -\cs_new:Npn \__fontscale_remove_arg_spec_sm:n #1 +\NewExpandableDocumentCommand \__fontscale_use_none_sm:w { s m } { } +\tl_map_inline:nn { - \bool_lazy_all:nT - { - { \tl_if_single_p:n {#1} } - { \tl_if_single_token_p:n #1 } - { \token_if_eq_meaning_p:NN #1 * } - } - { \use_none:n } - } -\text_declare_purify_equivalent:Nn \fontscalesetup - { \__fontscale_remove_arg_spec_sm:n } -\text_declare_purify_equivalent:Nn \SetFontStep - { \__fontscale_remove_arg_spec_sm:n } -\text_declare_purify_equivalent:Nn \SetFontScale - { \__fontscale_remove_arg_spec_sm:n } -\text_declare_purify_equivalent:Nn \SetFontSize - { \__fontscale_remove_arg_spec_sm:n } + \fontscalesetup \SetFontStep \SetFontScale \SetFontSize + \SetFontBaselineskip + } + { \text_declare_purify_equivalent:Nn #1 { \__fontscale_use_none_sm:w } } \text_declare_purify_equivalent:Nn \ScaleFont { \use_none:n } -\text_declare_purify_equivalent:Nn \SetFontSizeBaselineskip { \use_none:nn } -\text_declare_purify_equivalent:Nn \SetFontBaselineskip - { \__fontscale_remove_arg_spec_sm:n }
\ No newline at end of file +\text_declare_purify_equivalent:Nn \SetFontSizeBaselineskip { \use_none:nn }
\ No newline at end of file |