Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. documentclass{scrartcl}
  2.  
  3. usepackage{lmodern}
  4.  
  5. usepackage{array}
  6. usepackage{booktabs}
  7. usepackage{tabu}
  8.  
  9. % First attempt:
  10.  
  11. usepackage{xstring}
  12. newcommand{tosfescapestep}[2]{%
  13. expandafterStrSubstituteexpandafter{x}{#1}{#2}[x]%
  14. }
  15. newcommand{tosfescapehelper}[1]{{%
  16. noexpandarg % suppress expansions made by xstring
  17. StrSubstitute{#1}{0}{oldstylenums{1}}[x]% first step
  18. tosfescapestep{1}{oldstylenums{1}}%
  19. tosfescapestep{2}{oldstylenums{2}}%
  20. tosfescapestep{3}{oldstylenums{3}}%
  21. tosfescapestep{4}{oldstylenums{4}}%
  22. tosfescapestep{5}{oldstylenums{5}}%
  23. tosfescapestep{6}{oldstylenums{6}}%
  24. tosfescapestep{7}{oldstylenums{7}}%
  25. tosfescapestep{8}{oldstylenums{8}}%
  26. tosfescapestep{9}{oldstylenums{9}}%
  27. x}}
  28. newcommand{tosfescape}[1]{tosfescapehelper{#1}}
  29.  
  30. % Second attempt:
  31.  
  32. usepackage{xparse}
  33. usepackage{expl3}
  34. %usepackage{l3regex}
  35.  
  36. ExplSyntaxOn
  37.  
  38. NewDocumentCommand tosfdemo { m }%
  39. { tosfdemo_helper:n { #1 } }
  40.  
  41. tl_new:N l_tosfdemo_tl
  42. cs_new:Npn tosfdemo_helper:n #1 {
  43. tl_set:Nn l_tosfdemo_tl {#1}
  44. regex_replace_all:nnN { (d+) } { c{oldstylenums}cB{ 1 cE} } l_tosfdemo_tl
  45. tl_use:N l_tosfdemo_tl
  46. }
  47.  
  48. ExplSyntaxOff
  49.  
  50. begin{document}
  51.  
  52. noindent Braces -- bold, first and second attempt to texttt{oldstylenums} textbf{work}:\[medskipamount]
  53. textbf{bold 1 23}\
  54. tosfescape{first 1 23}\
  55. tosfdemo{second 1 23}bigskip
  56.  
  57. noindenttexttt{textbackslash bgroup} & texttt{textbackslash egroup} -- as in table~ref{tab:1}, bold textbf{works}, first and second attempt to texttt{oldstylenums} textbf{does not work}:\[medskipamount]
  58. textbfbgroup bold 1 23egroup\
  59. tosfescapebgroup first 1 23egroup\
  60. tosfdemobgroup second 1 23egroup
  61.  
  62. begin{table}[h]
  63. centering
  64. caption{Bold textbf{works}, first and second attempt to texttt{oldstylenums} textbf{does not work}}
  65. label{tab:1}
  66. begin{tabu}{c >{textbfbgroup}c<{egroup} >{tosfescapebgroup}c<{egroup} >{tosfdemobgroup}c<{egroup}}
  67. %toprule
  68. rowfont{itshapebfseries} no change & texttt{textbackslash textbf} & texttt{textbackslash tosfescape} & texttt{textbackslash tosfdemo} \
  69. midrule
  70. regular 1 23 & bold 1 23 & first 1 23 & second 1 23 \
  71. %bottomrule
  72. end{tabu}
  73. end{table}
  74.  
  75. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement