summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/xelatex/xepersian-hm/xepersian-hm-common-kashida.tex
blob: e8f18375b6e6847ace433375011b06058a3d5e92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
%%
%% This is file `xepersian-hm-common-kashida.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xepersian-hm.dtx  (with options: `xepersian-hm-common-kashida-tex')
%% 
%% Copyright (C) 2020 Hossein Movahhedian
%% 
%% It may be distributed and/or modified under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
\ProvidesExplFile {xepersian-hm-common-kashida.tex} {2020-09-04} {1.1a} { Fixes~implementation~of~Kashida~in~xepersian~package }

\bool_if:NT \l_xephm_ligature_bool
{
  \clist_new:N \l_xephm_ligatures_clist
  \int_new:N \l_xephm_lig_names_len_int
  \int_set:Nn \l_xephm_lig_names_len_int { \clist_count:N \l_xephm_lig_names_clist }
  \int_step_inline:nnnn { 1 } { 2 } { \l_xephm_lig_names_len_int }
    {
      \int_set:Nn \l_tmpa_int { #1 }
      \int_set:Nn \l_tmpb_int { \int_eval:n { \l_tmpa_int + 1 } }
      \tl_set:Nf \l_tmpa_tl { \clist_item:Nn \l_xephm_lig_names_clist { \l_tmpa_int } }
      \clist_set:Nx \l_tmpa_clist { { \clist_item:Nn \l_xephm_lig_names_clist { \l_tmpb_int } } }
      \bool_if:nT { \tl_if_eq_p:NN  \l_xephm_active_ligs_tl  \l_tmpa_tl || \tl_if_eq_p:NN  \l_xephm_active_ligs_tl \l_xephm_lig_default_tl }
        {
          \clist_put_left:Nx \l_xephm_ligatures_clist { \l_tmpa_clist }
        }
    }
  \clist_map_inline:Nn \l_xephm_ligatures_clist
    {
      \seq_set_split:Nnn \l_tmpa_seq { = } { #1 }
      \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl { } { }
      \seq_pop_left:NN \l_tmpa_seq \l_tmpb_tl { } { }
      \tl_const:cx { \tl_use:N \l_tmpb_tl } { \char"\l_tmpa_tl \ }
    }
}

\bool_if:NT \l_xephm_linebreakpenalty_bool
{
  %% Partly adapted from LaTeX2e source
  \cs_new:Nn \xephm_line_break: {
    \if_mode_vertical:
      \GenericError{
        \space\space\space\space\space\space\space\space\space\space\space\space\space\space\space
        }{
           LaTeX Error: There’s no line here to end
        }{
           See the LaTeX manual or LaTeX Companion for explanation.
        }{
           Your command was ignored.\MessageBreak
           Type \space I <command> <return> \space to replace it~
           with another command,\MessageBreak
           or \space <return> \space to continue without it.}
    \else:
      \l_tmpa_skip \tex_lastskip:D
      \tex_unskip:D
      \tex_penalty:D -\l_xephm_line_break_penalty_int
      \dim_compare:nT { \l_tmpa_skip > \c_zero_skip }
        { \skip_horizontal:N \l_tmpa_skip  \tex_ignorespaces:D }
    \fi:
  }

  \NewDocumentCommand { \discouragebadlinebreaks } { O{\l_xephm_line_break_penalty_int} O{\c_xephm_skip_b_tl} m }
    {
      \IfNoValueF {#1}
        { \int_set:Nn \l_xephm_line_break_penalty_int {#1} }
      \IfNoValueF {#2}
        { \tl_set:Nn \l_xephm_skip_default_tl {#2} }
      \xephm_put_line_breaks:n { #3 }
   }

  \cs_new_protected:Nn \xephm_put_line_breaks:n
    {
      \tl_set:Nn \l_xephm_line_break_tl { #1 }
      \regex_replace_all:nnN { ([ابپتثجحخچدذرزژسشعغصضفقطظکگلمنوهیـ])+ } { \ \0 \  \c{xephm_line_break:}\  } \l_xephm_line_break_tl
      \tl_use:N \l_xephm_line_break_tl
    }
}

 \endinput
%% 
%%
%% End of file `xepersian-hm-common-kashida.tex'.