summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/lua-ul/lua-ul.sty
blob: 3f9c6571f749c3e154499748cc80785500a4fff1 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%%
%% This is file `lua-ul.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% lua-ul.dtx  (with options: `package')
%% 
%% Copyright (C) 2020-2021 by Marcel Krueger
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage
  {lua-ul}
  [2021/05/12 v0.1.4 Underlining and related functionality for LuaTeX]

\ifx\directlua\undefined
  \PackageError{lua-ul}{LuaLaTeX required}%
  {Lua-UL requires LuaLaTeX.
   Maybe you forgot to switch the engine in your editor?}
\fi
\directlua{require'lua-ul'}
\RequirePackage{xparse}
\newif\ifluaul@predefined
\newif\ifluaul@soulnames
\luaul@predefinedtrue
\DeclareOption{minimal}{\luaul@predefinedfalse}
\DeclareOption{soul}{\luaul@soulnamestrue}
\ProcessOptions\relax
\protected\def\luaul@maybedefineuse#1#2{%
  \unless\ifcsname#1\endcsname
    \expandafter\xdef\csname#1\endcsname{#2}%
  \fi
  \csname#1\endcsname
}
  \newcommand\luaul@defaultcontext{%
    \number\dimexpr1ex
    @\unless\ifx\undefined\LuaCol@Attribute
      \the\LuaCol@Attribute
    \fi
  }
\NewDocumentCommand\newunderlinetype
    { E{*}{{}} m O{\luaul@defaultcontext} m }{%
  \newcommand#2{}% "Reserve" the name
  \protected\def#2{%
    \expandafter\luaul@maybedefineuse
      \expanded{{\csstring#2@@#3}}%
      {\LuaULSetUnderline
        \LuaULNewUnderlineType#1{#4\hskip0pt}%
  }}%
}
\ifluaul@predefined
  \newcommand\luaul@highlight@color{yellow}
  \def\luaul@@setcolor\xcolor@#1#2{}
  \newcommand\luaul@setcolor[1]{%
    \ifx\XC@getcolor\undefined
      \def\luaul@currentcolor{#1}%
    \else
      \begingroup
        \XC@getcolor{#1}\luaul@tmpcolor
      \expanded{\endgroup
        \def\noexpand\luaul@currentcolor{%
          \expandafter\luaul@@setcolor\luaul@tmpcolor}}%
    \fi
  }
  \newcommand\luaul@applycolor{%
    \ifx\XC@getcolor\undefined
      \color{\luaul@currentcolor}%
    \else
      \expandafter\XC@undeclaredcolor\luaul@currentcolor
    \fi
  }
\NewDocumentCommand\LuaULSetHighLightColor{om}{%
  \edef\luaul@highlight@color{\IfValueTF{#1}{[#1]{#2}}{#2}}%
}
  \newunderlinetype\@underLine{%
    \leaders\vrule height -.65ex depth .75ex
  }
  \NewDocumentCommand\underLine{+m}{{\@underLine#1}}

  \newunderlinetype\@strikeThrough{%
    \leaders\vrule height .55ex depth -.45ex
  }
  \newunderlinetype\colored@strikeThrough[\number\dimexpr1ex@%
                                          \luaul@currentcolor]{%
    \luaul@applycolor
    \leaders\vrule height .55ex depth -.45ex
  }
  \NewDocumentCommand\strikeThrough{o+m}{{%
    \IfValueTF{#1}{%
      \luaul@setcolor{#1}%
      \colored@strikeThrough
    }\@strikeThrough%
    #2%
  }}

  \newunderlinetype\@highLight[\number\dimexpr1ex@%
                               \luaul@currentcolor]{%
    \luaul@applycolor
    \leaders\vrule height 1.75ex depth .75ex
  }
  \NewDocumentCommand\highLight{O{\luaul@highlight@color}+m}{{%
    \luaul@setcolor{#1}%
    \@highLight#2%
  }}
  \ifluaul@soulnames
    \let\textul\underLine \let\ul\textul
    \let\textst\strikeThrough \let\st\textst
    \let\texthl\highLight \let\hl\texthl
  \fi
\fi
\ifx \reset@font \normalfont
  \let \reset@font \relax
  \DeclareRobustCommand \reset@font {%
    \normalfont
    \LuaULResetUnderline*%
  }
\else
  \MakeRobust \reset@font
  \begingroup
    \expandafter \let
        \expandafter \helper
        \csname reset@font \endcsname
  \expandafter \endgroup
  \expandafter \gdef
    \csname reset@font \expandafter \endcsname
  \expandafter {%
    \helper%
    \LuaULResetUnderline*%
  }
\fi
\output\expandafter\expandafter\expandafter{%
  \expandafter\expandafter\expandafter\LuaULResetUnderline
  \expandafter\expandafter\expandafter*%
  \expandafter\@firstofone\the\output%
}
%% 
%%
%% End of file `lua-ul.sty'.