LaTeX forum ⇒ Fonts & Character Setsexpl3: changing the catcode such that _ is understood as subscript

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
erwann
Posts: 73
Joined: Thu Aug 25, 2016 2:24 am

expl3: changing the catcode such that _ is understood as subscript

Postby erwann » Tue May 01, 2018 11:37 pm

The example that follows says it all.

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{minimal}
  2. \usepackage{expl3}
  3. \usepackage{xparse}
  4. \usepackage{amssymb}
  5.  
  6. \ExplSyntaxOn
  7.  
  8. \tl_set_rescan:Nnn
  9. \tl_matrix_elem
  10. {\char_set_catcode_math_subscript:n \_} %Wrong guess, apparently
  11. {\ensuremath{A_{ij}}}
  12.  
  13. \NewDocumentCommand\matrixelem{}{\tl_matrix_elem}
  14.  
  15. \begin{document}
  16.  
  17. \ExplSyntaxOff
  18.  
  19. \matrixelem % Expect $A_{ij}$
  20.  
  21. \end{document}


Console output:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
  2. restricted \write18 enabled.
  3. entering extended mode
  4. (./tmpl_expr.tex
  5. LaTeX2e <2017-04-15>
  6. Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
  7. (/usr/local/texlive/2017/texmf-dist/tex/latex/base/minimal.cls
  8. Document Class: minimal 2001/05/25 Standard LaTeX minimal class
  9. ) (/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3.sty
  10. (/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
  11. (/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
  12. (/usr/local/texlive/2017/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
  13. (/usr/local/texlive/2017/texmf-dist/tex/latex/amsfonts/amssymb.sty
  14. (/usr/local/texlive/2017/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
  15. ! Missing number, treated as zero.
  16. <to be read again>
  17. \protect
  18. l.12 {\ensuremath{A_{ij}}}
  19.  
  20. ?




*.log:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex 2018.4.25) 1 MAY 2018 17:24
  2. entering extended mode
  3. restricted \write18 enabled.
  4. %&-line parsing enabled.
  5. **tmpl_expr.tex
  6. (./tmpl_expr.tex
  7. LaTeX2e <2017-04-15>
  8. Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
  9. (/usr/local/texlive/2017/texmf-dist/tex/latex/base/minimal.cls
  10. Document Class: minimal 2001/05/25 Standard LaTeX minimal class
  11. ) (/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3.sty
  12. Package: expl3 2018/02/21 L3 programming layer (loader)
  13.  
  14. (/usr/local/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3-code.tex
  15. Package: expl3 2018/02/21 L3 programming layer (code)
  16. \c_max_int=\count79
  17. \l_tmpa_int=\count80
  18. \l_tmpb_int=\count81
  19. \g_tmpa_int=\count82
  20. \g_tmpb_int=\count83
  21. \g__intarray_font_int=\count84
  22. \g__prg_map_int=\count85
  23. \c_log_iow=\count86
  24. \l_iow_line_count_int=\count87
  25. \l__iow_line_target_int=\count88
  26. \l__iow_one_indent_int=\count89
  27. \l__iow_indent_int=\count90
  28. \c_zero_dim=\dimen102
  29. \c_max_dim=\dimen103
  30. \l_tmpa_dim=\dimen104
  31. \l_tmpb_dim=\dimen105
  32. \g_tmpa_dim=\dimen106
  33. \g_tmpb_dim=\dimen107
  34. \c_zero_skip=\skip41
  35. \c_max_skip=\skip42
  36. \l_tmpa_skip=\skip43
  37. \l_tmpb_skip=\skip44
  38. \g_tmpa_skip=\skip45
  39. \g_tmpb_skip=\skip46
  40. \c_zero_muskip=\muskip10
  41. \c_max_muskip=\muskip11
  42. \l_tmpa_muskip=\muskip12
  43. \l_tmpb_muskip=\muskip13
  44. \g_tmpa_muskip=\muskip14
  45. \g_tmpb_muskip=\muskip15
  46. \l_keys_choice_int=\count91
  47. \c__fp_leading_shift_int=\count92
  48. \c__fp_middle_shift_int=\count93
  49. \c__fp_trailing_shift_int=\count94
  50. \c__fp_big_leading_shift_int=\count95
  51. \c__fp_big_middle_shift_int=\count96
  52. \c__fp_big_trailing_shift_int=\count97
  53. \c__fp_Bigg_leading_shift_int=\count98
  54. \c__fp_Bigg_middle_shift_int=\count99
  55. \c__fp_Bigg_trailing_shift_int=\count100
  56. \c__fp_rand_size_int=\count101
  57. \c__fp_rand_four_int=\count102
  58. \c__fp_rand_eight_int=\count103
  59. \l__sort_length_int=\count104
  60. \l__sort_min_int=\count105
  61. \l__sort_top_int=\count106
  62. \l__sort_max_int=\count107
  63. \l__sort_true_max_int=\count108
  64. \l__sort_block_int=\count109
  65. \l__sort_begin_int=\count110
  66. \l__sort_end_int=\count111
  67. \l__sort_A_int=\count112
  68. \l__sort_B_int=\count113
  69. \l__sort_C_int=\count114
  70. \l__tl_build_start_index_int=\count115
  71. \l__tl_build_index_int=\count116
  72. \l__tl_analysis_normal_int=\count117
  73. \l__tl_analysis_index_int=\count118
  74. \l__tl_analysis_nesting_int=\count119
  75. \l__tl_analysis_type_int=\count120
  76. \l__regex_internal_a_int=\count121
  77. \l__regex_internal_b_int=\count122
  78. \l__regex_internal_c_int=\count123
  79. \l__regex_balance_int=\count124
  80. \l__regex_group_level_int=\count125
  81. \l__regex_mode_int=\count126
  82. \c__regex_cs_in_class_mode_int=\count127
  83. \c__regex_cs_mode_int=\count128
  84. \l__regex_catcodes_int=\count129
  85. \l__regex_default_catcodes_int=\count130
  86. \c__regex_catcode_D_int=\count131
  87. \c__regex_catcode_S_int=\count132
  88. \c__regex_catcode_L_int=\count133
  89. \c__regex_catcode_O_int=\count134
  90. \c__regex_catcode_A_int=\count135
  91. \c__regex_all_catcodes_int=\count136
  92. \l__regex_show_lines_int=\count137
  93. \l__regex_min_state_int=\count138
  94. \l__regex_max_state_int=\count139
  95. \l__regex_left_state_int=\count140
  96. \l__regex_right_state_int=\count141
  97. \l__regex_capturing_group_int=\count142
  98. \l__regex_min_pos_int=\count143
  99. \l__regex_max_pos_int=\count144
  100. \l__regex_curr_pos_int=\count145
  101. \l__regex_start_pos_int=\count146
  102. \l__regex_success_pos_int=\count147
  103. \l__regex_curr_char_int=\count148
  104. \l__regex_curr_catcode_int=\count149
  105. \l__regex_last_char_int=\count150
  106. \l__regex_case_changed_char_int=\count151
  107. \l__regex_curr_state_int=\count152
  108. \l__regex_step_int=\count153
  109. \l__regex_min_active_int=\count154
  110. \l__regex_max_active_int=\count155
  111. \l__regex_replacement_csnames_int=\count156
  112. \l__regex_match_count_int=\count157
  113. \l__regex_min_submatch_int=\count158
  114. \l__regex_submatch_int=\count159
  115. \l__regex_zeroth_submatch_int=\count160
  116. \g__regex_trace_regex_int=\count161
  117. \c_empty_box=\box26
  118. \l_tmpa_box=\box27
  119. \l_tmpb_box=\box28
  120. \g_tmpa_box=\box29
  121. \g_tmpb_box=\box30
  122. \l__box_top_dim=\dimen108
  123. \l__box_bottom_dim=\dimen109
  124. \l__box_left_dim=\dimen110
  125. \l__box_right_dim=\dimen111
  126. \l__box_top_new_dim=\dimen112
  127. \l__box_bottom_new_dim=\dimen113
  128. \l__


References: http://mirror.utexas.edu/ctan/macros/la ... /l3kernel/
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Tags:

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu May 03, 2018 1:31 pm

Why don't you just use LaTeX's \sb or expl3's \c_math_subscript_token?

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage{expl3}
  3. \usepackage{xparse}
  4. \usepackage{amssymb}
  5.  
  6. \ExplSyntaxOn
  7. \tl_new:N \tl_matrix_elem_tl
  8. \tl_set:Nn \tl_matrix_elem_tl { \ensuremath { A \sb {ij} } }
  9. % or:
  10. % \tl_set:Nn \tl_matrix_elem_tl { \ensuremath { A \c_math_subscript_token {ij} } }
  11.  
  12. \NewDocumentCommand \matrixelem {} { \tl_use:N \tl_matrix_elem_tl }
  13.  
  14. \begin{document}
  15.  
  16. \ExplSyntaxOff
  17.  
  18. \matrixelem % Expect $A_{ij}$
  19.  
  20. \end{document}
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

erwann
Posts: 73
Joined: Thu Aug 25, 2016 2:24 am

Postby erwann » Sun May 06, 2018 1:36 am

cgnieder wrote:Why don't you just use LaTeX's \sb or expl3's \c_math_subscript_token?
Too obvious for me to see it. Thanks!
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)


Return to “Fonts & Character Sets”

Who is online

Users browsing this forum: No registered users and 1 guest