summaryrefslogtreecommitdiff
path: root/macros/unicodetex/latex/unisc/unisc.dtx
blob: bb1e7d379ed77d2f9b6ba1031e73d520c8599c7c (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
% \iffalse meta-comment
%
% File: unisc.dtx
% -------------------------------------------------------
% Package:     unisc
% Version:     v0.2 (29 April, 2022)
% Author:      निरंजन
% Description: Unicode small caps with Xe/LuaLaTeX.
% Repository:  https://puszcza.gnu.org.ua/projects/unisc
% License:     GPLv3+, GFDLv1.3+
% -------------------------------------------------------
%
% The LaTeX Package unisc v0.2
% Copyright © 2022 निरंजन
%
% This program is free software: you can redistribute it
% and/or modify it under the terms of the GNU General Public
% License as published by the Free Software Foundation,
% either version 3 of the License, or (at your option) any
% later version.
%
% This program is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU General Public License for more
% details.
%
% You should have received a copy of the GNU General Public
% License along with this program. If not, see
% <https://www.gnu.org/licenses/>.
%
% The current maintainer of this work is निरंजन.
%
% This work consists of the files unisc.dtx
%                                 unisc.ins
% and the derived file            unisc.sty.
% \fi
% \iffalse
%<*internal>
\iffalse
%</internal>
%<*readme>
-------------------------------------------------------
Package:     unisc
Version:     v0.2 (29 April, 2022)
Author:      निरंजन
Description: Unicode small caps with Xe/LuaLaTeX.
Repository:  https://puszcza.gnu.org.ua/projects/unisc
License:     GPLv3+, GFDLv1.3+
-------------------------------------------------------
%</readme>
%<*internal>
\fi
%</internal>
%<*driver|package>
\def\uniscname{unisc}
\def\uniscversion{0.2}
\def\uniscdate{2022-04-29}
\def\uniscdescription{%
  Unicode small caps with Xe/LuaLaTeX.%
}
%</driver|package>
%<*driver>
\documentclass{l3doc}
\usepackage{xcolor}
\usepackage{fontawesome5}
\usepackage{hologo}
\DeclareRobustCommand\XeLaTeX{\hologo{XeLaTeX}}
\usepackage{unisc}
\usepackage{hyperref,hyperxmp}
\hypersetup{%
  unicode,%
  colorlinks,%
  urlcolor=blue!60!black,%
  linkcolor=red!60!black,%
  citecolor=green!60!black,%
  pdftitle={The unisc package},%
  pdfauthor={निरंजन},%
  pdfsubject={\uniscdescription},%
  pdfcreator={निरंजन},%
  pdfkeywords={Unicode, small caps, LaTeX},%
  pdfcopyright={%
    The LaTeX package unisc\textLF
    Copyright © 2022 निरंजन\textLF
    Permission is granted to copy, distribute and/or modify
    this document under the terms of the GNU Free
    Documentation License, Version 1.3 or any later version
    published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no
    Back-Cover Texts. A copy of the license is included in
    the section entitled “GNU Free Documentation License”.%
  },%
  pdflicenseurl={https://www.gnu.org/licenses/fdl-1.3.txt}%
}
\ExplSyntaxOn
\pdf_version_gset:n{2.0}
\ExplSyntaxOff
\usepackage{mdframed}
\usepackage{fontspec}
\newfontfamily\charissil{CharisSIL}
\newfontfamily\devanagari[%
  Script=Devanagari,%
  Scale=0.8%
]%
{Shobhika}
\NewCommandCopy\oldamp\&
\def\&{\textit{\oldamp}}

\begin{document}
    \DocInput{\uniscname.dtx}
\end{document}
%</driver>
% \fi
% \title{The \pkg{\uniscname} package}
% \author{^^A
%   {\devanagari निरंजन}\thanks{^^A
%     \href{mailto:hi.niranjan@pm.me}^^A
%     {\faIcon{envelope} \texttt{hi.niranjan@pm.me}}^^A
%   }^^A
% }
%     \date{^^A
%   Version \uniscversion\ --- \uniscdate\\[1ex]^^A
%   {^^A
%     \small
%     \faIcon{globe}^^A
%     \quad
%     \url{https://puszcza.gnu.org.ua/projects/unisc}\\[0.5ex]^^A
%     \faIcon{bug}^^A
%     \quad
%     \url{https://puszcza.gnu.org.ua/bugs/?group=unisc}^^A
%   }^^A
% }
%
% \maketitle
% 
% \begin{documentation}
%   \begin{abstract}
%     \LaTeX\ produces small caps with
%     \cs{textsc}\marg{text} or \cs{scshape}. Both of these
%     commands don't produce small caps in Unicode. If the
%     output text is copied and pasted somewhere it shows
%     the same characters used in the input. This package
%     aims to internally convert all the characters provided
%     to the commands mentioned above. It assumes that the
%     file using this package is compiled with Lua/\XeLaTeX\
%     \& a good Unicode font which has the small caps
%     characters, e.g.,
%     \href{https://ctan.org/pkg/charissil}{Charis
%     SIL}. Please note that as there are no Unicode slots
%     allotted to upper case small caps, both the lower case
%     and upper case input will be converted to only one
%     relevant Unicode character in the output, e.g.,
%     \verb|\textsc{Hh}| will produce the same character
%     twice unlike \verb|\oldtextsc{Hh}|.
%   \end{abstract}
%   
%   \tableofcontents
%   
%   \vfill
%   
%   {^^A
%     \setlength{\parindent}{0pt}
%     The \LaTeX\ package \pkg{unisc}
%     
%     Copyright © 2022 {\devanagari निरंजन}
%   
%     Permission is granted to copy, distribute and/or
%     modify this document under the terms of the GNU Free
%     Documentation License, Version 1.3 or any later
%     version published by the Free Software Foundation;
%     with no Invariant Sections, no Front-Cover Texts, and
%     no Back-Cover Texts. A copy of the license is included
%     in the section entitled ``GNU Free Documentation
%     License''.^^A
%   }^^A
%     
%     \newpage
%     
%     \section{Documentation}
%     
%     This package provides the following two macros.
%
%     \subsection{Macros}
%     
%     This package renews two basic \LaTeX\ commands, i.e.,
%     \cs{scshape} \& \cs{textsc}. To keep the original
%     definitions available for the users, I have copied the
%     old commands \& provided two of the following macros
%     which behave exactly like their old variants.
%     
%     \begin{function}{\oldscshape}
%       \begin{syntax}
%         \{\cs{oldscshape} \meta{text}\}
%       \end{syntax}
%     \end{function}
%
%     \begin{function}{\oldtextsc}
%       \begin{syntax}
%         \cs{oldtextsc}\marg{text}
%       \end{syntax}
%     \end{function}
%
%     \subsection{The \enquote*{x} factor}
%
%     This package doesn't support the small capital shape
%     of the character \enquote*{x} as there is no Unicode
%     number allotted for a \enquote*{small capital x} as of
%     now. The package simply prints the small x (for both
%     \verb|\textsc{x}| \& \verb|\textsc{X}|) as it is of
%     the same height of the other small capital letters
%     along with a warning message that warns the users
%     about this deviation.
%     
%     \subsection{Example}
%     
%     \begin{mdframed}
% \begin{verbatim}
% \documentclass{article}
% \usepackage{unisc}
% \usepackage{fontspec}
% \setmainfont{CharisSIL}% https://ctan.org/pkg/charissil

% \begin{document}
% \noindent\textbf{Fake small caps:}
% {\oldscshape hello world} \oldtextsc{hello world}.

% \noindent\textbf{Unicode small caps:}
% {\scshape hello world} \textsc{hello world}.
% \end{document}
% \end{verbatim}
%     \end{mdframed}
%     
%     This produces the following:
%     
%     \begin{mdframed}
%       \charissil
%       \noindent\textbf{Fake small caps:}
%       {\oldscshape hello world} \oldtextsc{hello world}.
%       
%       \noindent\textbf{Unicode small caps:}
%       {\scshape hello world} \textsc{hello world}.
%     \end{mdframed}
%   \end{documentation}
%   
%   \newpage
%   
%   \begin{implementation}
%     \section{Implementation}
%     Provide package with its basic information.
%    \begin{macrocode}
%<@@=unisc>
%<*package>
\ProvidesPackage{unisc}[2022/04/29 v0.2
Unicode small caps with Lua/XeLaTeX.]
%    \end{macrocode}
% Load the necessary packages.
%    \begin{macrocode}
\RequirePackage{pgfparser}
\RequirePackage{xpatch}
%    \end{macrocode}
% Make copies of old commands.
%    \begin{macrocode}
\NewCommandCopy\oldtextsc\textsc
\NewCommandCopy\oldscshape\scshape
%    \end{macrocode}
% As pointed out by Florent Rougon in
% \href{https://topanswers.xyz/transcript?room=2050&id=138859#c138859}%
% {this} comment; the definition of \cs{oldtextsc} uses
% \cs{scshape} twice which needs to be replaced with
% \cs{oldscshape}. For that the following patching is done
% \& the old definition is retained.
%    \begin{macrocode}
\xpatchcmd{\oldtextsc}{\scshape}{\oldscshape}{}{\ERROR}
\xpatchcmd{\oldtextsc}{\scshape}{\oldscshape}{}{\ERROR}
%    \end{macrocode}
% The following code is kindly provided by Jonathan P.\
% Spratte on the following thread:
% \url{https://topanswers.xyz/tex?q=2005}. I have modified
% it a bit as per my needs and my indentation style.
%    \begin{macrocode}
\protected\long\def\unisc@output#1{%
  \xdef\unisc@outputcontainer{%
    \unexpanded\expandafter{%
      \unisc@outputcontainer\unexpanded{#1}%
    }%
  }%
}
\protected\long\def\unisc@outputexpanded#1{%
  \xdef\unisc@outputcontainer{%
    \unexpanded\expandafter{\unisc@outputcontainer#1%
    }%
  }%
}
\providecommand\@gobbletwo[2]{}
\pgfparserdefunknown{scparser}{initial}{%
  \let\unisc@initiated\@empty
  \pgfparserswitch{initiated}%
  \pgfparserreinsert
}
\pgfparserset{scparser/silent=true}
\pgfparserdefunknown{scparser}{all}{%
  \expandafter\unisc@output\expandafter{\pgfparserletter}%
}
\newcommand*\unisc@bgroup{\expandafter{\iffalse}\fi}
\newcommand*\unisc@egroup{\iffalse{\fi}}
\pgfparserdef{scparser}{all}\begingroup
  {\begingroup\unisc@outputexpanded\begingroup}
\pgfparserdef{scparser}{all}\endgroup
  {\unisc@checkend\endgroup}
\pgfparserdef{scparser}{all}{\meaning\bgroup}{%
  \unisc@bgroup\unisc@outputexpanded\unisc@bgroup
}
\pgfparserdef{scparser}{all}{\meaning\egroup}
  {\unisc@checkend\unisc@egroup}
\newcommand\unisc@savedefinition[1]
  {\unexpanded{\def#1}{\unexpanded\expandafter{#1}}}
\protected\def\unisc@checkend#1{%
  \expanded{%
    \unexpanded{#1}%
    \unexpanded{\ifdefined\unisc@initiated}%
    \unisc@savedefinition\pgfparserstate
    \unexpanded{\unisc@outputexpanded#1}%
    \unexpanded{\else}%
    \unexpanded{\pgfparserswitch{final}}%
    \unisc@savedefinition\pgfparser@current
    \unisc@savedefinition\pgfparser@usersname
    \unexpanded{\fi}%
  }%
}
%    \end{macrocode}
% Following is the code for the replacements of the
% regular characters with the Unicode ones.
%    \begin{macrocode}
%% LATIN LETTER SMALL CAPITAL A
\pgfparserdef{scparser}{initiated}a%
  {\unisc@outputexpanded{\symbol{"1D00}}}
\pgfparserdef{scparser}{initiated}A%
  {\unisc@outputexpanded{\symbol{"1D00}}}
%% LATIN LETTER SMALL CAPITAL B
\pgfparserdef{scparser}{initiated}b%
  {\unisc@outputexpanded{\symbol{"0299}}}
\pgfparserdef{scparser}{initiated}B%
  {\unisc@outputexpanded{\symbol{"0299}}}
%% LATIN LETTER SMALL CAPITAL C
\pgfparserdef{scparser}{initiated}c%
  {\unisc@outputexpanded{\symbol{"1D04}}}
\pgfparserdef{scparser}{initiated}C%
  {\unisc@outputexpanded{\symbol{"1D04}}}
%% LATIN LETTER SMALL CAPITAL D
\pgfparserdef{scparser}{initiated}d%
  {\unisc@outputexpanded{\symbol{"1D05}}}
\pgfparserdef{scparser}{initiated}D%
  {\unisc@outputexpanded{\symbol{"1D05}}}
%% LATIN LETTER SMALL CAPITAL E
\pgfparserdef{scparser}{initiated}e%
  {\unisc@outputexpanded{\symbol{"1D07}}}
\pgfparserdef{scparser}{initiated}E%
  {\unisc@outputexpanded{\symbol{"1D07}}}
%% LATIN LETTER SMALL CAPITAL F
\pgfparserdef{scparser}{initiated}f%
  {\unisc@outputexpanded{\symbol{"A730}}}
\pgfparserdef{scparser}{initiated}F%
  {\unisc@outputexpanded{\symbol{"A730}}}
%% LATIN LETTER SMALL CAPITAL G
\pgfparserdef{scparser}{initiated}g%
  {\unisc@outputexpanded{\symbol{"0262}}}
\pgfparserdef{scparser}{initiated}G%
  {\unisc@outputexpanded{\symbol{"0262}}}
%% LATIN LETTER SMALL CAPITAL H
\pgfparserdef{scparser}{initiated}h%
  {\unisc@outputexpanded{\symbol{"029C}}}
\pgfparserdef{scparser}{initiated}H%
  {\unisc@outputexpanded{\symbol{"029C}}}
%% LATIN LETTER SMALL CAPITAL I
\pgfparserdef{scparser}{initiated}i%
  {\unisc@outputexpanded{\symbol{"026A}}}
\pgfparserdef{scparser}{initiated}I%
  {\unisc@outputexpanded{\symbol{"026A}}}
%% LATIN LETTER SMALL CAPITAL J
\pgfparserdef{scparser}{initiated}j%
  {\unisc@outputexpanded{\symbol{"1D0A}}}
\pgfparserdef{scparser}{initiated}J%
  {\unisc@outputexpanded{\symbol{"1D0A}}}
%% LATIN LETTER SMALL CAPITAL K
\pgfparserdef{scparser}{initiated}k%
  {\unisc@outputexpanded{\symbol{"1D0B}}}
\pgfparserdef{scparser}{initiated}K%
  {\unisc@outputexpanded{\symbol{"1D0B}}}
%% LATIN LETTER SMALL CAPITAL L
\pgfparserdef{scparser}{initiated}l%
  {\unisc@outputexpanded{\symbol{"029F}}}
\pgfparserdef{scparser}{initiated}L%
  {\unisc@outputexpanded{\symbol{"029F}}}
%% LATIN LETTER SMALL CAPITAL M
\pgfparserdef{scparser}{initiated}m%
  {\unisc@outputexpanded{\symbol{"1D0D}}}
\pgfparserdef{scparser}{initiated}M%
  {\unisc@outputexpanded{\symbol{"1D0D}}}
%% LATIN LETTER SMALL CAPITAL N
\pgfparserdef{scparser}{initiated}n%
  {\unisc@outputexpanded{\symbol{"0274}}}
\pgfparserdef{scparser}{initiated}N%
  {\unisc@outputexpanded{\symbol{"0274}}}
%% LATIN LETTER SMALL CAPITAL O
\pgfparserdef{scparser}{initiated}o%
  {\unisc@outputexpanded{\symbol{"1D0F}}}
\pgfparserdef{scparser}{initiated}O%
  {\unisc@outputexpanded{\symbol{"1D0F}}}
%% LATIN LETTER SMALL CAPITAL P
\pgfparserdef{scparser}{initiated}p%
  {\unisc@outputexpanded{\symbol{"1D18}}}
\pgfparserdef{scparser}{initiated}P%
  {\unisc@outputexpanded{\symbol{"1D18}}}
%% LATIN LETTER SMALL CAPITAL Q
\pgfparserdef{scparser}{initiated}q%
  {\unisc@outputexpanded{\symbol{"A7AF}}}
\pgfparserdef{scparser}{initiated}Q%
  {\unisc@outputexpanded{\symbol{"A7AF}}}
%% LATIN LETTER SMALL CAPITAL R
\pgfparserdef{scparser}{initiated}r%
  {\unisc@outputexpanded{\symbol{"0280}}}
\pgfparserdef{scparser}{initiated}R%
  {\unisc@outputexpanded{\symbol{"0280}}}
%% LATIN LETTER SMALL CAPITAL S
\pgfparserdef{scparser}{initiated}s%
  {\unisc@outputexpanded{\symbol{"A731}}}
\pgfparserdef{scparser}{initiated}S%
  {\unisc@outputexpanded{\symbol{"A731}}}
%% LATIN LETTER SMALL CAPITAL T
\pgfparserdef{scparser}{initiated}t%
  {\unisc@outputexpanded{\symbol{"1D1B}}}
\pgfparserdef{scparser}{initiated}T%
  {\unisc@outputexpanded{\symbol{"1D1B}}}
%% LATIN LETTER SMALL CAPITAL U
\pgfparserdef{scparser}{initiated}u%
  {\unisc@outputexpanded{\symbol{"1D1C}}}
\pgfparserdef{scparser}{initiated}U%
  {\unisc@outputexpanded{\symbol{"1D1C}}}
%% LATIN LETTER SMALL CAPITAL V
\pgfparserdef{scparser}{initiated}v%
  {\unisc@outputexpanded{\symbol{"1D20}}}
\pgfparserdef{scparser}{initiated}V%
  {\unisc@outputexpanded{\symbol{"1D20}}}
%% LATIN LETTER SMALL CAPITAL W
\pgfparserdef{scparser}{initiated}w%
  {\unisc@outputexpanded{\symbol{"1D21}}}
\pgfparserdef{scparser}{initiated}W%
  {\unisc@outputexpanded{\symbol{"1D21}}}
%% LATIN LETTER X
\pgfparserdef{scparser}{initiated}x{%
  \unisc@outputexpanded{\symbol{"0078}}%
  \PackageWarning{unisc}{%
    You have used the unsupported character `x' with the\MessageBreak
    \string\textsc\space or \string\scshape\space command%
  }%
}
\pgfparserdef{scparser}{initiated}X{%
  \unisc@outputexpanded{\symbol{"0078}}%
  \PackageWarning{unisc}{%
    You have used the unsupported character `X' in the\MessageBreak
    argument of \string\textsc
  }%
}
%% No Unicode number for small capital x as of now.
%% \textsc{X} == \textsc{x} for size-consistency.
%% LATIN LETTER SMALL CAPITAL Y
\pgfparserdef{scparser}{initiated}y%
  {\unisc@outputexpanded{\symbol{"028F}}}
\pgfparserdef{scparser}{initiated}Y%
  {\unisc@outputexpanded{\symbol{"028F}}}
%% LATIN LETTER SMALL CAPITAL Z
\pgfparserdef{scparser}{initiated}z%
  {\unisc@outputexpanded{\symbol{"1D22}}}
\pgfparserdef{scparser}{initiated}Z%
  {\unisc@outputexpanded{\symbol{"1D22}}}
%% BLANK SPACE
\pgfparserdef{scparser}{initiated}{blank space}%
  {\unisc@outputexpanded{ }}
%% END OF INPUT CHARACTERS
\pgfparserdeffinal{scparser}%
  {\expanded{\unisc@outputcontainer}}
%    \end{macrocode}
% Renew the definitions of \cs{textsc} \& \cs{scshape}
% commands.
%    \begin{macrocode}
\AddToHook{begindocument/end}{%
  \RenewDocumentCommand\scshape{  }{%
    \ifdefined\unisc@initiated
      \PackageError{unisc}{Nested use not allowed}{%
        \string\unisc@initiated\space already defined,
        this shouldn't happen. Aborting.%
      }%
      \expandafter\@gobbletwo
    \else
      \global\let\unisc@outputcontainer\@empty
    \fi
    \pgfparserparse{scparser}%
  }
  \RenewDocumentCommand\textsc{ m }{%
    \begingroup\scshape #1\endgroup
  }%
}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \end{implementation}
% \newpage
% \addcontentsline{toc}{section}{^^A
%   GNU Free Documentation License^^A
% }
% \include{gfdl-tex.tex}
% \Finale