Quality and efficiency of my code in LaTeX3?












0














As an exercise in learning LaTeX3, I would like to replace the following 7
functions, copied from which do the same job in
xepersian package, with a single function.



208 DeclareDocumentCommand setlatintextfont { O{} m O{} }
209 {
210 __xepersian_main_setlatintextfont:nn {#1,#3} {#2}
211 ignorespaces
212 }
213 cs_new:Nn __xepersian_main_setlatintextfont:nn
214 {
215 fontspec_set_family:Nnn l__xepersian_latinfont_family_tl {Ligatures=TeX,#1} {#2}
216 use:x { exp_not:n { DeclareRobustCommand latinfont }
217 {
218 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
219 exp_not:N fontfamily { l__xepersian_latinfont_family_tl }
220 exp_not:N selectfont
221 }
222 }
223 str_if_eq_x:nnT {familydefault} {rmdefault}
224 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
225 __xepersian_setlatintextfont_hook:nn {#1} {#2}
226 normalfont
227 }
228
229 cs_set_eq:NN __xepersian_setlatintextfont_hook:nn use_none:nn


313 DeclareDocumentCommand setpersiansansfont { O{} m O{} }
314 {
315 __xepersian_main_setpersiansansfont:nn {#1,#3} {#2}
316 ignorespaces
317 }
318 cs_new:Nn __xepersian_main_setpersiansansfont:nn
319 {
320 fontspec_set_family:Nnn l__xepersian_persiansffamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
321 tl_set_eq:NN persiansfdefault l__xepersian_persiansffamily_family_tl
322 use:x { exp_not:n { DeclareRobustCommand persiansffamily }
323 {
324 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
325 exp_not:N fontfamily { l__xepersian_persiansffamily_family_tl }
326 exp_not:N selectfont
327 }
328 }
329 str_if_eq_x:nnT {familydefault} {persiansfdefault}
330 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
331 __xepersian_setpersiansansfont_hook:nn {#1} {#2}
332 normalfont
333 }
334
335 cs_set_eq:NN __xepersian_setpersiansansfont_hook:nn use_none:nn
336


337 DeclareDocumentCommand setpersianmonofont { O{} m O{} }
338 {
339 __xepersian_main_setpersianmonofont:nn {#1,#3} {#2}
340 ignorespaces
341 }
342 cs_new:Nn __xepersian_main_setpersianmonofont:nn
343 {
344 fontspec_set_family:Nnn l__xepersian_persianttfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
345 tl_set_eq:NN persianttdefault l__xepersian_persianttfamily_family_tl
346 use:x { exp_not:n { DeclareRobustCommand persianttfamily }
347 {
348 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
349 exp_not:N fontfamily { l__xepersian_persianttfamily_family_tl }
350 exp_not:N selectfont
351 }
352 }
353 str_if_eq_x:nnT {familydefault} {persianttdefault}
354 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
355 __xepersian_setpersianmonofont_hook:nn {#1} {#2}
356 normalfont
357 }
358
359 cs_set_eq:NN __xepersian_setpersianmonofont_hook:nn use_none:nn
360


361 DeclareDocumentCommand setnavarfont { O{} m O{} }
362 {
363 __xepersian_main_setnavarfont:nn {#1,#3} {#2}
364 ignorespaces
365 }
366 cs_new:Nn __xepersian_main_setnavarfont:nn
367 {
368 fontspec_set_family:Nnn l__xepersian_navarfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
369 tl_set_eq:NN navardefault l__xepersian_navarfamily_family_tl
370 use:x { exp_not:n { DeclareRobustCommand navarfamily }
371 {
372 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
373 exp_not:N fontfamily { l__xepersian_navarfamily_family_tl }
374 exp_not:N selectfont
375 }
376 }
377 str_if_eq_x:nnT {familydefault} {navardefault}
378 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
379 __xepersian_setnavarfont_hook:nn {#1} {#2}
380 normalfont
381 }
382
383 cs_set_eq:NN __xepersian_setnavarfont_hook:nn use_none:nn
384


385 DeclareDocumentCommand setpookfont { O{} m O{} }
386 {
387 __xepersian_main_setpookfont:nn {#1,#3} {#2}
388 ignorespaces
389 }
390 cs_new:Nn __xepersian_main_setpookfont:nn
391 {
392 fontspec_set_family:Nnn l__xepersian_pookfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
393 tl_set_eq:NN pookdefault l__xepersian_pookfamily_family_tl
394 use:x { exp_not:n { DeclareRobustCommand pookfamily }
395 {
396 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
397 exp_not:N fontfamily { l__xepersian_pookfamily_family_tl }
398 exp_not:N selectfont
399 }
400 }
401 str_if_eq_x:nnT {familydefault} {pookdefault}
402 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
403 __xepersian_setpookfont_hook:nn {#1} {#2}
404 normalfont
405 }
406
407 cs_set_eq:NN __xepersian_setpookfont_hook:nn use_none:nn
408


409 DeclareDocumentCommand setsayehfont { O{} m O{} }
410 {
411 __xepersian_main_setsayehfont:nn {#1,#3} {#2}
412 ignorespaces
413 }
414 cs_new:Nn __xepersian_main_setsayehfont:nn
415 {
416 fontspec_set_family:Nnn l__xepersian_sayehfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
417 tl_set_eq:NN sayehdefault l__xepersian_sayehfamily_family_tl
418 use:x { exp_not:n { DeclareRobustCommand sayehfamily }
419 {
420 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
421 exp_not:N fontfamily { l__xepersian_sayehfamily_family_tl }
422 exp_not:N selectfont
423 }
424 }
425 str_if_eq_x:nnT {familydefault} {sayehdefault}
426 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
427 __xepersian_setsayehfont_hook:nn {#1} {#2}
428 normalfont
429 }
430
431 cs_set_eq:NN __xepersian_setsayehfont_hook:nn use_none:nn
432


433 DeclareDocumentCommand setiranicfont { O{} m O{} }
434 {
435 __xepersian_main_setiranicfont:nn {#1,#3} {#2}
436 ignorespaces
437 }
438 cs_new:Nn __xepersian_main_setiranicfont:nn
439 {
440 fontspec_set_family:Nnn l__xepersian_iranicfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
441 tl_set_eq:NN iranicdefault l__xepersian_iranicfamily_family_tl
442 use:x { exp_not:n { DeclareRobustCommand iranicfamily }
443 {
444 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
445 exp_not:N fontfamily { l__xepersian_iranicfamily_family_tl }
446 exp_not:N selectfont
447 }
448 }
449 str_if_eq_x:nnT {familydefault} {iranicdefault}
450 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
451 __xepersian_setiranicfont_hook:nn {#1} {#2}
452 normalfont
453 }
454
455 cs_set_eq:NN __xepersian_setiranicfont_hook:nn use_none:nn


The following is my code which I have replaced all of the above in xepersian.sty:



cs_set:Nn __xepersian_declare_set_fonts:nnnnn
{
exp_args:Nc DeclareDocumentCommand { set #1 font } { O{} m O{} }
{
cs:w __xepersian_main_set #1 font :nn cs_end: {##1,##3} {##2}
ignorespaces
}
exp_args:Nc cs_new:Nn { __xepersian_main_set #1 font :nn }
{
exp_args:Ncnx fontspec_set_family:Nnn { l__xepersian_ #2 #3 _family_tl } {#5,##1} {##2}
exp_args:Ncc tl_set_eq:NN { #2 default } { l__xepersian_ #2 #3 _family_tl }
use:x { exp_not:n { exp_args:Nc DeclareRobustCommand { #2 #3 } }
{
exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
exp_not:N fontfamily { cs:w l__xepersian_ #2 #3 _family_tl cs_end: }
exp_not:N selectfont
}
}
str_if_eq_x:nnT {familydefault} { cs:w #4 default cs_end: }
{ tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
cs:w __xepersian_set #1 font_hook :nn cs_end: {##1} {##2}
normalfont
}
exp_args:Nc cs_set_eq:NN { __xepersian_set #1 font_hook :nn } use_none:nn
}

__xepersian_declare_set_fonts:nnnnn { latintext } { latin } { font } { rm } { Ligatures=TeX }

seq_new:N l__my_xepersian_styles_seq
seq_set_split:Nnn l__my_xepersian_styles_seq { , }
{
% { { latintext } { latin } { font } { rm } { Ligatures=TeX } } ,
{ { persiansans } { persiansf } { family } { persiansf } { Script=Persian,Ligatures=PersianTeX } } ,
{ { persianmono } { persiantt } { family } { persiantt } { Script=Persian,Ligatures=PersianTeX } } ,
{ { iranic } { iranic } { family } { iranic } { Script=Persian,Ligatures=PersianTeX } } ,
{ { navar } { navar } { family } { navar } { Script=Persian,Ligatures=PersianTeX } } ,
{ { pook } { pook } { family } { pook } { Script=Persian,Ligatures=PersianTeX } } ,
{ { sayeh } { sayeh } { family } { sayeh } { Script=Persian,Ligatures=PersianTeX } }
}

seq_map_inline:Nn l__my_xepersian_styles_seq
{
__xepersian_declare_set_fonts:nnnnn #1
}


As I am a beginner in LaTeX3, I would like to know if I can improve the
quality and efficiency of my code or perhaps simplify it.









share



























    0














    As an exercise in learning LaTeX3, I would like to replace the following 7
    functions, copied from which do the same job in
    xepersian package, with a single function.



    208 DeclareDocumentCommand setlatintextfont { O{} m O{} }
    209 {
    210 __xepersian_main_setlatintextfont:nn {#1,#3} {#2}
    211 ignorespaces
    212 }
    213 cs_new:Nn __xepersian_main_setlatintextfont:nn
    214 {
    215 fontspec_set_family:Nnn l__xepersian_latinfont_family_tl {Ligatures=TeX,#1} {#2}
    216 use:x { exp_not:n { DeclareRobustCommand latinfont }
    217 {
    218 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    219 exp_not:N fontfamily { l__xepersian_latinfont_family_tl }
    220 exp_not:N selectfont
    221 }
    222 }
    223 str_if_eq_x:nnT {familydefault} {rmdefault}
    224 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    225 __xepersian_setlatintextfont_hook:nn {#1} {#2}
    226 normalfont
    227 }
    228
    229 cs_set_eq:NN __xepersian_setlatintextfont_hook:nn use_none:nn


    313 DeclareDocumentCommand setpersiansansfont { O{} m O{} }
    314 {
    315 __xepersian_main_setpersiansansfont:nn {#1,#3} {#2}
    316 ignorespaces
    317 }
    318 cs_new:Nn __xepersian_main_setpersiansansfont:nn
    319 {
    320 fontspec_set_family:Nnn l__xepersian_persiansffamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    321 tl_set_eq:NN persiansfdefault l__xepersian_persiansffamily_family_tl
    322 use:x { exp_not:n { DeclareRobustCommand persiansffamily }
    323 {
    324 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    325 exp_not:N fontfamily { l__xepersian_persiansffamily_family_tl }
    326 exp_not:N selectfont
    327 }
    328 }
    329 str_if_eq_x:nnT {familydefault} {persiansfdefault}
    330 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    331 __xepersian_setpersiansansfont_hook:nn {#1} {#2}
    332 normalfont
    333 }
    334
    335 cs_set_eq:NN __xepersian_setpersiansansfont_hook:nn use_none:nn
    336


    337 DeclareDocumentCommand setpersianmonofont { O{} m O{} }
    338 {
    339 __xepersian_main_setpersianmonofont:nn {#1,#3} {#2}
    340 ignorespaces
    341 }
    342 cs_new:Nn __xepersian_main_setpersianmonofont:nn
    343 {
    344 fontspec_set_family:Nnn l__xepersian_persianttfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    345 tl_set_eq:NN persianttdefault l__xepersian_persianttfamily_family_tl
    346 use:x { exp_not:n { DeclareRobustCommand persianttfamily }
    347 {
    348 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    349 exp_not:N fontfamily { l__xepersian_persianttfamily_family_tl }
    350 exp_not:N selectfont
    351 }
    352 }
    353 str_if_eq_x:nnT {familydefault} {persianttdefault}
    354 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    355 __xepersian_setpersianmonofont_hook:nn {#1} {#2}
    356 normalfont
    357 }
    358
    359 cs_set_eq:NN __xepersian_setpersianmonofont_hook:nn use_none:nn
    360


    361 DeclareDocumentCommand setnavarfont { O{} m O{} }
    362 {
    363 __xepersian_main_setnavarfont:nn {#1,#3} {#2}
    364 ignorespaces
    365 }
    366 cs_new:Nn __xepersian_main_setnavarfont:nn
    367 {
    368 fontspec_set_family:Nnn l__xepersian_navarfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    369 tl_set_eq:NN navardefault l__xepersian_navarfamily_family_tl
    370 use:x { exp_not:n { DeclareRobustCommand navarfamily }
    371 {
    372 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    373 exp_not:N fontfamily { l__xepersian_navarfamily_family_tl }
    374 exp_not:N selectfont
    375 }
    376 }
    377 str_if_eq_x:nnT {familydefault} {navardefault}
    378 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    379 __xepersian_setnavarfont_hook:nn {#1} {#2}
    380 normalfont
    381 }
    382
    383 cs_set_eq:NN __xepersian_setnavarfont_hook:nn use_none:nn
    384


    385 DeclareDocumentCommand setpookfont { O{} m O{} }
    386 {
    387 __xepersian_main_setpookfont:nn {#1,#3} {#2}
    388 ignorespaces
    389 }
    390 cs_new:Nn __xepersian_main_setpookfont:nn
    391 {
    392 fontspec_set_family:Nnn l__xepersian_pookfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    393 tl_set_eq:NN pookdefault l__xepersian_pookfamily_family_tl
    394 use:x { exp_not:n { DeclareRobustCommand pookfamily }
    395 {
    396 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    397 exp_not:N fontfamily { l__xepersian_pookfamily_family_tl }
    398 exp_not:N selectfont
    399 }
    400 }
    401 str_if_eq_x:nnT {familydefault} {pookdefault}
    402 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    403 __xepersian_setpookfont_hook:nn {#1} {#2}
    404 normalfont
    405 }
    406
    407 cs_set_eq:NN __xepersian_setpookfont_hook:nn use_none:nn
    408


    409 DeclareDocumentCommand setsayehfont { O{} m O{} }
    410 {
    411 __xepersian_main_setsayehfont:nn {#1,#3} {#2}
    412 ignorespaces
    413 }
    414 cs_new:Nn __xepersian_main_setsayehfont:nn
    415 {
    416 fontspec_set_family:Nnn l__xepersian_sayehfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    417 tl_set_eq:NN sayehdefault l__xepersian_sayehfamily_family_tl
    418 use:x { exp_not:n { DeclareRobustCommand sayehfamily }
    419 {
    420 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    421 exp_not:N fontfamily { l__xepersian_sayehfamily_family_tl }
    422 exp_not:N selectfont
    423 }
    424 }
    425 str_if_eq_x:nnT {familydefault} {sayehdefault}
    426 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    427 __xepersian_setsayehfont_hook:nn {#1} {#2}
    428 normalfont
    429 }
    430
    431 cs_set_eq:NN __xepersian_setsayehfont_hook:nn use_none:nn
    432


    433 DeclareDocumentCommand setiranicfont { O{} m O{} }
    434 {
    435 __xepersian_main_setiranicfont:nn {#1,#3} {#2}
    436 ignorespaces
    437 }
    438 cs_new:Nn __xepersian_main_setiranicfont:nn
    439 {
    440 fontspec_set_family:Nnn l__xepersian_iranicfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
    441 tl_set_eq:NN iranicdefault l__xepersian_iranicfamily_family_tl
    442 use:x { exp_not:n { DeclareRobustCommand iranicfamily }
    443 {
    444 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    445 exp_not:N fontfamily { l__xepersian_iranicfamily_family_tl }
    446 exp_not:N selectfont
    447 }
    448 }
    449 str_if_eq_x:nnT {familydefault} {iranicdefault}
    450 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    451 __xepersian_setiranicfont_hook:nn {#1} {#2}
    452 normalfont
    453 }
    454
    455 cs_set_eq:NN __xepersian_setiranicfont_hook:nn use_none:nn


    The following is my code which I have replaced all of the above in xepersian.sty:



    cs_set:Nn __xepersian_declare_set_fonts:nnnnn
    {
    exp_args:Nc DeclareDocumentCommand { set #1 font } { O{} m O{} }
    {
    cs:w __xepersian_main_set #1 font :nn cs_end: {##1,##3} {##2}
    ignorespaces
    }
    exp_args:Nc cs_new:Nn { __xepersian_main_set #1 font :nn }
    {
    exp_args:Ncnx fontspec_set_family:Nnn { l__xepersian_ #2 #3 _family_tl } {#5,##1} {##2}
    exp_args:Ncc tl_set_eq:NN { #2 default } { l__xepersian_ #2 #3 _family_tl }
    use:x { exp_not:n { exp_args:Nc DeclareRobustCommand { #2 #3 } }
    {
    exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
    exp_not:N fontfamily { cs:w l__xepersian_ #2 #3 _family_tl cs_end: }
    exp_not:N selectfont
    }
    }
    str_if_eq_x:nnT {familydefault} { cs:w #4 default cs_end: }
    { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
    cs:w __xepersian_set #1 font_hook :nn cs_end: {##1} {##2}
    normalfont
    }
    exp_args:Nc cs_set_eq:NN { __xepersian_set #1 font_hook :nn } use_none:nn
    }

    __xepersian_declare_set_fonts:nnnnn { latintext } { latin } { font } { rm } { Ligatures=TeX }

    seq_new:N l__my_xepersian_styles_seq
    seq_set_split:Nnn l__my_xepersian_styles_seq { , }
    {
    % { { latintext } { latin } { font } { rm } { Ligatures=TeX } } ,
    { { persiansans } { persiansf } { family } { persiansf } { Script=Persian,Ligatures=PersianTeX } } ,
    { { persianmono } { persiantt } { family } { persiantt } { Script=Persian,Ligatures=PersianTeX } } ,
    { { iranic } { iranic } { family } { iranic } { Script=Persian,Ligatures=PersianTeX } } ,
    { { navar } { navar } { family } { navar } { Script=Persian,Ligatures=PersianTeX } } ,
    { { pook } { pook } { family } { pook } { Script=Persian,Ligatures=PersianTeX } } ,
    { { sayeh } { sayeh } { family } { sayeh } { Script=Persian,Ligatures=PersianTeX } }
    }

    seq_map_inline:Nn l__my_xepersian_styles_seq
    {
    __xepersian_declare_set_fonts:nnnnn #1
    }


    As I am a beginner in LaTeX3, I would like to know if I can improve the
    quality and efficiency of my code or perhaps simplify it.









    share

























      0












      0








      0







      As an exercise in learning LaTeX3, I would like to replace the following 7
      functions, copied from which do the same job in
      xepersian package, with a single function.



      208 DeclareDocumentCommand setlatintextfont { O{} m O{} }
      209 {
      210 __xepersian_main_setlatintextfont:nn {#1,#3} {#2}
      211 ignorespaces
      212 }
      213 cs_new:Nn __xepersian_main_setlatintextfont:nn
      214 {
      215 fontspec_set_family:Nnn l__xepersian_latinfont_family_tl {Ligatures=TeX,#1} {#2}
      216 use:x { exp_not:n { DeclareRobustCommand latinfont }
      217 {
      218 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      219 exp_not:N fontfamily { l__xepersian_latinfont_family_tl }
      220 exp_not:N selectfont
      221 }
      222 }
      223 str_if_eq_x:nnT {familydefault} {rmdefault}
      224 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      225 __xepersian_setlatintextfont_hook:nn {#1} {#2}
      226 normalfont
      227 }
      228
      229 cs_set_eq:NN __xepersian_setlatintextfont_hook:nn use_none:nn


      313 DeclareDocumentCommand setpersiansansfont { O{} m O{} }
      314 {
      315 __xepersian_main_setpersiansansfont:nn {#1,#3} {#2}
      316 ignorespaces
      317 }
      318 cs_new:Nn __xepersian_main_setpersiansansfont:nn
      319 {
      320 fontspec_set_family:Nnn l__xepersian_persiansffamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      321 tl_set_eq:NN persiansfdefault l__xepersian_persiansffamily_family_tl
      322 use:x { exp_not:n { DeclareRobustCommand persiansffamily }
      323 {
      324 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      325 exp_not:N fontfamily { l__xepersian_persiansffamily_family_tl }
      326 exp_not:N selectfont
      327 }
      328 }
      329 str_if_eq_x:nnT {familydefault} {persiansfdefault}
      330 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      331 __xepersian_setpersiansansfont_hook:nn {#1} {#2}
      332 normalfont
      333 }
      334
      335 cs_set_eq:NN __xepersian_setpersiansansfont_hook:nn use_none:nn
      336


      337 DeclareDocumentCommand setpersianmonofont { O{} m O{} }
      338 {
      339 __xepersian_main_setpersianmonofont:nn {#1,#3} {#2}
      340 ignorespaces
      341 }
      342 cs_new:Nn __xepersian_main_setpersianmonofont:nn
      343 {
      344 fontspec_set_family:Nnn l__xepersian_persianttfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      345 tl_set_eq:NN persianttdefault l__xepersian_persianttfamily_family_tl
      346 use:x { exp_not:n { DeclareRobustCommand persianttfamily }
      347 {
      348 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      349 exp_not:N fontfamily { l__xepersian_persianttfamily_family_tl }
      350 exp_not:N selectfont
      351 }
      352 }
      353 str_if_eq_x:nnT {familydefault} {persianttdefault}
      354 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      355 __xepersian_setpersianmonofont_hook:nn {#1} {#2}
      356 normalfont
      357 }
      358
      359 cs_set_eq:NN __xepersian_setpersianmonofont_hook:nn use_none:nn
      360


      361 DeclareDocumentCommand setnavarfont { O{} m O{} }
      362 {
      363 __xepersian_main_setnavarfont:nn {#1,#3} {#2}
      364 ignorespaces
      365 }
      366 cs_new:Nn __xepersian_main_setnavarfont:nn
      367 {
      368 fontspec_set_family:Nnn l__xepersian_navarfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      369 tl_set_eq:NN navardefault l__xepersian_navarfamily_family_tl
      370 use:x { exp_not:n { DeclareRobustCommand navarfamily }
      371 {
      372 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      373 exp_not:N fontfamily { l__xepersian_navarfamily_family_tl }
      374 exp_not:N selectfont
      375 }
      376 }
      377 str_if_eq_x:nnT {familydefault} {navardefault}
      378 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      379 __xepersian_setnavarfont_hook:nn {#1} {#2}
      380 normalfont
      381 }
      382
      383 cs_set_eq:NN __xepersian_setnavarfont_hook:nn use_none:nn
      384


      385 DeclareDocumentCommand setpookfont { O{} m O{} }
      386 {
      387 __xepersian_main_setpookfont:nn {#1,#3} {#2}
      388 ignorespaces
      389 }
      390 cs_new:Nn __xepersian_main_setpookfont:nn
      391 {
      392 fontspec_set_family:Nnn l__xepersian_pookfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      393 tl_set_eq:NN pookdefault l__xepersian_pookfamily_family_tl
      394 use:x { exp_not:n { DeclareRobustCommand pookfamily }
      395 {
      396 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      397 exp_not:N fontfamily { l__xepersian_pookfamily_family_tl }
      398 exp_not:N selectfont
      399 }
      400 }
      401 str_if_eq_x:nnT {familydefault} {pookdefault}
      402 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      403 __xepersian_setpookfont_hook:nn {#1} {#2}
      404 normalfont
      405 }
      406
      407 cs_set_eq:NN __xepersian_setpookfont_hook:nn use_none:nn
      408


      409 DeclareDocumentCommand setsayehfont { O{} m O{} }
      410 {
      411 __xepersian_main_setsayehfont:nn {#1,#3} {#2}
      412 ignorespaces
      413 }
      414 cs_new:Nn __xepersian_main_setsayehfont:nn
      415 {
      416 fontspec_set_family:Nnn l__xepersian_sayehfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      417 tl_set_eq:NN sayehdefault l__xepersian_sayehfamily_family_tl
      418 use:x { exp_not:n { DeclareRobustCommand sayehfamily }
      419 {
      420 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      421 exp_not:N fontfamily { l__xepersian_sayehfamily_family_tl }
      422 exp_not:N selectfont
      423 }
      424 }
      425 str_if_eq_x:nnT {familydefault} {sayehdefault}
      426 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      427 __xepersian_setsayehfont_hook:nn {#1} {#2}
      428 normalfont
      429 }
      430
      431 cs_set_eq:NN __xepersian_setsayehfont_hook:nn use_none:nn
      432


      433 DeclareDocumentCommand setiranicfont { O{} m O{} }
      434 {
      435 __xepersian_main_setiranicfont:nn {#1,#3} {#2}
      436 ignorespaces
      437 }
      438 cs_new:Nn __xepersian_main_setiranicfont:nn
      439 {
      440 fontspec_set_family:Nnn l__xepersian_iranicfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      441 tl_set_eq:NN iranicdefault l__xepersian_iranicfamily_family_tl
      442 use:x { exp_not:n { DeclareRobustCommand iranicfamily }
      443 {
      444 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      445 exp_not:N fontfamily { l__xepersian_iranicfamily_family_tl }
      446 exp_not:N selectfont
      447 }
      448 }
      449 str_if_eq_x:nnT {familydefault} {iranicdefault}
      450 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      451 __xepersian_setiranicfont_hook:nn {#1} {#2}
      452 normalfont
      453 }
      454
      455 cs_set_eq:NN __xepersian_setiranicfont_hook:nn use_none:nn


      The following is my code which I have replaced all of the above in xepersian.sty:



      cs_set:Nn __xepersian_declare_set_fonts:nnnnn
      {
      exp_args:Nc DeclareDocumentCommand { set #1 font } { O{} m O{} }
      {
      cs:w __xepersian_main_set #1 font :nn cs_end: {##1,##3} {##2}
      ignorespaces
      }
      exp_args:Nc cs_new:Nn { __xepersian_main_set #1 font :nn }
      {
      exp_args:Ncnx fontspec_set_family:Nnn { l__xepersian_ #2 #3 _family_tl } {#5,##1} {##2}
      exp_args:Ncc tl_set_eq:NN { #2 default } { l__xepersian_ #2 #3 _family_tl }
      use:x { exp_not:n { exp_args:Nc DeclareRobustCommand { #2 #3 } }
      {
      exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      exp_not:N fontfamily { cs:w l__xepersian_ #2 #3 _family_tl cs_end: }
      exp_not:N selectfont
      }
      }
      str_if_eq_x:nnT {familydefault} { cs:w #4 default cs_end: }
      { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      cs:w __xepersian_set #1 font_hook :nn cs_end: {##1} {##2}
      normalfont
      }
      exp_args:Nc cs_set_eq:NN { __xepersian_set #1 font_hook :nn } use_none:nn
      }

      __xepersian_declare_set_fonts:nnnnn { latintext } { latin } { font } { rm } { Ligatures=TeX }

      seq_new:N l__my_xepersian_styles_seq
      seq_set_split:Nnn l__my_xepersian_styles_seq { , }
      {
      % { { latintext } { latin } { font } { rm } { Ligatures=TeX } } ,
      { { persiansans } { persiansf } { family } { persiansf } { Script=Persian,Ligatures=PersianTeX } } ,
      { { persianmono } { persiantt } { family } { persiantt } { Script=Persian,Ligatures=PersianTeX } } ,
      { { iranic } { iranic } { family } { iranic } { Script=Persian,Ligatures=PersianTeX } } ,
      { { navar } { navar } { family } { navar } { Script=Persian,Ligatures=PersianTeX } } ,
      { { pook } { pook } { family } { pook } { Script=Persian,Ligatures=PersianTeX } } ,
      { { sayeh } { sayeh } { family } { sayeh } { Script=Persian,Ligatures=PersianTeX } }
      }

      seq_map_inline:Nn l__my_xepersian_styles_seq
      {
      __xepersian_declare_set_fonts:nnnnn #1
      }


      As I am a beginner in LaTeX3, I would like to know if I can improve the
      quality and efficiency of my code or perhaps simplify it.









      share













      As an exercise in learning LaTeX3, I would like to replace the following 7
      functions, copied from which do the same job in
      xepersian package, with a single function.



      208 DeclareDocumentCommand setlatintextfont { O{} m O{} }
      209 {
      210 __xepersian_main_setlatintextfont:nn {#1,#3} {#2}
      211 ignorespaces
      212 }
      213 cs_new:Nn __xepersian_main_setlatintextfont:nn
      214 {
      215 fontspec_set_family:Nnn l__xepersian_latinfont_family_tl {Ligatures=TeX,#1} {#2}
      216 use:x { exp_not:n { DeclareRobustCommand latinfont }
      217 {
      218 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      219 exp_not:N fontfamily { l__xepersian_latinfont_family_tl }
      220 exp_not:N selectfont
      221 }
      222 }
      223 str_if_eq_x:nnT {familydefault} {rmdefault}
      224 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      225 __xepersian_setlatintextfont_hook:nn {#1} {#2}
      226 normalfont
      227 }
      228
      229 cs_set_eq:NN __xepersian_setlatintextfont_hook:nn use_none:nn


      313 DeclareDocumentCommand setpersiansansfont { O{} m O{} }
      314 {
      315 __xepersian_main_setpersiansansfont:nn {#1,#3} {#2}
      316 ignorespaces
      317 }
      318 cs_new:Nn __xepersian_main_setpersiansansfont:nn
      319 {
      320 fontspec_set_family:Nnn l__xepersian_persiansffamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      321 tl_set_eq:NN persiansfdefault l__xepersian_persiansffamily_family_tl
      322 use:x { exp_not:n { DeclareRobustCommand persiansffamily }
      323 {
      324 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      325 exp_not:N fontfamily { l__xepersian_persiansffamily_family_tl }
      326 exp_not:N selectfont
      327 }
      328 }
      329 str_if_eq_x:nnT {familydefault} {persiansfdefault}
      330 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      331 __xepersian_setpersiansansfont_hook:nn {#1} {#2}
      332 normalfont
      333 }
      334
      335 cs_set_eq:NN __xepersian_setpersiansansfont_hook:nn use_none:nn
      336


      337 DeclareDocumentCommand setpersianmonofont { O{} m O{} }
      338 {
      339 __xepersian_main_setpersianmonofont:nn {#1,#3} {#2}
      340 ignorespaces
      341 }
      342 cs_new:Nn __xepersian_main_setpersianmonofont:nn
      343 {
      344 fontspec_set_family:Nnn l__xepersian_persianttfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      345 tl_set_eq:NN persianttdefault l__xepersian_persianttfamily_family_tl
      346 use:x { exp_not:n { DeclareRobustCommand persianttfamily }
      347 {
      348 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      349 exp_not:N fontfamily { l__xepersian_persianttfamily_family_tl }
      350 exp_not:N selectfont
      351 }
      352 }
      353 str_if_eq_x:nnT {familydefault} {persianttdefault}
      354 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      355 __xepersian_setpersianmonofont_hook:nn {#1} {#2}
      356 normalfont
      357 }
      358
      359 cs_set_eq:NN __xepersian_setpersianmonofont_hook:nn use_none:nn
      360


      361 DeclareDocumentCommand setnavarfont { O{} m O{} }
      362 {
      363 __xepersian_main_setnavarfont:nn {#1,#3} {#2}
      364 ignorespaces
      365 }
      366 cs_new:Nn __xepersian_main_setnavarfont:nn
      367 {
      368 fontspec_set_family:Nnn l__xepersian_navarfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      369 tl_set_eq:NN navardefault l__xepersian_navarfamily_family_tl
      370 use:x { exp_not:n { DeclareRobustCommand navarfamily }
      371 {
      372 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      373 exp_not:N fontfamily { l__xepersian_navarfamily_family_tl }
      374 exp_not:N selectfont
      375 }
      376 }
      377 str_if_eq_x:nnT {familydefault} {navardefault}
      378 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      379 __xepersian_setnavarfont_hook:nn {#1} {#2}
      380 normalfont
      381 }
      382
      383 cs_set_eq:NN __xepersian_setnavarfont_hook:nn use_none:nn
      384


      385 DeclareDocumentCommand setpookfont { O{} m O{} }
      386 {
      387 __xepersian_main_setpookfont:nn {#1,#3} {#2}
      388 ignorespaces
      389 }
      390 cs_new:Nn __xepersian_main_setpookfont:nn
      391 {
      392 fontspec_set_family:Nnn l__xepersian_pookfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      393 tl_set_eq:NN pookdefault l__xepersian_pookfamily_family_tl
      394 use:x { exp_not:n { DeclareRobustCommand pookfamily }
      395 {
      396 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      397 exp_not:N fontfamily { l__xepersian_pookfamily_family_tl }
      398 exp_not:N selectfont
      399 }
      400 }
      401 str_if_eq_x:nnT {familydefault} {pookdefault}
      402 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      403 __xepersian_setpookfont_hook:nn {#1} {#2}
      404 normalfont
      405 }
      406
      407 cs_set_eq:NN __xepersian_setpookfont_hook:nn use_none:nn
      408


      409 DeclareDocumentCommand setsayehfont { O{} m O{} }
      410 {
      411 __xepersian_main_setsayehfont:nn {#1,#3} {#2}
      412 ignorespaces
      413 }
      414 cs_new:Nn __xepersian_main_setsayehfont:nn
      415 {
      416 fontspec_set_family:Nnn l__xepersian_sayehfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      417 tl_set_eq:NN sayehdefault l__xepersian_sayehfamily_family_tl
      418 use:x { exp_not:n { DeclareRobustCommand sayehfamily }
      419 {
      420 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      421 exp_not:N fontfamily { l__xepersian_sayehfamily_family_tl }
      422 exp_not:N selectfont
      423 }
      424 }
      425 str_if_eq_x:nnT {familydefault} {sayehdefault}
      426 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      427 __xepersian_setsayehfont_hook:nn {#1} {#2}
      428 normalfont
      429 }
      430
      431 cs_set_eq:NN __xepersian_setsayehfont_hook:nn use_none:nn
      432


      433 DeclareDocumentCommand setiranicfont { O{} m O{} }
      434 {
      435 __xepersian_main_setiranicfont:nn {#1,#3} {#2}
      436 ignorespaces
      437 }
      438 cs_new:Nn __xepersian_main_setiranicfont:nn
      439 {
      440 fontspec_set_family:Nnn l__xepersian_iranicfamily_family_tl {Script=Persian,Ligatures=PersianTeX,#1} {#2}
      441 tl_set_eq:NN iranicdefault l__xepersian_iranicfamily_family_tl
      442 use:x { exp_not:n { DeclareRobustCommand iranicfamily }
      443 {
      444 exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      445 exp_not:N fontfamily { l__xepersian_iranicfamily_family_tl }
      446 exp_not:N selectfont
      447 }
      448 }
      449 str_if_eq_x:nnT {familydefault} {iranicdefault}
      450 { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      451 __xepersian_setiranicfont_hook:nn {#1} {#2}
      452 normalfont
      453 }
      454
      455 cs_set_eq:NN __xepersian_setiranicfont_hook:nn use_none:nn


      The following is my code which I have replaced all of the above in xepersian.sty:



      cs_set:Nn __xepersian_declare_set_fonts:nnnnn
      {
      exp_args:Nc DeclareDocumentCommand { set #1 font } { O{} m O{} }
      {
      cs:w __xepersian_main_set #1 font :nn cs_end: {##1,##3} {##2}
      ignorespaces
      }
      exp_args:Nc cs_new:Nn { __xepersian_main_set #1 font :nn }
      {
      exp_args:Ncnx fontspec_set_family:Nnn { l__xepersian_ #2 #3 _family_tl } {#5,##1} {##2}
      exp_args:Ncc tl_set_eq:NN { #2 default } { l__xepersian_ #2 #3 _family_tl }
      use:x { exp_not:n { exp_args:Nc DeclareRobustCommand { #2 #3 } }
      {
      exp_not:N fontencoding { g__fontspec_nfss_enc_tl }
      exp_not:N fontfamily { cs:w l__xepersian_ #2 #3 _family_tl cs_end: }
      exp_not:N selectfont
      }
      }
      str_if_eq_x:nnT {familydefault} { cs:w #4 default cs_end: }
      { tl_set_eq:NN encodingdefault g__fontspec_nfss_enc_tl }
      cs:w __xepersian_set #1 font_hook :nn cs_end: {##1} {##2}
      normalfont
      }
      exp_args:Nc cs_set_eq:NN { __xepersian_set #1 font_hook :nn } use_none:nn
      }

      __xepersian_declare_set_fonts:nnnnn { latintext } { latin } { font } { rm } { Ligatures=TeX }

      seq_new:N l__my_xepersian_styles_seq
      seq_set_split:Nnn l__my_xepersian_styles_seq { , }
      {
      % { { latintext } { latin } { font } { rm } { Ligatures=TeX } } ,
      { { persiansans } { persiansf } { family } { persiansf } { Script=Persian,Ligatures=PersianTeX } } ,
      { { persianmono } { persiantt } { family } { persiantt } { Script=Persian,Ligatures=PersianTeX } } ,
      { { iranic } { iranic } { family } { iranic } { Script=Persian,Ligatures=PersianTeX } } ,
      { { navar } { navar } { family } { navar } { Script=Persian,Ligatures=PersianTeX } } ,
      { { pook } { pook } { family } { pook } { Script=Persian,Ligatures=PersianTeX } } ,
      { { sayeh } { sayeh } { family } { sayeh } { Script=Persian,Ligatures=PersianTeX } }
      }

      seq_map_inline:Nn l__my_xepersian_styles_seq
      {
      __xepersian_declare_set_fonts:nnnnn #1
      }


      As I am a beginner in LaTeX3, I would like to know if I can improve the
      quality and efficiency of my code or perhaps simplify it.







      xetex fontspec latex3 xepersian





      share












      share










      share



      share










      asked 2 mins ago









      Tisha Shusho

      155




      155



























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467484%2fquality-and-efficiency-of-my-code-in-latex3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467484%2fquality-and-efficiency-of-my-code-in-latex3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt