0

I am trying to modify the current version of xepersian package to suit my needs. The following code copied from xepersian-mathsdigitspec.sty is supposed to check if some characters do exist in the font to be loaded. My question is about the function \__xepersian_mathsdigitspec_char_not_exist_error. Is there any way to replace those repeating lines of code in the argument of the function with a (while, until, ...) LOOP which iterates over a list of characters [06F0, ..., 066B]?

\cs_new:Npn \__xepersian_mathsdigitspec_error:nxx    { \msg_error:nnxx    {xepersian-mathsdigitspec} }
\cs_new:Nn \__xepersian_mathsdigitspec_msg_new:nnnn
  { \msg_new:nnxx {#1} {#2} { \tl_trim_spaces:n {#3} } { \tl_trim_spaces:n {#4} } }
\char_set_catcode_space:n {32}
\__xepersian_mathsdigitspec_msg_new:nnnn {xepersian-mathsdigitspec} {char-not-exist}
 {
  The font "#1" does not contain U+#2.
 }
 {
  Select another font and rerun xelatex.
 }
\char_set_catcode_ignore:n {32}

\prg_new_conditional:Nnn \__xepersian_mathsdigitspec_primitive_font_char_if_exist:n {p,TF,T,F}
  {
    \etex_iffontchar:D \l_fontspec_font `#1 \scan_stop:
      \prg_return_true:
    \else:
      \prg_return_false:
    \fi:
  }

\cs_new:Nn \__xepersian_mathsdigitspec_char_not_exist_error:n
 {
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۰ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F0 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۱ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F1 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۲ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F2 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۳ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F3 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۴ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F4 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۵ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F5 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۶ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F6 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۷ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F7 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۸ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F8 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۹ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F9 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ٫ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 066B } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ٪ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 066A } }
 }
  • If you just need to see if certain glyphs exist, why not just use fonttable, as in \documentclass{article} \usepackage{fullpage} \usepackage{fonttable} \begin{document} \fonttable{cmti10} \fonttable{cmsy10} \end{document} – Steven B. Segletes Dec 18 '18 at 11:52
  • Welcome to the site, as well. By the way, it is appropriate in your question to include a fully compiling example rather than just a code snippet or macro definition. – Steven B. Segletes Dec 18 '18 at 11:54
  • 1
    Thanks, Steven, the check for the existence of the characters must be done within the program. BTW, I tried too much to prepare a complete, small, and working example, but I couldn't, because I am a newbie. – Tisha Shusho Dec 18 '18 at 19:41
0

After reading the documents "The expl3 package and LaTeX3 programming" and the "LaTeX3 Interfaces" again (but thoroughly this time) I think I have found a solution to my question. I replaced the following piece of code in xepersian-mathsdigitspec.sty:

\prg_new_conditional:Nnn \__xepersian_mathsdigitspec_primitive_font_char_if_exist:n {p,TF,T,F}
  {
    \etex_iffontchar:D \l_fontspec_font `#1 \scan_stop:
      \prg_return_true:
    \else:
      \prg_return_false:
    \fi:
  }

\cs_new:Nn \__xepersian_mathsdigitspec_char_not_exist_error:n
 {
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۰ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F0 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۱ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F1 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۲ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F2 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۳ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F3 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۴ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F4 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۵ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F5 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۶ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F6 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۷ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F7 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۸ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F8 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ۹ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 06F9 } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ٫ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 066B } }
    \__xepersian_mathsdigitspec_primitive_font_char_if_exist:nF ٪ { \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #1 } { 066A } }
 }

with

\seq_new:N \l_my_xepersian_digits_seq 
\seq_set_split:Nnn \l_my_xepersian_digits_seq { , } { 06F0 , 06F1 , 06F2 , 06F3 , 06F4 , 06F5 , 06F6 , 06F7 , 06F8 , 06F9 , 066A , 066B }

and replaced all instances of the function \__xepersian_mathsdigitspec_char_not_exist_error with:

\seq_map_inline:Nn \l_my_xepersian_digits_seq
  {
    \etex_iffontchar:D \l_fontspec_font "##1 \scan_stop:
    \else:
      \__xepersian_mathsdigitspec_error:nxx {char-not-exist} { #2 } { ##1 }
    \fi:
  }

Of course one can use \seq_map_function to define a new function and replace all occurrences of the function \__xepersian_mathsdigitspec_char_not_exist_error with that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.