summaryrefslogtreecommitdiff
path: root/fonts/newtx/tex/newtxtext.sty
blob: ac7033051d35bd4a4b60fafcd0fe33c739c4d1f4 (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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
\NeedsTeXFormat{LaTeX2e}

% Based originally on Young Ryu's txfonts.sty, v.1.1.1
%
% Changes from original txfonts.sty by Michael Sharpe, msharpe at ucsd dot edu;
% Text and math versions now separate. 
% Added scaled keyword and osf option;
% Text is now directed to an extension of TeXGyreTermes rather than tx.
% 1.7 is first version of newtxtext to support both [pdf]latex and unicode latex.
\def\ntx@showstate{0} % turn off state debugging---1 for on
%\def\ntx@state{0} % 0 for both, 1 for tutex only, 2 for legacy only
\def\setstate#1{\if 1\ntx@showstate\typeout{State=#1}\fi}

\def\fileversion{1.737}
\def\filedate{2024/01/11}
\ProvidesPackage{newtxtext}[%
\filedate\space v\fileversion (Michael Sharpe) latex and unicode latex support for TeXGyreTermesX]

\message{`newtxtext' v\fileversion, \filedate\space Text macros taking advantage of TeXGyre Termes and its extensions (msharpe)}
\RequirePackage{xpatch,xcolor} % need to patch \scshape
\RequirePackage{iftex,xkeyval,etoolbox,textcomp}
\RequirePackage{xstring,ifthen,scalefnt} % for \textfrac
\RequirePackage{mweights} % should be in latex kernel
\DeclareEncodingSubset{TS1}{ntx*}{0}
\input{binhex}

\newcount\ntx@tmpcnta
\newcount\ntx@cnt \ntx@cnt=0

%KOMA check
\newif\ifntx@KOMA
\@ifundefined{ftntm@font}{}{\ntx@KOMAtrue}
%\@ifundefined{ver@scrextend.sty}{}{\ntx@KOMAtrue}
%LTX check
\newif\ifntx@LTX
\@ifclassloaded{article}{\ntx@LTXtrue}{}
\@ifclassloaded{report}{\ntx@LTXtrue}{}
\@ifclassloaded{book}{\ntx@LTXtrue}{}
\newif\ifntx@AMSloaded
\@ifclassloaded{amsart}{\ntx@AMSloadedtrue}{}
\@ifclassloaded{amsproc}{\ntx@AMSloadedtrue}{}
\@ifclassloaded{amsbook}{\ntx@AMSloadedtrue}{}

% Engine check
\newif\ifntx@newtx
\@ifundefined{ntx@otfmathtrue}{\newif\ifntx@otfmath}{}
 % default is type1 math
%
\@ifundefined{ntx@otftexttrue}{% not run from newtx.sty
   \newif\ifntx@otftext
   \iftutex\ntx@otftexttrue\fi %  otf text for unicode 
%iftex's \iftutex returns true for LuaTeX and XeTeX, not [pdf]latex
  %\newif\ifntx@nofontspec 
  % default is to load fontspec iftutex  
  % might have been defined in newtx.sty
  \def\ntx@id{0} % make it appear that newtxtext was chosen in newtx
}{% run from newtx.sty
  \ntx@newtxtrue%
  %\ifntx@otftext\typeout{ntx@otftexttrue.}\else\typeout{ntx@otftextfalse.}\fi
}
%%%%%%%%%%%%%%%%%%
%
\newif\ifntx@nomath\ntx@nomathfalse % load fontspec with no-math

\newif\ifntx@lining\ntx@liningtrue
\newif\ifntx@tabular\ntx@tabulartrue % default is tabular lining figures
%\@ifundefined{ver@newtxmath.sty}{\iftutex\ntx@otfmathtrue\fi}{}

\DeclareOptionX{type1}[true]{}
%{\def\ntx@tmpx{\@nameuse{if#1}\ntx@otftextfalse\fi}
\DeclareOptionX{type1text}[true]{}

\DeclareOptionX{nofontspec}[true]{}

\DeclareOptionX{no-math}[true]{%
\@nameuse{if#1}\ntx@nomathtrue\fi
}
\DeclareOptionX{otfmath}[true]{%
\@nameuse{if#1}\ntx@otfmathtrue\fi
}
\def\ntx@defaultfeatures{}
\DeclareOptionX{defaultfeatures}{\def\ntx@defaultfeatures{#1}}

%Figure style options
\def\ntx@dfltfigurestyle{lf}
\def\ntx@dfltfigurealign{t}

\DeclareOptionX{lining}[true]{%
\@nameuse{ntx@lining#1}
}
\DeclareOptionX{lf}[true]{%
\@nameuse{ntx@lining#1}
}
\DeclareOptionX{oldstyle}[true]{%
\@nameuse{if#1}%
  \ntx@liningfalse
\else
  \ntx@liningtrue
\fi
}
\DeclareOptionX{osf}[true]{%
\@nameuse{if#1}%
  \ntx@liningfalse
\else
  \ntx@liningtrue
\fi
}
\DeclareOptionX{tabular}[true]{%
\@nameuse{ntx@tabular#1}
}
\DeclareOptionX{t}[true]{%
\@nameuse{ntx@tabular#1}
}
\DeclareOptionX{proportional}[true]{%
\@nameuse{if#1}%
  \ntx@tabularfalse
\else
  \ntx@tabulartrue
\fi
}
\DeclareOptionX{p}[true]{%
\@nameuse{if#1}%
  \ntx@tabularfalse
\else
  \ntx@tabulartrue
\fi
}

%Scale
\newcommand*{\ntx@scale}{1}  % actual scaled command in \ntx@scaled
\DeclareOptionX{scale}{\renewcommand*{\ntx@scale}{#1}}
\DeclareOptionX{scaled}{\renewcommand*{\ntx@scale}{#1}}
%\newdimen\ntxsups@scale
%\newdimen\ntxsups@raise
%\def\ntxsups@raised{\z@}
%\def\ntxsups@Lspaced{.03em}
%\def\ntxsups@Rspaced{.03em}
%\def\ntxsups@scaledval{1}
%\def\ntxsups@scalefactor{1}
%\newcommand*{\ntxsups@color}{black}
\newif\ifntx@supsflag
\DeclareOptionX{supscaled}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@scaledval}{#1}}%added 2023/09/16
\DeclareOptionX{supscale}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@scaledval}{#1}}%added 2023/09/16
\DeclareOptionX{supsraised}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@raised}{#1}}%added 2023/09/16
\DeclareOptionX{supLspaced}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@Lspaced}{#1}}%added 2023/09/16
\DeclareOptionX{supRspaced}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@Rspaced}{#1}}%added 2023/09/16
\DeclareOptionX{supspaced}{\ntx@supsflagtrue}%
\DeclareOptionX{supscolor}{\ntx@supsflagtrue}%{\renewcommand*{\ntxsups@color}{#1}} %added 2023/09/16

\newif\ifntx@defaultsups
%\newif\ifntx@adobesc % we don't use this exc. in fd, but may in future
\newif\ifntx@scosf
\newif\ifntx@largesc 
\newif\ifntx@helv \ntx@helvtrue % default is to load helvetica as sans serif font
\newif\ifntx@tt \ntx@tttrue % default is to load ntxtt as typewriter font
\newif\ifntx@thrm
\newif\ifntx@sl 
\newif\ifntx@oldsu\ntx@oldsutrue %use old versions of sups/subs
\def\ntx@suver{alt} % sups version, alt (the old version) or {} for new version
% Other options
\DeclareOptionX{defaultsups}[true]{%
\@nameuse{ntx@defaultsups#1}
}
\DeclareOptionX{babel}[true]{%
\@nameuse{ntx@babel#1}% for backward compatibility
}
\DeclareOptionX{largesc}[true]{%
\@nameuse{ntx@largesc#1}
}
\DeclareOptionX{nohelv}[true]{%
\@nameuse{if#1}\ntx@helvfalse\fi}%

\DeclareOptionX{nott}[true]{%
\@nameuse{if#1}\ntx@ttfalse\fi}%

\def\ntx@helvratio{.94}
\DeclareOptionX{helvratio}[0.94]{%
\def\ntx@helvratio{#1}
}
\def\ntx@spcmag{1}
\def\ntx@spc{.25em}
\def\ntx@stretch{.2em}
\def\ntx@shrink{.1em}
\def\ntx@nospc{T}

\DeclareOptionX{spcfactor}{%
\def\ntx@spcmag{#1}\def\ntx@nospc{F}
}
\DeclareOptionX{spacing}{%
\def\ntx@spc{#1}
}
\DeclareOptionX{stretch}{%
\def\ntx@stretch{#1}
}
\DeclareOptionX{shrink}{%
\def\ntx@shrink{#1}
}
\def\ntx@thmshape{i} % other option is slanted
\def\ntx@defaultfeatures{}
\newif\ifntx@zeroslash
\def\ntx@thmlin{X} % default is to not change to lining
\def\ntx@noti{T}\def\ntx@nolo{T}
\DeclareOptionX{newsu}{\def\ntx@suver{}\ntx@oldsufalse}% added 2023/09/16
\DeclareOptionX{defaultfeatures}{\def\ntx@defaultfeatures{#1}}
\DeclareOptionX{oldSS}{\advance\ntx@cnt 32 }
\DeclareOptionX{slashedzero}{\ntx@zeroslashtrue}
\DeclareOptionX{theoremfont}{\ntx@thrmtrue}
\DeclareOptionX{thmslshape}{\def\ntx@thmshape{s}}
\DeclareOptionX{thmlining}{\edef\ntx@thmlin{l}}
\DeclareOptionX{trueslanted}{\ntx@sltrue}
\DeclareOptionX{scosf}{\ntx@scosftrue}
\DeclareOptionX{tighter}{% 
\gdef\ntx@spc{.25em}\gdef\ntx@stretch{.125em}%
\gdef\ntx@shrink{.1em}\def\ntx@noti{F}}
\DeclareOptionX{looser}{%
\gdef\ntx@spc{.3em}\gdef\ntx@stretch{.2em}%
\gdef\ntx@shrink{.1em}\def\ntx@nolo{F}}
%\traceon
%\DeclareOptionX{sfracvcenter}{%
%\def\ntx@sfrVC{#1}}
%\DeclareOptionX{sfracvspacing}{%
%\def\ntx@sfrVS{#1}}
%\DeclareOptionX{sfracbarthick}{%
%\def\ntx@sfrTH{#1}}
%\DeclareOptionX{sfracscaling}{%
%\def\ntx@sfrSC{#1}}
\ProcessOptionsX\relax

\ifntx@supsflag%
\PackageWarningNoLine{newpxtext}{sups options no longer handled---use superiors package (v2) instead.}\fi

% otfmath beats no-math
\ifntx@otfmath\ntx@nomathfalse\fi
%\setlength{\ntxsups@raise}{\ntxsups@raised}
%\setlength{\ntxsups@scale}{\ntxsups@scaledval\p@}
%\ntxsups@scale=\ntx@scale\ntxsups@scale %
%\def\ntxsups@scalefactor{\strip@pt\ntxsups@scale}
%\def\ntxsups@scaled{s*[\ntxsups@scalefactor]}

%\ifntx@otftext \typeout{ntx@otftexttrue}\else\typeout{ntx@otftextfalse}\fi
\ifntx@newtx\let\ntx@scale=\ntxtext@scale\fi
% following lines required by newtxmath
% They must follow the definition of \ntx@scaled
\@tempdima=\ntx@scale\p@\@tempdima=\ntx@helvratio\@tempdima%
\edef\qhv@scale{\strip@pt\@tempdima}
\edef\ntx@scaled{s*[\ntx@scale]}% used in fd files
\providecommand*{\ntx@minfam}{minntx} % won't override value from newtx

%\RequirePackage[T1]{fontenc} % do we need this?
\renewcommand{\rmdefault}{\ntx@minfam} % the default until end of preamble
\renewcommand{\familydefault}{\rmdefault} % Cause the fd files to load

\def\re@DeclareTextSymbol#1#2#3{%
   \let#1=\undefined
   \DeclareTextSymbol{#1}{#2}{#3}}

\iftutex
\setstate1
 \@ifpackageloaded{fontspec}{}{%
  \ifntx@nomath
    \RequirePackage[no-math]{fontspec}
  \else
    \RequirePackage{fontspec}
  \fi%
 } 
  %\ifxetex\XeTeXtracingfonts=1\fi % causing unwanted warnings in Tectonic system
  \ifluatex  % avoid possibly uncorrected "system" fonts
    \directlua{fonts.names.set_location_precedence{
        "local", "texmf", "system" }}
  \fi
\fi

\ifntx@otftext   
\setstate1
  \def\ntx@base{TeXGyreTermesX}
  \ifntx@scosf
  	\AtBeginDocument{%
	    \xpretocmd{\scshape}
  	    {\addfontfeatures{Numbers=OldStyle}}
  	    {}{}%
	}%
  \fi
  \newcommand{\textfrac}[3][]{{%\normalfont%
  \mbox{%
    \ifthenelse{\not\equal{#1}{}}%Test for integer portion [optional #1]
      {{\lfstyle#1}\kern.06em}{}%
  \addfontfeatures{RawFeature=+numr}#2\char"2044% numerator
  \addfontfeatures{RawFeature=-numr;+dnom;+ss20}\char"2044{}#3% 
}}}
  
\else % type1
\setstate2

  \ifntx@scosf
  	\AtBeginDocument{%
	    \xpretocmd{\scshape}
  	     {\fontfamily{ntx\ntx@figurealign osf}}
  	     {}{}%
	}%
  \fi%
 % for possible use in footnote markers
%  \DeclareFontFamily{OT1}{zsups}{}%
%  \DeclareFontShape{OT1}{zsups}{m}{n}{%
%    <-> s*[\ntxsups@scalefactor] ntxsups-Regular-ot1
%}{}
%  \DeclareFontFamily{T1}{zsups}{}%
%  \DeclareFontShape{T1}{zsups}{m}{n}{%
%    <-> s*[\ntxsups@scalefactor] ntxsups-Regular-t1
%}{}
%\AtEndPreamble{%
%  \@ifundefined{T@LY1}{}% true branch
%  {%false branch---LY1 encoding has been declared
%  \DeclareFontFamily{LY1}{zsups}{}%
%  \DeclareFontShape{LY1}{zsups}{m}{n}{%
%    <-> s*[\ntxsups@scalefactor] ntxsups-Regular-ly1
%}{}
%}}
%  \DeclareFontFamily{TS1}{zsups}{}%
%  \DeclareFontShape{TS1}{zsups}{m}{n}{%
%    <-> s*[\ntxsups@scalefactor] ntxsups-Regular-ts1
%}{}
%\DeclareRobustCommand{\supstyle}{%
%  \not@math@alphabet\supstyle\relax
%  \usefont{\f@encoding}{zsups}{m}{n}}
%
%\ifdim\ntxsups@raise=\z@
%	\DeclareRobustCommand{\textsups}[1]{{\supstyle#1}}
%\else
%	\DeclareRobustCommand{\textsups}[1]{%
%	\raisebox{\ntxsups@raised}{\hbox{{\supstyle#1}}}}
%\fi
\RequirePackage{fontaxes}
    \fa@naming@exception{figures}{{superior}{proportional}}{sups}
    \fa@naming@exception{figures}{{superior}{tabular}}{sups}
   \DeclareRobustCommand{\sustyle}{%
   \not@math@alphabet\sustyle\relax
   \fontfamily{ntxsups\ntx@suver}\selectfont}
 \NewCommandCopy { \sufigures } { \sustyle }
%   \let\sufigures=\sustyle%%%%%
 
   \fa@naming@exception{figures}{{inferior}{proportional}}{inf}
   \fa@naming@exception{figures}{{inferior}{tabular}}{inf}
%    \def\infigures{\@nomath\infigures
%        \fontfigurestyle{inferior}\selectfont}
%     \let\instyle=\infigures
%    \DeclareTextFontCommand{\textinf}{\infigures}
%    \let\textinferior\textinf
   \DeclareRobustCommand{\infstyle}{%
   \not@math@alphabet\infstyle\relax
   \fontfamily{ntxinf\ntx@suver}\selectfont}
 \NewCommandCopy { \infigures } { \infstyle }
 \NewCommandCopy { \instyle } { \infstyle }
%   \let\infigures=\infstyle%%%%%
%	\let\instyle\infstyle
	
   \fa@naming@exception{figures}{{numerators}{proportional}}{numr}
   \fa@naming@exception{figures}{{numerators}{tabular}}{numr}

   \DeclareRobustCommand{\nustyle}{%
   \not@math@alphabet\nustyle\relax
   \fontfamily{ntxnumr}\selectfont}
 \NewCommandCopy { \nufigures } { \nustyle }
%   \let\nufigures=\nustyle
 
   \fa@naming@exception{figures}{{denominators}{proportional}}{dnom}
   \fa@naming@exception{figures}{{denominators}{tabular}}{dnom}
%    \def\defigures{\@nomath\defigures
%        \fontfamily{defigures}\selectfont}
%     \let\destyle=\defigures
%    \DeclareTextFontCommand{\textde}{\defigures}
%    \let\textdenominators\textde
   \DeclareRobustCommand{\destyle}{%
   \not@math@alphabet\destyle\relax
   \fontfamily{ntxdnom}\selectfont}
 \NewCommandCopy { \defigures } { \defstyle }
   %\let\defigures=\destyle

%    \fa@naming@exception{figures}{{numerators}{proportional}}{numr}
%    \fa@naming@exception{figures}{{numerators}{tabular}}{numr}
%    \def\defigures{\@nomath\nufigures
%        \fontfigurestyle{numerators}\selectfont}
%     \let\nustyle=\nufigures
%    \DeclareTextFontCommand{\textnum}{\nufigures}
%    \let\textnumerators\textnum
%  \DeclareRobustCommand{\nustyle}{%
%   \not@math@alphabet\nustyle\relax
%   \fontfamily{ntxnumr}\selectfont}
%   \let\nufigures=\nustyle

\newcommand{\textfrac}[3][]{% like \textfrac[1]{7}{8}
  \mbox{%
    \ifthenelse{\not\equal{#1}{}}%Test for integer portion [optional #1]
      {\textlf{#1}\kern.1em}{}%         
    {\nustyle#2}% numerator
    \StrRight{#2}{1}[\@digit@]%
    % look for  1, 2, 6, 7
    \ifcase\@digit@% 0
    \or%\kern.03em% 1
    \or\kern.04em% 2
    \or%\kern-.01em% 3
    \or%\kern.02em% 4
    \or%\kern.01em% 5
    \or\kern.01em% 6
    \or\kern-.06em% 7
     \or%\kern-.11em% 8
    \or\kern-.02em% 9
   \fi%
%    \kern\ntx@foresolidus{\fontencoding{TS1}\selectfont\char"2F}%
%    \kern\ntx@aftsolidus%
    {\fontencoding{TS1}\selectfont\char"2F}%
	\StrLeft{#3}{1}[\@digit@]%
    % look for 1, 4, 7
    \ifcase\@digit@% 0
    \or%\kern -.02em% 1
    \or% 2
    \or% 3
    \or\kern -.05em% 4
    \or% 5
    \or\kern-.02em% 6
    \or\kern .01em% 7
    \fi%
    {\destyle #3}%       denominator [#3]
  }%mbox
} % textfrac
\fi
\setstate0

%\let\orig@footnote=\thefootnote
%\let\orig@makefnmark=\@makefnmark
\def\bfseries@rm{b}
\def\mdseries@rm{m}

\def\useosf{\ntx@liningfalse}
\@onlypreamble\useosf
\def\useproportional{\ntx@tabularfalse}
\@onlypreamble\useproportional

\ifntx@otftext
\setstate1
  \def\ntx@dflt{}
  \ifntx@zeroslash\edef\ntx@dflt{Numbers = SlashedZero , 
  }\fi
  \if T\ntx@nospc
    \if F\ntx@noti\def\ntx@spcmag{{1,.625,1}}\def\ntx@nospc{F}\fi
    \if F\ntx@nolo\def\ntx@spcmag{{1.2,1,1}}\def\ntx@nospc{F}\fi  
  \fi
  \if F\ntx@nospc
  	\edef\ntx@dflt{\ntx@dflt WordSpace = \ntx@spcmag ,
	}
  \fi
  \def\ntx@scraw{pcap}
  \ifntx@largesc\def\ntx@scraw{smcp}\fi
  
 %\ntx@cnt will be 0..2^8-1 
  \edef\ntx@lst{}
  \ifnum\ntx@cnt>127 \edef\ntx@lst{8}\advance\ntx@cnt -128 \fi
  \ifnum\ntx@cnt>63 \edef\ntx@lst{7,\ntx@lst}\advance\ntx@cnt -64 \fi
  \ifnum\ntx@cnt>31 \edef\ntx@lst{6,\ntx@lst}\advance\ntx@cnt -32 \fi
  \ifnum\ntx@cnt>15 \edef\ntx@lst{5,\ntx@lst}\advance\ntx@cnt -16 \fi
  \ifnum\ntx@cnt>7 \edef\ntx@lst{4,\ntx@lst}\advance\ntx@cnt -8 \fi
  \ifnum\ntx@cnt>3 \edef\ntx@lst{3,\ntx@lst}\advance\ntx@cnt -4 \fi
  \ifnum\ntx@cnt>1 \edef\ntx@lst{2,\ntx@lst}\advance\ntx@cnt -2 \fi
  \ifnum\ntx@cnt>0 \edef\ntx@lst{1,\ntx@lst}\fi
  \ifthenelse{\not\equal{\ntx@lst}{}}
	{\edef\ntx@dflt{\ntx@dflt StylisticSet={\ntx@lst} , 
	}}{}
  
   \defaultfontfeatures{
     Ligatures = TeX ,
	Scale = \ntx@scale ,
     Extension = .otf ,
     SmallCapsFeatures={\ifntx@scosf Numbers = OldStyle ,
     \fi RawFeature = +\ntx@scraw } ,
     \ifluatex Renderer=Basic ,\fi
     \ntx@dflt ,
     RawFeature=-ss05 ,   
     \ntx@defaultfeatures ,
    }
 
 \else % type1
 \setstate2

  \def\ntx@spacing{%
	\fontdimen2\font=\ntx@spc
	\fontdimen3\font=\ntx@stretch
	\fontdimen4\font=\ntx@shrink}
  %\show\ntx@scaled
  %\def\oldstylenums#1{{\fontencoding{TS1}\selectfont #1}}

    \DeclareRobustCommand{\lfstyle}{%
      \not@math@alphabet\lfstyle\relax
      \fontfamily{ntxlf}\selectfont %
    }
    \DeclareRobustCommand{\tlfstyle}{%
      \not@math@alphabet\tlfstyle\relax
      \fontfamily{ntxtlf}\selectfont %
    }
    \DeclareRobustCommand{\osfstyle}{%
      \not@math@alphabet\osfstyle\relax
      \fontfamily{ntxosf}\selectfont %
    }
    \DeclareRobustCommand{\tosfstyle}{%
      \not@math@alphabet\tosfstyle\relax
      \fontfamily{ntxtosf}\selectfont %
    }    
    \ifntx@defaultsups %
    \else\fi
%    \ExplSyntaxOn
%	%\@textsuperscript is defined in latex.ltx to render text at about 70% size, at math superscript position
%	\DeclareDocumentCommand \textsuperscript {m} {
%	    \hbox_set:Nn \l_tmpa_box {{\sustyle #1}}
%		\box_scale:Nnn \l_tmpa_box { \ntxsups@scalefactor } { \ntxsups@scalefactor } 
%	    \hbox_set:Nn \l_tmpa_box
%    { \box_move_up:nn \ntxsups@raised {\box_use:N \l_tmpa_box} }
%	    \hspace*{\ntxsups@Lspaced}{\color{\ntxsups@color}\box_use:N \l_tmpa_box} \hspace*{\ntxsups@Rspaced}}%  
%	
%
%	\cs_set:Npn \@makefnmark {
%		\mbox{%
%		\footnotemarkfont\textsuperscript{\@thefnmark}}
%	  }
%	\cs_if_exist:NTF \ftntm@font % will exist only for KOMA
%	  {
%	\cs_new:Npn \footnotemarkfont {\normalfont \ftntm@font}
%	  }
%	  {
%	\cs_new:Npn \footnotemarkfont {\normalfont}
%	  }
%	    \ExplSyntaxOff
%    \patchcmd{\maketitle}{\@textsuperscript{\normalfont\@thefnmark}}{\normalfont{\textsuperscript\@thefnmark}}{}{}
%    \patchcmd{\maketitle}{\@textsuperscript{\normalfont\@thefnmark}}{\normalfont{\textsuperscript\@thefnmark}}{}{}
%%    \patchcmd{\maketitle}     
%%{\hb@xt@1.8em}{\hb@xt@1.8em}{}{} %2.18?
%    \ifntx@KOMA
%      \setkomafont{footnotereference}{\normalfont\sustyle}
%      \setkomafont{footnotelabel}{\normalfont\sustyle}
%    \fi
%  \fi
%      \ifntx@KOMA
%      	%\let\textsuperscript\sustyle
%      \else % NOT KOMA
%        \def\f@@tn@te{footnote}
%        \def\@makefnmark{%
%          \ifx\@mpfn\f@@tn@te%
%            \ifx\thefootnote\orig@footnote%
%              \hbox{\sustyle\hspace*{.05em}\@thefnmark\hspace*{.05em}}%
%            \else%
%              \orig@makefnmark%
%            \fi
%          \else%
%            \orig@makefnmark%
%          \fi}%
%        \fi
%    \fi
  \ifntx@helv\renewcommand*{\sfdefault}{qhv}\fi
  \ifntx@tt\renewcommand*{\ttdefault}{ntxtt}\fi
  \DeclareRobustCommand\thfamily % new family for theorem font
        {\not@math@alphabet\thfamily\relax
         \fontfamily\thdefault\selectfont}
\fi % type1
\setstate0

\ifntx@thrm
	%\RequirePackage{amsmath,amsthm} % in case of theoremfont
	\ifdefined\newtheoremstyle %amsthm and ntheorem, not theorem.sty
		\@ifpackageloaded{ntheorem}\relax{%
		\newtheoremstyle{plain}
		{\medskipamount}   % ABOVESPACE, was \topsep
    	{\medskipamount}   % BELOWSPACE, was \topsep
    	{\thfamily}  % BODYFONT--\thfamily is italic with upright figures and punctuation
    	{}       % INDENT (empty value is the same as 0pt)
    	{\bfseries} % HEADFONT--you may want to add \tlfstyle so the number is tab lining, regardless of text figure selection
    	{.}         % HEADPUNCT
    	{5pt plus 1pt minus 1pt} % HEADSPACE
    	{}          % CUSTOM-HEAD-SPEC\newtheorem{thm}{Theorem}[section]
    	} % end @ifpackageloaded
    \fi%
\fi%}		

\ifntx@otftext
\setstate1

%	\def\ntx@nft{\if t\ntx@thmtab Monospaced%
%	\else Proportional\fi}
   \DeclareRobustCommand{\lfstyle}{%
      \not@math@alphabet\lfstyle\relax
      \addfontfeatures{Numbers={Proportional,Lining}}%
    }
    
   \DeclareRobustCommand{\tlfstyle}{%
      \not@math@alphabet\tlfstyle\relax
      \addfontfeatures{Numbers={Monospaced,Lining}}%
    }
   \DeclareRobustCommand{\osfstyle}{%
      \not@math@alphabet\osfstyle\relax
      \addfontfeatures{Numbers={Proportional,OldStyle}}%
    }
   \DeclareRobustCommand{\tosfstyle}{%
      \not@math@alphabet\tosfstyle\relax
      \addfontfeatures{Numbers={Monospaced,OldStyle}}%
    }
   \DeclareRobustCommand{\oldstylenums}{%
      \not@math@alphabet\oldstylenums\relax
      \addfontfeatures{Numbers=OldStyle}%
    }
   \DeclareRobustCommand{\liningnums}{%
      \not@math@alphabet\liningnums\relax
      \addfontfeatures{Numbers=Lining}%
    }
   \DeclareRobustCommand{\tabularnums}{%
      \not@math@alphabet\tabularnums\relax
      \addfontfeatures{Numbers=Monospaced}%
    }
   \DeclareRobustCommand{\proportionalnums}{%
      \not@math@alphabet\proportionalnums\relax
      \addfontfeatures{Numbers=Proportional}%
    }
   \DeclareRobustCommand{\destyle}{%
      \not@math@alphabet\destyle\relax
      \addfontfeatures{RawFeature=-pnum;-onum;+dnom}%
    }
   \DeclareRobustCommand{\nustyle}{%
      \not@math@alphabet\nustyle\relax
      \addfontfeatures{RawFeature=-pnum;-onum;+numr}%
    }
   \DeclareRobustCommand{\sustyle}{%
      \not@math@alphabet\sustyle\relax
      \addfontfeatures{RawFeature=-pnum;-onum;+sups}%
    }
   \DeclareRobustCommand{\infstyle}{%
      \not@math@alphabet\infstyle\relax
      \addfontfeatures{RawFeature=-pnum;-onum;+subs}%
    }
\ifntx@oldsu
   \NewCommandCopy { \sustyle } { \nustyle }
   \NewCommandCopy { \infstyle } { \destyle }
\fi
\NewCommandCopy { \sufigures } { \sustyle }
\NewCommandCopy { \nufigures } { \nustyle }
\NewCommandCopy { \infigures } { \infstyle }
\NewCommandCopy { \defigures } { \destyle }
%   \let\sufigures\sustyle
%   \let\nufigures\nustyle
%   \let\infigures\infstyle
%   \let\defigures\destyle

   \ifntx@defaultsups %
   \else
   \fi
%      \ExplSyntaxOn
%    \RenewDocumentCommand \textsuperscript {m} {
%	    \hbox_set:Nn \l_tmpa_box {\textsu{\tlfstyle #1}}
%		\box_scale:Nnn \l_tmpa_box { \ntxsups@scalefactor } { \ntxsups@scalefactor } 
%	    \hbox_set:Nn \l_tmpa_box
%    { \box_move_up:nn \ntxsups@raised {\box_use:N \l_tmpa_box} }
%	    \hspace*{\ntxsups@Lspaced}{\color{\ntxsups@color}\box_use:N \l_tmpa_box} \hspace*{\ntxsups@Rspaced}}	
%	    
%\cs_set:Npn \@makefnmark {
%  \mbox{\footnotemarkfont\textsuperscript{\@thefnmark}}
%}
%\cs_if_exist:NTF \ftntm@font % KOMA only
%{
%  \cs_new:Npn \footnotemarkfont {\ftntm@font}
%}
%{
%  \cs_new:Npn \footnotemarkfont {\normalfont}
%}
%          \patchcmd{\maketitle}{\@textsuperscript{\normalfont\@thefnmark}}{\normalfont{\textsuperscript\@thefnmark}}{}{}
%     \patchcmd{\maketitle}{\@textsuperscript{\normalfont\@thefnmark}}{\normalfont{\textsuperscript\@thefnmark}}{}{}
%%         \patchcmd{\maketitle}     
%%{\hb@xt@1.8em}{\hb@xt@1.8em}{}{} % 2.18?
%    \ExplSyntaxOff
%    \ifntx@KOMA
%      \setkomafont{footnotereference}{\normalfont\sustyle}
%      \setkomafont{footnotelabel}{\normalfont\sustyle}
%    \fi
%   \fi% end of tutex footnote handling
   %   \else % tutex+LTX (article,book,report)
%     \patchcmd[]{\maketitle}{\normalfont\@thefnmark}{\@thefnmark}{\message{Successfully patched maketitle command}}{\message{Unable to patch maketitle command}}
%     \patchcmd[]{\maketitle}{\normalfont\@thefnmark}{\@thefnmark}{\message{Successfully patched maketitle command}}{\message{Unable to patch maketitle command}}
%    \def\@makefnmark%
%       {\hbox{\@textsuperscript{\@thefnmark}}}
%     \DeclareRobustCommand*\textsuperscript[1]{%
%       \@textsuperscript{#1}}
%     \def\@textsuperscript#1{%
%       {\normalfont{\sustyle#1}}
%   \fi
   \renewcommand*{\textcircled}[1]{% 
	\StrLen{#1}[\ntx@tmpa]\ntx@tmpcnta=\ntx@tmpa\relax
	\ifnum\ntx@tmpcnta>2\relax#1%
	\else
	  \ifnum\ntx@tmpcnta=\@ne%
\mbox{\normalfont\addfontfeatures{RawFeature=+ss08}#1}%	
	  \else % argument has length 2
	    \IfInteger{#1}{%
	      \ntx@tmpcnta=#1\relax%
	    %\ifnum\ntx@tmpcnta<10\relax--must be >=10
	    %  #1
	    %\else % >=10
	      \ifnum\ntx@tmpcnta>20\relax#1%
	      \else % between 10 and 20
	        \advance\ntx@tmpcnta 9311\relax%
	        \symbol{"\nhex{4}{\the\ntx@tmpcnta}}
	      \fi
	    %\fi %\ifnum
	    }{#1}  % \IfInteger
	  \fi %ifnum
	\fi
	}
	  %\ntx@tmpcnta=9321 % decimal value of "2469 (uni2469 is circled{10})
	  %\ntx@cnt=#1 \advance\count@\the\count1 \advance\count@ -10\relax
%	  \symbol{"\nhex{4}{\the\count@}}
%    \renewcommand*{\textcircled}[1]{\hmode@bgroup\ooalign{%
%    \hfil \raise -.08ex\hbox{{%
%    \normalfont\addfontfeatures{Numbers={Monospaced, Lining}}%
%    \scalefont{.8}{\sustyle#1}}}% end hbox
%    \hfil \crcr \symbol{"25EF}}%
%    \egroup}
\else % type1
\setstate2

    \renewcommand*{\textcircled}[1]{\hmode@bgroup\ooalign{%
    \hfil \raise .3ex\hbox{{%
    \normalfont
    {\scalefont{.6}\tlfstyle#1}}}% end hbox
    \hfil \crcr {\usefont{TS1}{ntxtlf}{m}{n}\char"4F}}%\textbigcircle}%
    \egroup}
\fi

% applies to both
\setstate0
\DeclareTextFontCommand{\textosf}{\osfstyle}
\DeclareTextFontCommand{\texttosf}{\tosfstyle}
\DeclareTextFontCommand{\texttlf}{\tlfstyle}
\DeclareTextFontCommand{\textlf}{\lfstyle}
%\show\textlf
\DeclareTextFontCommand{\textsu}{\sustyle}
%    \let\textsuperior\textsu
\NewCommandCopy { \textsup } { \textsu }
\NewCommandCopy { \textsups } { \textsu }
%    \let\textsup\textsu
%   \let\textsups\textsu
\DeclareTextFontCommand{\textnum}{\nustyle}
 \NewCommandCopy { \textnu } { \textnum }
 \NewCommandCopy { \textnumerator } { \textnum }
%   \let\textnu\textnum
%    \let\textnumerator\textnum
\DeclareTextFontCommand{\textde}{\destyle}
 \NewCommandCopy { \textdenominator } { \textde }
 %   \let\textdenominator\textde
\DeclareTextFontCommand{\textinf}{\infstyle}
 \NewCommandCopy { \textinferior } { \textinf }
 \NewCommandCopy { \textsub } { \textinf }
%\let\textinferior\textinf
%    \let\textsub\textinf
  %  \let\infigures\instyle
\AtEndPreamble{%
\ifntx@otftext
\setstate1
  \ifntx@lining
    \def\ntx@figurestyle{Lining}
  \else
    \def\ntx@figurestyle{OldStyle}
  \fi
  \ifntx@tabular
    \def\ntx@figurealign{Monospaced} 
  \else
    \def\ntx@figurealign{Proportional} 
  \fi
  %\ifntx@scosf
     \setmainfont
          [ Numbers = {\ntx@figurealign,\ntx@figurestyle},
           ] {\ntx@base}
% \else
%     \setmainfont
%          [ Numbers = {\ntx@figurealign,\ntx@figurestyle},
%          ] {\ntx@base}
% \fi
  \let\ntx@sty\ntx@figurestyle
  \if l\ntx@thmlin\def\ntx@sty{Lining}\fi
  \newcommand{\thfamily}%{\@nameuse{ntx\ntx@figurestyle}%
    {\@nameuse{\if i\ntx@thmshape itshape\else slshape\fi}\addfontfeatures{%
    Numbers={\ntx@figurealign,\ntx@sty} ,
    RawFeature=+ss05}
    } % for theorems
    \ifntx@sl\else\let\slshape=\thfamily\fi   % need xpatch? 
\else % type1
\setstate2

  \ifntx@lining
    \def\ntx@figurestyle{lf} 
  \else
    \def\ntx@figurestyle{osf} 
  \fi
  \ifntx@tabular
    \def\ntx@figurealign{t} 
  \else
    \def\ntx@figurealign{} 
  \fi
  \renewcommand{\rmdefault}{ntx\ntx@figurealign%
  \ntx@figurestyle}
  \ifthenelse{\equal{\familydefault}{\sfdefault}\OR \equal{\familydefault}{\ttdefault}}%
  {}{\renewcommand{\familydefault}{\rmdefault}}

  \def\ntx@thfigurestyle{\ntx@figurestyle}
  \ifx\ntx@figurestyle\ntx@dfltfigurestyle
    \def\ntx@thfigurestyle{tlf}
  \else
    \def\ntx@thfigurestyle{osf}
  \fi % there just two possible figure styles for the theorem font
  \newcommand*{\thdefault}{ntxth-\ntx@thfigurestyle}
  \normalfont
\fi
}
%both
\setstate0

\@ifundefined{tx@xht}{\def\tx@xht{450}}{} % lowercase letters
\@ifundefined{tx@deht}{\def\tx@deht{406}}{} % denominator figures ht
\@ifundefined{tx@nubase}{\def\tx@nubase{270}}{} % baseline of numerators
\@ifundefined{tx@debase}{\def\tx@debase{0}}{} % baseline of denoms
\@ifundefined{tx@sfrVC}{\def\tx@sfrVC{331}}{}% vertical center of sfrac
\@ifundefined{tx@sfrVS}{\def\tx@sfrVS{106}}{} % space above/below bar
\@ifundefined{tx@sfrTH}{\def\tx@sfrTH{54}}{} % bar thickness
\@ifundefined{tx@sfrSC}{\def\tx@sfrSC{.9}}{} % scale 

\@ifundefined{textsfrac}{
\newdimen\tx@sixem\tx@sixem6pt % for checking if a number refers to ex
\newdimen\tx@y \newdimen\tx@x 

% convert numerical entry that may be multiple of ex (<6) or em value
\def\tx@toex#1{\tx@x#1pt \ifdim\tx@x<\z@\tx@y-\tx@x\else\tx@y\tx@x\fi \ifdim\tx@y>\tx@sixem \tx@x\dimexpr 1pt * (\dimexpr #1pt\relax) / \dimexpr \tx@xht pt\relax\relax\fi}

\newdimen\tx@tmpdima \newdimen\tx@tmpdimb  \newdimen\tx@tmpdimc
\newdimen\tx@tmpdimd \newdimen\tx@tmpdime \newdimen\tx@tmpdimf
\newdimen\tx@dimA
\newdimen\tx@dimAA \newdimen\tx@dimB \newdimen\tx@dimBB 
\newdimen\tx@dimC % vertical center
% double cap letters for below bar, single cap for above
\tx@toex\tx@sfrVC\tx@dimC\tx@x %Vertical center of fraction
\tx@toex\tx@sfrTH\tx@tmpdimb\tx@x % bar thickness
\tx@tmpdime.5\tx@tmpdimb % half bar thickness
\tx@toex\tx@sfrVS\tx@tmpdimc\tx@x% vertical space
\tx@toex\tx@deht\tx@tmpdimd\tx@x % height of unscaled figures
\tx@tmpdimd\tx@sfrSC\tx@tmpdimd % height of scaled figures
\tx@toex\tx@debase\tx@tmpdimf\tx@x % unscaled baseline of de figures
\tx@toex\tx@nubase\tx@tmpdima\tx@x % unscaled baseline of nu figures
\tx@tmpdima\tx@sfrSC\tx@tmpdima % scaled nu baseline
\tx@tmpdimf\tx@sfrSC\tx@tmpdimf % scaled de baseline
\tx@dimA\tx@dimC
\advance\tx@dimA by \tx@tmpdime % top of bar
\tx@dimAA\tx@dimC
\advance\tx@dimAA by -\tx@tmpdime % bottom of bar
\tx@dimB\tx@dimA
\advance\tx@dimB by \tx@tmpdimc % top figure baseline
\advance\tx@dimB by -\tx@tmpdima
\tx@dimBB\tx@dimAA
\advance\tx@dimBB by -\tx@tmpdimc % 
\advance\tx@dimBB by -\tx@tmpdimd % bottom figure baseline
\advance\tx@dimBB by -\tx@tmpdimf
\newcommand*{\textsfrac}[3][]{% like \textsfrac[1]{23}{34}
\mbox{%
    \ifthenelse{\not\equal{#1}{}}%Test for integer portion [optional #1]
      {\textlf{#1}\kern.1em}{}%         
	{\hmode@bgroup%
\ooalign{%
	\setbox0=\hbox{\scalefont{\tx@sfrSC}\nustyle#2}%
	\hfil \raise\strip@pt\tx@dimB ex\box0\hfil \crcr%
	\leaders\hrule height \strip@pt\tx@dimA ex depth -\strip@pt\tx@dimAA ex\hfill \crcr%
	\setbox1=\hbox{\scalefont{\tx@sfrSC}\destyle#3}%
	\hfil\raise\strip@pt\tx@dimBB ex\box1\hfil}%
\egroup}}}
}{} % end of \@ifundefined{textsfrac}{

\ifntx@thrm
	\@ifundefined{theoremstyle}{}{%
    \theoremstyle{plain}
    \patchcmd{\th@plain}{\itshape}{\thfamily}{\message{Replaced itshape by thfamily in theorem style plain.}}{\message{Unable to replace itshape by thfamily in theorem style plain.}}
    }
\fi
%\DeclareRobustCommand{\textth}[1]{%
%    {\thfamily #1}%
%}
\DeclareTextFontCommand{\textth}{\thfamily}
\let\textthit\textth

% Define \oldstylenums, \liningnums ,\tabularnums and \proportionalnums
\ifntx@otftext
\else % type1
\setstate2

    \DeclareTextFontCommand{%
      \oldstylenums}{\fontfamily{ntx\ntx@figurealign osf}\selectfont }
    \DeclareTextFontCommand{%
      \liningnums}{\fontfamily{ntx\ntx@figurealign lf}\selectfont }
    \DeclareTextFontCommand{%
      \tabularnums}{\fontfamily{ntxt\ntx@figurestyle}\selectfont }
    \DeclareTextFontCommand{%
      \proportionalnums}{\fontfamily{ntx\ntx@figurestyle}\selectfont }
	\re@DeclareTextSymbol{\textdollar}{OT1}{36}
\fi

\endinput