Browse Source

use lua-ul if possible

master
Jonathan Spratte 5 months ago
parent
commit
a735f25672
2 changed files with 158 additions and 34 deletions
  1. 34
    2
      Doc/tex/doc_MRTwuline.tex
  2. 124
    32
      MRTwuline/MRTwuline.sty

+ 34
- 2
Doc/tex/doc_MRTwuline.tex View File

@@ -2,7 +2,8 @@
2 2
 The package provides a MS Word like looking line breakable underlining. It does
3 3
 so by using \pkg{ulem} or \pkg{stackengine}.
4 4
 
5
-\section{Options}\label{sec:wuline:options}%>>=
5
+\section{Options}
6
+\subsection{Load time options}\label{sec:wuline:options:loadtime}%>>=
6 7
 \begin{describeopt}{tUline,tikzunderline}
7 8
   If this option is passed \TikZ\ will be added as a required package and an
8 9
   alternative underlining macro defined called \cs{tUline}, see its description
@@ -10,6 +11,36 @@ so by using \pkg{ulem} or \pkg{stackengine}.
10 11
 \end{describeopt}
11 12
 %=<<
12 13
 
14
+\subsection{Setup options}%>>=
15
+\begin{describeopt}{rule~ht,ruleht}[\meta{dimen}]
16
+  With this setting you can decide how thick the rule is, the initial value is
17
+  \texttt{\csname l__MRTwuline_rule_thickness_tl\endcsname}, the value is
18
+  evaluated at use time, so that a smaller font gets a thinner line.
19
+\end{describeopt}
20
+
21
+\begin{describeopt}{math~dp,mathdp}[\meta{dimen}]
22
+  With this setting you can decide the height of the rule below the symbol in
23
+  maths mode. The initial value is
24
+  \texttt{\csname l__MRTwuline_math_depth_tl\endcsname}, the value is evaluated
25
+  at use time.
26
+\end{describeopt}
27
+
28
+\begin{describeopt}{text~dp,textdp}[\meta{dimen}]
29
+  With this setting you can decide the height of the rule below the symbol in
30
+  text mode. The initial value is
31
+  \texttt{\csname l__MRTwuline_text_depth_tl\endcsname}, the value is evaluated
32
+  at use time.
33
+\end{describeopt}
34
+
35
+\begin{describeopt}{luaul,lua-ul}[\meta{bool}]
36
+  If you're using \hologo{LuaLaTeX}, the \pkg{lua-ul} package is loaded. With it
37
+  \cs{WUline} behaves much better, giving the typesetting results you'd get
38
+  without it in text, just with underlining (this includes automatic
39
+  hyphenation). With this key you can decide whether \cs{WUline} uses
40
+  \pkg{lua-ul} or not, if available it is initially set to |true|.
41
+\end{describeopt}
42
+%=<<
43
+
13 44
 \section{Macros}\label{sec:wuline:mac}%>>=
14 45
 \begin{describemacro}{WUline}[\oarg{height}\marg{text}]%>>=
15 46
   This sets \meta{text} and underlines it in a way that looks like MS Word
@@ -29,7 +60,8 @@ so by using \pkg{ulem} or \pkg{stackengine}.
29 60
   [\oarg{height}\oarg{overhang}\oarg{thickness}\marg{text}]
30 61
   This macro can be used to underline bigger portions of text. You should never
31 62
   need it, I guess. Just use \cs{WUline} instead. If you need it, you'll have to
32
-  use the package option \opt{tUline}.\\[\parskip]
63
+  use the package option \opt{tUline} (see
64
+  \autoref{sec:wuline:options:loadtime}).\\[\parskip]
33 65
   If you think you can use this one instead: It underlines \meta{text} at the
34 66
   given \meta{height} (default \texttt{-0.35ex}) with the given \meta{thickness}
35 67
   (default \texttt{0.185ex}). You can specify \meta{overhang} (default

+ 124
- 32
MRTwuline/MRTwuline.sty View File

@@ -10,25 +10,90 @@
10 10
   {MRTwuline}          {\MRTwuline@date}
11 11
   {\MRTwuline@version} {MS Word like underline using ulem or stackengine}
12 12
 
13
-\newif\if@MRTwuline@tikzuline@
14
-\DeclareOption{tikzunderline}{\@MRTwuline@tikzuline@true}
13
+\keys_define:nn { MRTwuline }
14
+  {
15
+    ,rule~ht .tl_set:N = \l__MRTwuline_rule_thickness_tl
16
+    ,ruleht  .meta:n   = { rule~ht = { #1 } }
17
+    ,math~dp .tl_set:N = \l__MRTwuline_math_depth_tl
18
+    ,mathdp  .meta:n   = { math~dp = { #1 } }
19
+    ,text~dp .tl_set:N = \l__MRTwuline_text_depth_tl
20
+    ,textdp  .meta:n   = { text~dp = { #1 } }
21
+  }
22
+
23
+\cs_generate_variant:Nn \keys_set:nn { nV }
24
+
25
+\tl_set:Nn \l__MRTwuline_rule_thickness_tl { 0.185ex }
26
+\tl_set:Nn \l__MRTwuline_math_depth_tl { 0.21ex }
27
+\tl_set:Nn \l__MRTwuline_text_depth_tl { 0.42ex }
28
+
29
+\bool_new:N \l__MRTwuline_luaul_bool
30
+
31
+\let\if@MRTwuline@tikzuline\iffalse
32
+\DeclareOption{tikzunderline}{\let\if@MRTwuline@tikzuline\iftrue}
15 33
 \DeclareOption{tUline}{\ExecuteOptions{tikzunderline}}
34
+\DeclareOption*{ \keys_set:nV { MRTwuline } \CurrentOption }
16 35
 \ProcessOptions\relax
17 36
 
37
+\NewDocumentCommand \MRTwulineSetup { +m }
38
+  {
39
+    \keys_set:nn { MRTwuline } { #1 }
40
+  }
41
+
42
+% support lua-ul if available >>=
43
+\sys_if_engine_luatex:TF
44
+  {
45
+    \file_if_exist:nTF { lua-ul.sty }
46
+      { \bool_set_true:N }
47
+      { \bool_set_false:N }
48
+  }
49
+  { \bool_set_false:N }
50
+  \l__MRTwuline_luaul_bool 
51
+\bool_if:NTF \l__MRTwuline_luaul_bool
52
+  {
53
+    \dim_new:N \l__MRTwuline_luaul_dp_dim
54
+    \dim_new:N \l__MRTwuline_luaul_wd_dim
55
+    \dim_set:Nn \l__MRTwuline_luaul_dp_dim { \l__MRTwuline_text_depth_tl }
56
+    \dim_set:Nn \l__MRTwuline_luaul_wd_dim { \l__MRTwuline_rule_thickness_tl }
57
+    \keys_define:nn { MRTwuline }
58
+      { luaul .bool_set:N = \l__MRTwuline_luaul_bool }
59
+    \bool_set_true:N \l__MRTwuline_luaul_bool
60
+    \PassOptionsToPackage{minimal}{lua-ul}
61
+    \RequirePackage{lua-ul}
62
+    \newunderlinetype \__MRTwuline_luaul_on:
63
+      [
64
+        \luaul@defaultcontext
65
+        wd: \dim_use:N \l__MRTwuline_luaul_wd_dim
66
+        dp: \dim_use:N \l__MRTwuline_luaul_dp_dim
67
+      ]
68
+      { \leaders \MRTwuline_text_rule:n \l__MRTwuline_luaul_dp_dim }
69
+  }
70
+  {
71
+    \msg_new:nnn { MRTwuline } { key~needs~lua-ul }
72
+      {
73
+        The ~ used ~ key ~ `\l_keys_key_str' ~ is ~ only ~ available ~ if ~
74
+        LuaTeX ~ is ~ used.
75
+      }
76
+    \keys_define:nn { MRTwuline }
77
+      { luaul .code:n = { \msg_error:nn { MRTwuline } { key~needs~lua-ul } } }
78
+  }
79
+\keys_define:nn { MRTwuline } { lua-ul .meta:n = { luaul = { #1 } } }
80
+% =<<
81
+
18 82
 % \WUline >>=
19 83
 \NewDocumentCommand \WUline { o m }
20 84
   {
21 85
     \mode_if_math:TF
22
-      { \MRTwuline_math:nn { #1 } { #2 } }
23
-      { \MRTwuline_text:nn { #1 } { #2 } }
86
+      \MRTwuline_math:nn
87
+      \MRTwuline_text:nn
88
+      { #1 } { #2 }
24 89
   }
25
-\cs_new:Npn \MRTwuline_math:nn #1 #2
90
+\cs_new_protected:Npn \MRTwuline_math:nn #1
26 91
   {
27 92
     \IfNoValueTF { #1 }
28
-      { \MRTwuline_math_out:nn { \MRTwuline@mathheight } { #2 } }
29
-      { \MRTwuline_math_out:nn { #1 } { #2 } }
93
+      { \MRTwuline_math_out:nn \l__MRTwuline_math_depth_tl }
94
+      { \MRTwuline_math_out:nn { #1 } }
30 95
   }
31
-\cs_new:Npn \MRTwuline_math_out:nn #1 #2
96
+\cs_new_protected:Npn \MRTwuline_math_out:nn #1 #2
32 97
   {
33 98
     \ThisStyle
34 99
       {
@@ -36,33 +101,61 @@
36 101
         \stackengine
37 102
           { #1 }
38 103
           { $ { \SavedStyle #2 } $ }
39
-          { \rule { \wd0 } { 0.185ex } }
104
+          { \rule { \wd0 } { \l__MRTwuline_rule_thickness_tl } }
40 105
           { U } { c } { F } { F } { S }
41 106
       }
42 107
     \underline { \vphantom { #2 } }
43 108
   }
44
-\cs_new:Npn \MRTwuline_text:nn #1 #2
109
+\cs_new_protected:Npn \MRTwuline_text:nn #1
45 110
   {
46
-    \bgroup
47 111
     \IfNoValueTF { #1 }
112
+      { \MRTwuline_text_out:nn \l__MRTwuline_text_depth_tl }
113
+      { \MRTwuline_text_out:nn { #1 } }
114
+  }
115
+\bool_if:NTF \l__MRTwuline_luaul_bool
116
+  {
117
+    \cs_new_protected:Npn \MRTwuline_text_out:nn #1 #2
48 118
       {
49
-        \markoverwith
50
-          { \rule [ \MRTwuline@textheight ] { 0.25ex } { 0.185ex} } 
119
+        \bool_if:NTF \l__MRTwuline_luaul_bool
120
+          {
121
+            \group_begin:
122
+              \dim_set:Nn \l__MRTwuline_luaul_dp_dim { #1 }
123
+              \dim_set:Nn \l__MRTwuline_luaul_wd_dim
124
+                { \l__MRTwuline_rule_thickness_tl }
125
+              \__MRTwuline_luaul_on:
126
+              #2
127
+            \group_end:
128
+          }
129
+          {
130
+            \bgroup
131
+            \markoverwith { \MRTwuline_text_rule:n { #1 } }
132
+            \ULon { #2 }
133
+          }
51 134
       }
52
-      { \markoverwith { \rule [ #1 ] { 0.25ex } { 0.185ex } } }
53
-    \ULon{#2}
54 135
   }
55
-\MRTutil@def\MRTwuline@mathheight{0.21ex}%
56
-\MRTutil@def\MRTwuline@textheight{-0.42ex}%
136
+  {
137
+    \cs_new_protected:Npn \MRTwuline_text_out:nn #1
138
+      {
139
+        \bgroup
140
+        \markoverwith { \MRTwuline_text_rule:n { #1 } }
141
+        \ULon
142
+      }
143
+  }
144
+\cs_new_protected:Npn \MRTwuline_text_rule:n #1
145
+  {
146
+    \vrule
147
+      \@height \dim_eval:n { \l__MRTwuline_rule_thickness_tl - #1 }
148
+      \@depth \dim_eval:n { #1 }
149
+    \scan_stop:
150
+  }
57 151
 % =<<
58 152
 
59 153
 % \tUline >>=
60
-\if@MRTwuline@tikzuline@
61
-  \ExplSyntaxOff
154
+\if@MRTwuline@tikzuline
155
+  \MRTutil@def\MRTwuline@tUline@width{\l__MRTwuline_rule_thickness_tl}
62 156
   \RequirePackage{tikz}
63 157
   \usetikzlibrary{calc}
64 158
   \RequirePackage{tikzpagenodes}
65
-  \MRTutil@def\MRTwuline@tUline@width{0.185ex}
66 159
   \newlength\MRTwuline@tUline@length
67 160
   \newcount\MRTwuline@tUline@count
68 161
   \MRTutil@def\MRTwuline@gettikzxy#1#2#3% >>=
@@ -72,7 +165,7 @@
72 165
       \xdef#2{\the\pgf@x}%
73 166
       \xdef#3{\the\pgf@y}%
74 167
     }% =<<
75
-  \tikzset{MRTwuline@tUline/.style={line width=\MRTwuline@tUline@width}}
168
+  \tikzset{MRTwuline@tUline/.style={line~width=\MRTwuline@tUline@width}}
76 169
   \MRTutil@def\MRTwuline@EmptyOProcessor#1#2% >>=
77 170
     {%
78 171
       \MRTifEmptyTF{#2}%
@@ -83,27 +176,27 @@
83 176
     {
84 177
       >{\MRTwuline@EmptyOProcessor{-0.35ex}}O{} % height
85 178
       >{\MRTwuline@EmptyOProcessor{0pt}}O{}     % overhang
86
-      >{\MRTwuline@EmptyOProcessor{0.185ex}}O{} % line width
179
+      >{\MRTwuline@EmptyOProcessor{\l__MRTwuline_rule_thickness_tl}}O{}
87 180
       +m
88 181
     }
89 182
     {%
90 183
       \def\MRTwuline@tUline@width{#3}%
91
-      \tikz[remember picture,overlay, baseline=(Begin.base)]
184
+      \tikz[remember~picture, overlay, baseline=(Begin.base)]
92 185
         {%
93
-          \node[anchor=base,inner sep=0pt,outer sep=0pt,xshift=-#2]
186
+          \node[anchor=base,inner~sep=0pt,outer~sep=0pt,xshift=-#2]
94 187
             (Begin) {\strut};
95
-          \MRTwuline@gettikzxy{($(Begin.base)-(current page.south west)$)}
188
+          \MRTwuline@gettikzxy{($(Begin.base)-(current~page.south~west)$)}
96 189
             {\tUline@bx}{\tUline@by}%
97 190
         }%
98 191
       #4%
99
-      \tikz[remember picture,overlay, baseline=(End.base)]
192
+      \tikz[remember~picture,overlay, baseline=(End.base)]
100 193
         {%
101
-          \node[anchor=base,inner sep=0pt,outer sep=0pt,xshift=+#2]
194
+          \node[anchor=base,inner~sep=0pt,outer~sep=0pt,xshift=+#2]
102 195
             (End) {\strut};%
103
-          \MRTwuline@gettikzxy{($(End.base)-(current page.south west)$)}
196
+          \MRTwuline@gettikzxy{($(End.base)-(current~page.south~west)$)}
104 197
             {\tUline@ex}{\tUline@ey}%
105 198
         }%
106
-      \begin{tikzpicture}[overlay,remember picture]
199
+      \begin{tikzpicture}[overlay,remember~picture]
107 200
         \ifdim\dimexpr\tUline@ey-\tUline@by = 0pt
108 201
           % one line
109 202
           \draw[MRTwuline@tUline] ($(Begin.base)+(0,#1)$)
@@ -111,9 +204,9 @@
111 204
         \else
112 205
           % multiple lines
113 206
           \draw
114
-            ($(current page text area.west)-(#2,0)$) node(WestLine){};
207
+            ($(current~page~text~area.west)-(#2,0)$) node(WestLine){};
115 208
           \draw
116
-            ($(current page text area.east)+(#2,0)$) node(EastLine){};
209
+            ($(current~page~text~area.east)+(#2,0)$) node(EastLine){};
117 210
           \tUline@drawBtoE{#1}
118 211
           \ifdim\dimexpr\tUline@by-\tUline@ey>\baselineskip
119 212
             % more than two lines
@@ -147,7 +240,6 @@
147 240
         ($(Begin.base)+(0,#1)$) -- ($(Begin.base -| EastLine)+(0,#1)$)
148 241
         ($(End.base)+(0,#1)$) -- ($(End.base -| WestLine)+(0,#1)$);%
149 242
     }% =<<
150
-  \ExplSyntaxOn
151 243
 \fi
152 244
 % =<<
153 245
 

Loading…
Cancel
Save