summaryrefslogtreecommitdiff
path: root/language/korean/kotex-plain/kotexutf-core.tex
blob: c183291560b0ec7cf9254dfe4f438dd009715ec0 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
%% File `kotexutf-core.tex`
%%
%% Copyright (C) 2009-2015 Dohyun Kim <nomos at ktug org>
%% Copyright (C) 2015      Kangsoo Kim <karnes at ktug org>
%%
%% This work 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.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
\expandafter\ifx\csname eTeXversion\endcsname\relax
  \errhelp{kotexutf requires e-TeX. Please run etex or pdftex.}
  \errmessage{kotexutf : Not running under e-TeX.}
  \expandafter\endinput
\fi

%% frenchspacing is default
\frenchspacing

\def\unihangul@two@octets#1#2{%
    \expandafter\unihangulchar\expandafter{%
      \number\numexpr
	(`#1 - 192) * 64 +
	(`#2 - 128) \relax}}
\def\unihangul@three@octets#1#2#3{%
    \expandafter\unihangulchar\expandafter{%
      \number\numexpr
	(`#1 - 224) * 4096 +
	(`#2 - 128) * 64 +
	(`#3 - 128) \relax}}
\def\unihangul@four@octets#1#2#3#4{%
    \expandafter\unihangulchar\expandafter{%
      \number\numexpr
	(`#1 - 240) * 262144 +
	(`#2 - 128) * 4096 +
	(`#3 - 128) * 64 +
	(`#4 - 128) \relax}}

\count@"80 \loop
  \uccode\count@\z@
  \lccode\count@\z@
  \catcode\count@=12
\ifnum\count@<"BF \advance\count@\@ne \repeat

\count@"C2 \loop
  \uccode\count@\z@
  \lccode\count@\z@
  \begingroup
  \lccode`\~\count@
  \lowercase{\endgroup
    \protected\def~##1{%
      \ifcsname U8:\string~\string##1\endcsname
        \csname U8:\string~\string##1\expandafter\endcsname
      \else
        \expandafter\unihangul@two@octets
        \expandafter~\expandafter##1%
      \fi }}
\ifnum\count@<"DF \advance\count@\@ne \repeat

\count@"E0 \loop
  \uccode\count@\z@
  \lccode\count@\z@
  \begingroup
  \lccode`\~\count@
  \lowercase{\endgroup
  \protected\def~##1##2{%
    \ifcsname U8:\string~\string##1\string##2\endcsname
      \csname U8:\string~\string##1\string##2\expandafter\endcsname
    \else
      \expandafter\unihangul@three@octets
      \expandafter~\expandafter##1\expandafter##2%
    \fi }}
\ifnum\count@<"EF \advance\count@\@ne \repeat

\count@"F0 \loop
  \uccode\count@\z@
  \lccode\count@\z@
  \begingroup
  \lccode`\~\count@
  \lowercase{\endgroup
    \protected\def~##1##2##3{%
      \ifcsname U8:\string~\string##1\string##2\string##3\endcsname
        \csname U8:\string~\string##1\string##2\string##3\expandafter\endcsname
      \else
        \expandafter\unihangul@four@octets
        \expandafter~\expandafter##1\expandafter##2\expandafter##3%
      \fi }}
\ifnum\count@<"F4 \advance\count@\@ne \repeat

%% subfont plane and char slot
\def\geth@ngulpl@ne@ndch@r{%
  \count@\numexpr % 1 / 256 = .00390625
    \number\dimexpr.00390625\dimexpr\unih@ngulpoint sp\relax\relax
    \relax
  \chardef\h@ngulch@r % hangul char slot
    \number\numexpr\unih@ngulpoint-\@cclvi*\count@\relax
  \let\h@ngulpl@ne\@empty % hangul subfont plane
  \ifnum\count@>\@cclv
    \ifnum\count@>4095
      \def\h@ngulpl@ne{1}\count@\numexpr\count@-4096\relax
    \else
      \def\h@ngulpl@ne{0}%
    \fi
    \@tempcnta\numexpr % 1 / 256 = .00390625
      \number\dimexpr.00390625\dimexpr\count@ sp\relax\relax
      \relax
    \edef\h@ngulpl@ne{\h@ngulpl@ne\dhucsnumt@hex\@tempcnta}%
    \count@\numexpr\count@-\@cclvi*\@tempcnta\relax
  \fi
  \@tempcnta\numexpr % 1 / 16 = .0625
    \number\dimexpr.0625\dimexpr\count@ sp\relax\relax
    \relax
  \edef\h@ngulpl@ne{\h@ngulpl@ne\dhucsnumt@hex\@tempcnta}%
  \count@\numexpr\count@-\sixt@@n*\@tempcnta\relax
  \edef\h@ngulpl@ne{\h@ngulpl@ne\dhucsnumt@hex\count@}%
}
\def\dhucsnumt@hex#1{\ifcase\number#1
  0\or 1\or 2\or 3\or 4\or 5\or 6\or 7\or
  8\or 9\or a\or b\or c\or d\or e\or f\else \dhucserr@r\fi
}

%% hangul font specific dimens
%% changes for avoiding errors on MiKTeX, 2015/10/07, by Karnes.
%\def\dhucs@hu{}
%\def\dhucs@interhchar{}
%\def\dhucs@fullstoplower{}
%\def\dhucs@questionlower{}
%\def\dhucs@exclamationlower{}
\def\dhucs@hu{\z@}
\def\dhucs@interhchar{\z@}
\def\dhucs@fullstoplower{\z@}
\def\dhucs@exclamationlower{\z@}
\def\dhucs@questionlower{\z@}
\def\dhucs@serifhangulfont{nanummj}
\def\dhucs@sanshangulfont{nanumgt}
\def\dhucs@monohangulfont{nanumgt}
\def\dhucs@serifhanjafont{nanumgt}
\def\dhucs@sanshanjafont{nanumgt}
\def\dhucs@monohanjafont{nanumgt}

\def\usehangulfontspec#1{%
  \begingroup
    \immediate\openin\z@=hfontspec.#1 %
    \ifeof\z@
      \message{\space\space *** Cannot find hangul font-spec file hfontspec.#1 ***\space\space}
    \else
      \endlinechar\m@ne
      \get@hfnt@spec@
    \fi
    \immediate\closein\z@
  \endgroup}
\def\get@hfnt@spec@{%
    \read\z@ to \@tempb
    \ifx\@tempb\@empty
      \let\next\relax
    \else
      \expandafter\get@hfnt@spec@@\@tempb\@@nil
      \let\next\get@hfnt@spec@
    \fi\next}
\def\get@hfnt@spec@@#1 = #2\@@nil{%
  \expandafter\gdef\csname dhucs@#1\endcsname{#2}}

%% \unih@ngulpoint is unicode code point
\newcount\unih@ngulpoint

%% protect \unihangulchar
\protected\def\unihangulchar#1{%
  \unih@ngulpoint#1\relax
  \futurelet\dhucs@next\unihangulchar@@}
\def\unihangulchar@@{% check what comes next to hangul?
  % \nexttoh@ngul = 1 : ascii opening parentheses
  % \nexttoh@ngul = 2 : ascii closing parentheses
  % \nexttoh@ngul = 3 : ascii numbers
  % \nexttoh@ngul = 4 : ascii fullstop
  % \nexttoh@ngul = 5 : ascii question mark
  % \nexttoh@ngul = 6 : ascii exclamation mark
  % \nexttoh@ngul = 0 : all others
  \chardef\nexttoh@ngul\z@
  % \puncnobre@k = 0 : this is not char ``orphan'' case
  % \puncnobre@k = 1 : do not break before char ``orphan''
  \chardef\puncnobre@k\z@
  % avoiding char ``orphan'' operates only in four cases :
  % [hangulchar] [par]
  % [hangulchar] [space] [par]
  % [hangulchar] [.?!] [par]
  % [hangulchar] [.?!] [space] [par]
  \ifx\fi\dhucs@next \expandafter\let\csname dhucs@next\endcsname\relax \fi
  \ifx\ifx\dhucs@next \expandafter\let\csname dhucs@next\endcsname\relax \fi
  \ifx\par\dhucs@next
    \chardef\puncnobre@k\@ne
    \let\unihangul@branch\unihangulchar@@@
  \else
    \ifx\@sptoken\dhucs@next
      \let\unihangul@branch\check@next@to@sptoken
    \else
      \if\noexpand\dhucs@next\relax
      \else
        \check@dhucs@next@ascii456123\@nil
      \fi
      \ifnum\nexttoh@ngul>\thr@@
        \let\unihangul@branch\check@next@to@puncs
      \else
        \let\unihangul@branch\unihangulchar@@@
      \fi
    \fi
  \fi
  \unihangul@branch
}

\def\check@next@to@sptoken{%
  \afterassignment\check@next@to@sptoken@\let\dhucs@next= }
\def\check@next@to@sptoken@{%
  \futurelet\dhucs@nextnext\check@next@to@sptoken@@}
\def\check@next@to@sptoken@@{%
  \ifx\dhucs@nextnext\par
    \chardef\puncnobre@k\@ne
  \fi
  \unihangulchar@@@\dhucs@next
}

\def\check@next@to@puncs{%
  \afterassignment\check@next@to@puncs@\let\dhucs@next= }
\def\check@next@to@puncs@{%
  \futurelet\dhucs@nextnext\check@next@to@puncs@@}
\def\check@next@to@puncs@@{%
  \ifx\dhucs@nextnext\par
    \chardef\puncnobre@k\@ne
    \expandafter\unihangulchar@@@\expandafter\dhucs@next
  \else
    \ifx\dhucs@nextnext\@sptoken
      \expandafter\expandafter\expandafter\check@next@to@punc@sptoken
    \else
      \expandafter\expandafter\expandafter\unihangulchar@@@
      \expandafter\expandafter\expandafter\dhucs@next
    \fi
  \fi
}

\def\check@next@to@punc@sptoken{%
  \afterassignment\check@next@to@punc@sptoken@\let\dhucs@nextnext= }
\def\check@next@to@punc@sptoken@{%
  \futurelet\dhucs@nextnextnext\check@next@to@punc@sptoken@@}
\def\check@next@to@punc@sptoken@@{%
  \ifx\dhucs@nextnextnext\par
    \chardef\puncnobre@k\@ne
  \fi
  \unihangulchar@@@\dhucs@next\dhucs@nextnext
}

%% see lucenc.dfu
\def\check@dhucs@next@ascii#1{%
  \def\@tempa{#1}%
  \ifx#1\@nil
    \let\next\relax
  \else
    \let\next\check@dhucs@next@ascii
    \edef\@tempb{\csname nexttohangul-#1\endcsname}%
    \expandafter\check@dhucs@next@ascii@\@tempb\@nnil
  \fi\next
}
\def\check@dhucs@next@ascii@#1{%
  \ifx#1\@nnil\let\next@\relax
  \else
    \ifx#1\dhucs@next
      \chardef\nexttoh@ngul\@tempa
      \let\next@\remove@to@nnil \let\next\remove@to@nil
    \else
      \let\next@\check@dhucs@next@ascii@
    \fi
  \fi\next@
}
\def\remove@to@nil#1\@nil{}
\def\remove@to@nnil#1\@nnil{}

%%% if \strictcharcheck is defined ...
\ifdefined\strictcharcheck
  \def\dhucs@check@if@char@exists{%
    \unless\iffontchar\font@name\h@ngulch@r
      \errmessage{Character \number\h@ngulch@r\space
        doesn't exist in font \fontname\font@name}%
    \fi}
\else
  \let\dhucs@check@if@char@exists\relax
\fi

%% hangul space factor
\mathchardef\Hangul@spacefactor=1001\relax
\mathchardef\Hanja@spacefactor=1002\relax
\mathchardef\nobreak@spacefactor=998\relax

\def\getthish@ngulcl@ss{% what is current hangul category?
  % \thish@ngul = 1 : hangul
  % \thish@ngul = 2 : hanja, hiragana, katakana
  % \thish@ngul = 3 : opening parentheses; NOT in use: see lucenc.dfu
  % \thish@ngul = 4 : closing parentheses; NOT in use: see lucenc.dfu
  % \thish@ngul = 0 : all others
  \ifnum\unih@ngulpoint<12352
    \chardef\thish@ngul\z@ % cjk symbols
  \else\ifnum\unih@ngulpoint<12539
    \chardef\thish@ngul\tw@ % hiragana, katakana
  \else\ifnum\unih@ngulpoint<13312
    \chardef\thish@ngul\z@ % cjk symbols
  \else\ifnum\unih@ngulpoint<44032
    \chardef\thish@ngul\tw@ % hanja ext A; hanja unified
  \else\ifnum\unih@ngulpoint<57344
    \chardef\thish@ngul\@ne % hangul
  \else\ifnum\unih@ngulpoint<64256
    \chardef\thish@ngul\tw@ % hanja compatibillity
  \else\ifnum\unih@ngulpoint<65520
    \chardef\thish@ngul\z@ % full/half width marks
  \else
    \chardef\thish@ngul\tw@ % hanja ext. B mostly
  \fi\fi\fi\fi\fi \fi\fi
}

%% disallow linebreak after opening parentheses
\sfcode`\(=\nobreak@spacefactor
\sfcode`\`=\nobreak@spacefactor
\sfcode`\[=\nobreak@spacefactor
\sfcode`\{=\nobreak@spacefactor
%% TeX inserts \discretionary{}{}{} always after hyphen char,
%% so we can safely give nobreak-spacefactor to ``-'' to suppress
%% unwanted micro-space after latin hyphen char.
\sfcode`\-=\nobreak@spacefactor

\def\dobeforeh@ngulch@r{%
  \ifhmode
    \ifcase\lastnodetype
      % e-TeX's lastnodetype 0 is char node
      \dhucs@normal@break@before@cjk
    \or % hlist node
        % As \hbox returns spacefactor to 1000,
        % we cannot identify what was before this korean char.
        % So, allowing linebreak is somewhat dangerous; We Do, however.
      \ifcase\thish@ngul
        \or \ifcase\puncnobre@k\breakbetweenhanja
              \or\nobreakbetweenhanja\fi
        \or \ifcase\puncnobre@k\breakbetweenhanja
              \or\nobreakbetweenhanja\fi
      \fi
    \or % vlist node
    \or % rule node
    \or % ins node
    \or % mark node
    \or % adjust node
    \or % ligature node
      \ifnum\spacefactor>\nobreak@spacefactor
        \ifcase\thish@ngul
          \or \ifcase\puncnobre@k\breakafterasciichar
                \or\nobreakafterasciichar\fi
          \or \ifcase\puncnobre@k\breakafterasciichar
                \or\nobreakafterasciichar\fi
        \fi
      \fi
    \or % disc node
    \or % whatsit node
        % how do we know what there was before whatsit?
      \dhucs@normal@break@before@cjk
    \or % math node
      \ifcase\thish@ngul
        \or \ifcase\puncnobre@k\breakafterinlinemath
              \or\nobreakafterinlinemath\fi
        \or \ifcase\puncnobre@k\breakafterinlinemath
              \or\nobreakafterinlinemath\fi
      \fi
    \or % glue node
    \or % kern node, which is another source of headache!
      \ifdim\lastkern=\z@
        % is it safe to break lines after \kern 0pt?
        \dhucs@normal@break@before@cjk
      \else
        \ifnum\spacefactor>\nobreak@spacefactor
          \ifdim\lastkern=\@tempdima % see redefinition of \sw@slant
            \ifnum\spacefactor>\@m
              \ifcase\thish@ngul
                \or \ifcase\puncnobre@k\breakbetweenhanja
                      \or\nobreakbetweenhanja\fi
                \or \ifcase\puncnobre@k\breakbetweenhanja
                      \or\nobreakbetweenhanja\fi
              \fi
            \else
              \ifcase\thish@ngul
                \or \ifcase\puncnobre@k\breakafterasciichar
                      \or\nobreakafterasciichar\fi
                \or \ifcase\puncnobre@k\breakafterasciichar
                      \or\nobreakafterasciichar\fi
              \fi
            \fi
          \else
            \ifcase\thish@ngul
                \or \ifcase\puncnobre@k\breakbetweenhanja
                      \or\nobreakbetweenhanja\fi
                \or \ifcase\puncnobre@k\breakbetweenhanja
                      \or\nobreakbetweenhanja\fi
            \fi
          \fi
        \fi
      \fi
      \@tempdima\z@
    \or % penalty node
        % Even after \nobreak, inter-hangulchar kern should be applied!
      \ifnum\lastpenalty<\@M
        \dhucs@normal@break@before@cjk
      \else
        \chardef\puncnobre@k\@ne
        \dhucs@normal@break@before@cjk
      \fi
    \or % unset node
    \or % math mode node
    \fi
  \fi
}

\ifdefined\sw@slant
  %% detect last italiccorr
  \edef\sw@slant{\unexpanded\expandafter{\sw@slant\@tempdima\lastkern}}
\else
  \unless\ifdefined\@tempdima \newdimen\@tempdima\@tempdima=0pt \fi
\fi

\def\dhucs@normal@break@before@cjk{%
  \ifnum\spacefactor>\nobreak@spacefactor
    \ifcase\thish@ngul
        % other cjk char: do nothing
    \or % hangul
      \ifnum\spacefactor=\Hangul@spacefactor
        \ifcase\puncnobre@k\breakbetweenhangul
          \or\nobreakbetweenhangul\fi
      \else
        \ifnum\spacefactor=\Hanja@spacefactor
          \ifcase\puncnobre@k\breakbetweenhanja
            \or\nobreakbetweenhanja\fi
        \else
          \ifcase\puncnobre@k\breakafterasciichar
            \or\nobreakafterasciichar\fi
        \fi
      \fi
    \or % hanja, hiragana, katakana
      \ifnum\spacefactor=\Hangul@spacefactor
        \ifcase\puncnobre@k\breakbetweenhanja
          \or\nobreakbetweenhanja\fi
      \else
        \ifnum\spacefactor=\Hanja@spacefactor
          \ifcase\puncnobre@k\breakbetweenhanja
            \or\nobreakbetweenhanja\fi
        \else
          \ifcase\puncnobre@k\breakafterasciichar
            \or\nobreakafterasciichar\fi
        \fi
      \fi
    \fi
  \fi
}

\def\do@fterh@ngulch@r{%
  \ifhmode
    \ifcase\nexttoh@ngul
      \ifcase\thish@ngul
          \declarehanjaspacefactor
      \or \declarehangulspacefactor
      \or \declarehanjaspacefactor
      \or \declarenobreakspacefactor
      \or \declarehanjaspacefactor
      \fi
    \or \breakbeforeasciichar % (
    \or % )
      \spacefactor\@m
    \or \kernbeforeasciichar % 123
    \or \expandafter\expandafter\expandafter\asciifullstopafterhangul % .
    \or \expandafter\expandafter\expandafter\asciiquestionafterhangul % ?
    \or \expandafter\expandafter\expandafter\asciiexclamationafterhangul % !
    \fi
  \fi
}

\def\declarenobreakspacefactor{\spacefactor\nobreak@spacefactor}
\def\declarehangulspacefactor{\spacefactor\Hangul@spacefactor}
\def\declarehanjaspacefactor{\spacefactor\Hanja@spacefactor}

%% default linebreaking command
\def\breakbetweenhanja{\discretionary{}{}{}}
\def\nobreakbetweenhanja{}

%% under option [finemath], hfontspec.un becomes active.
%% otherwize, all font-spec value is 0pt.
\ifdefined\finemath %\if@dhucsfinemath
  %% As Korean typesetting allows linebreak at any point between hangul char,
  %% \doublehyphendemerits does not have meaning any longer.
  \doublehyphendemerits=0
  %% Now that some code to suppress char ``orphan'' has been added,
  %% \finalhyphendemerits does not have much meaning, either.
  %% Moreover, \finalhyphendemerits discourages linebreak of final word
  %% within a paragraph; undesirable when the final word is long.
  \finalhyphendemerits=0
  %%
  \usehangulfontspec{default}
  \def\breakbetweenhangul{\discretionary{}{}{\kern\dhucs@interhchar}}
  \def\nobreakbetweenhangul{\kern\dhucs@interhchar}
  % \dimexpr used, because \newdimen\something\something=1em fixes
  % \something's dimen size when it is initially assigned.
  % In this case, for example, \dhucs@hu applied to normal size is the same size
  % as to \Huge size font. This does not seem to be what we want.
  % Accordingly, we decided to declare \dhucs@hu as a macro, not a dimen.
  % Now that \dhucs@hu is a macro, e-TeX's \dimexpr enables simple definition
  % of its multiplication.
  \def\breakafterinlinemath{\hskip\dimexpr\dhucs@hu*3\relax\relax}
  % At above line, \dimexpr absorbs the first \relax;
  % second \relax terminates \hskip's arguments.
  % On the other hand, as \kern does not scan for ``plus'' or ``minus,''
  % another \relax seems to be redundant at following line.
  \def\nobreakafterinlinemath{\kern\dimexpr\dhucs@hu*3\relax}
  \def\breakafterasciichar{\hskip\dimexpr\dhucs@hu*2\relax\relax}
  \def\nobreakafterasciichar{\kern\dimexpr\dhucs@hu*2\relax}
  \def\breakbeforeasciichar{\hskip\dimexpr\dhucs@hu*2\relax\relax}
  \def\kernbeforeasciichar{\kern\dimexpr\dhucs@hu*2\relax}
  \def\asciifullstopafterhangul#1{%
    \lower\dhucs@fullstoplower\hbox\bgroup#1\dhucs@check@another@punc}
  \def\asciiquestionafterhangul#1{%
    \lower\dhucs@questionlower\hbox\bgroup
      \let\dhucs@kern@before@quot@char\dhucs@kern@before@quot@char@
      \kern\dimexpr\dhucs@hu*3\relax#1\dhucs@check@another@punc}
  \def\asciiexclamationafterhangul#1{%
    \lower\dhucs@exclamationlower\hbox\bgroup
      \let\dhucs@kern@before@quot@char\dhucs@kern@before@quot@char@
      \kern\dimexpr\dhucs@hu*4\relax#1\dhucs@check@another@punc}
  \def\dhucs@kern@before@quot@char@{%
    \ifx'\dhucs@next\kern\dimexpr\dhucs@hu*3\relax\fi
    \spacefactor1003\relax} % for U+2019, U+201D; see lucenc.dfu
  \let\dhucs@kern@before@quot@char\relax
  %% lowering multiple puctuations:
  %% If next char is a punctuation, do not close \hbox and scan another char.
  \def\dhucs@check@another@punc{%
    \futurelet\dhucs@next\dhucs@check@another@punc@}
  \def\dhucs@check@another@punc@{%
    \chardef\nexttoh@ngul\z@
    \if\noexpand\dhucs@next\relax\else
      \check@dhucs@next@ascii456\@nil
    \fi
    \dhucs@check@another@punc@@}
  \def\dhucs@check@another@punc@@{%
    \ifcase\nexttoh@ngul
          \expandafter\dhucs@check@another@punc@end
      \or \expandafter\dhucs@check@another@punc@end
      \or \expandafter\dhucs@check@another@punc@end
      \or \expandafter\dhucs@check@another@punc@end
      \or \let\dhucs@kern@before@quot@char\relax
          \expandafter\dhucs@check@another@punc@@@
      \or \let\dhucs@kern@before@quot@char\dhucs@kern@before@quot@char@
          \expandafter\dhucs@check@another@punc@@@
      \or \let\dhucs@kern@before@quot@char\dhucs@kern@before@quot@char@
          \expandafter\dhucs@check@another@punc@@@
    \fi}
  \def\dhucs@check@another@punc@@@#1{%
    \kern\dhucs@hu\relax #1\dhucs@check@another@punc}
  \def\dhucs@check@another@punc@end{%
    \dhucs@kern@before@quot@char
    \global\count@\spacefactor\egroup\spacefactor\count@}
\else
  \usehangulfontspec{default}
  \def\breakafterinlinemath{\hskip\z@skip}
  \def\nobreakafterinlinemath{}
  \def\breakbetweenhangul{\discretionary{}{}{}}
  \def\nobreakbetweenhangul{}
  \def\breakafterasciichar{\hskip\z@skip}
  \def\nobreakafterasciichar{}
  \def\breakbeforeasciichar{\hskip\z@skip}
  \def\kernbeforeasciichar{}
  \def\asciifullstopafterhangul{}
  \def\asciiquestionafterhangul{}
  \def\asciiexclamationafterhangul{}
\fi

%% linebreaking related to cjk symbols
\def\cjksymbolextraspace{\discretionary{}{}{}}
\def\cjksymbolskip{%
  \ifhmode
    \ifnum\spacefactor>\nobreak@spacefactor
      \ifnum\lastpenalty<\@M
        \cjksymbolextraspace
      \fi
    \fi
  \else
    \leavevmode
  \fi}
\def\postcjksymskip{\ifhmode\declarehanjaspacefactor\fi}
\def\postcjksymnobreak{\ifhmode\declarehanjaspacefactor\nobreak\fi}
\def\postcjksymbol{\ifhmode\declarehanjaspacefactor\fi}
\def\kernbeforelatinquoteclose{%
  \ifhmode\ifnum\spacefactor=1003 \kern\dimexpr\dhucs@hu*3\relax\fi\fi}
\def\cjksymbolunskip{}

%% \disablehangulfontspec disables all the font-spefic spaces and dimens
%% except the space after inline math.
\def\disablehangulfontspec{%
  \def\breakbetweenhangul{\discretionary{}{}{}}
  \let\nobreakbetweenhangul\@empty
  \def\breakafterasciichar{\hskip\z@skip}
  \let\nobreakafterasciichar\@empty
  \let\breakbeforeasciichar\breakafterasciichar
  \let\kernbeforeasciichar\@empty
  \let\asciifullstopafterhangul\relax
  \let\asciiquestionafterhangul\relax
  \let\asciiexclamationafterhangul\relax
}

%% \disablehangullinebreak disables all linebreaking
%% related to hangul typesetting.
\def\disablehangullinebreak{%
  \let\unihangulchar@\unihangulchar@@@
  \let\dobeforeh@ngulch@r\relax
  \let\do@fterh@ngulch@r\relax
  \let\cjksymbolskip\leavevmode}


%% bangjom emphasis
\def\dhucs@emph#1{}
\newdimen\dhucs@emph@raise
\protected\def\dotemph#1{\begingroup
  \setbox\z@\hbox{#1}\dhucs@emph@raise\ht\z@
  \advance\dhucs@emph@raise -.4em
  \let\dhucs@emph\dot@emph
  #1\endgroup}
\def\dot@emph#1{%
  \ifnum\thish@ngul>\z@ %\ifnum\thish@ngul<\thr@@ % hangul or hanja
    \setbox\z@\hbox{#1}\dimen@\wd\z@
    \rlap{\raise\dhucs@emph@raise
      \hbox to\dimen@{\normalfont\bfseries\hss˙\hss}}\fi %\fi
}

\endinput