Guest User

Untitled

a guest
Mar 17th, 2023
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.17 KB | None | 0 0
  1. \documentclass{article}
  2. \usepackage{xparse,xcolor}
  3. \usepackage{ebgaramond} % fully scalable font
  4. \usepackage{verbatim}
  5.  
  6. % egreg @ https://tex.stackexchange.com/questions/338364/
  7. % egreg @ https://tex.stackexchange.com/questions/514372/
  8. \ExplSyntaxOn
  9.  
  10. \keys_define:nn { mystyle }
  11. {
  12.  color .tl_set:N = \l__mystyle_color_tl,
  13.  size  .tl_set:N = \l__mystyle_size_tl,
  14.  skip  .tl_set:N = \l__mystyle_skip_tl,
  15.  color .initial:n = red,
  16.  size  .initial:n = 1,
  17.  skip  .initial:n = 1,
  18. }
  19.  
  20. \cs_new_eq:NN \optical_fontsize:nn \fontsize
  21. \cs_generate_variant:Nn \optical_fontsize:nn { ee }
  22.  
  23.  
  24. \NewDocumentCommand{\setmyfontsize}{ m O{1.2} }
  25. {
  26.  \optical_fontsize:ee
  27.   { \fp_eval:n { \use:c { f@size } + #1 } }
  28.   { \fp_eval:n { ( \use:c { f@size } + #1 ) * ( #2 ) } }
  29.  \selectfont
  30. }
  31.  
  32. \NewDocumentCommand{\stress}{ O{} m }
  33. {
  34.  \group_begin:
  35.  \keys_set:nn { mystyle } { #1 }
  36.  \clist_map_inline:nn { #2 }
  37.   {
  38.    \mystyle:VVVn
  39.     \l__mystyle_color_tl
  40.     \l__mystyle_size_tl
  41.     \l__mystyle_skip_tl
  42.     {##1}
  43.   }
  44.  \group_end:
  45. }
  46. \cs_new_protected:Nn \mystyle:nnnn
  47. {
  48.  \setmyfontsize{#2}[#3]\textcolor{#1}{#4}
  49. }
  50. \cs_generate_variant:Nn \mystyle:nnnn { VVV }
  51. \ExplSyntaxOff
  52.  
  53. \begin{document}
  54.  
  55. \stress{emphasize this sentence with default values and add extra characters to check the default baselineskip}
  56.  
  57. \bigskip
  58.  
  59. \stress[color=green,size=-1]{\textit{emphasize this sentence with custom color and size values}}
  60.  
  61. \bigskip
  62.  
  63. \stress[color=red,size=1]{emphasize this sentence with default color and size values set explicitly and check the resulting baselineskip: should be the same baselineskip as on the first line}
  64.  
  65. \bigskip
  66.  
  67. \stress[color=blue,size=3]{emphasize this sentence with custom color and size values and check the default baselineskip for this size: should have bigger font and bigger baselineskip than above}
  68.  
  69. \bigskip
  70.  
  71. \stress[color=blue,size=3, skip=2]{emphasize this sentence with custom color size and baseline skip values and check the result: should have bigger font and much bigger baselineskip than above}
  72.  
  73. \bigskip
  74.  
  75. \stress[color=gray,size=3]{notice how a comma messes things, notice how a comma messes things}
  76.  
  77. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment