Debian Codegraph @

texmf-dist/source/latex/unisc/unisc.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: unisc.dtx
4 % -------------------------------------------------------
5 % Package: unisc
6 % Version: v0.2 (29 April, 2022)
7 % Author: निरंजन
8 % Description: Unicode small caps with Xe/LuaLaTeX.
9 % Repository: https://puszcza.gnu.org.ua/projects/unisc
10 % License: GPLv3+, GFDLv1.3+
11 % -------------------------------------------------------
12 %
13 % The LaTeX Package unisc v0.2
14 % Copyright © 2022 निरंजन
15 %
16 % This program is free software: you can redistribute it
17 % and/or modify it under the terms of the GNU General Public
18 % License as published by the Free Software Foundation,
19 % either version 3 of the License, or (at your option) any
20 % later version.
21 %
22 % This program is distributed in the hope that it will be
23 % useful, but WITHOUT ANY WARRANTY; without even the implied
24 % warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
25 % PURPOSE. See the GNU General Public License for more
26 % details.
27 %
28 % You should have received a copy of the GNU General Public
29 % License along with this program. If not, see
30 % <https://www.gnu.org/licenses/>.
31 %
32 % The current maintainer of this work is निरंजन.
33 %
34 % This work consists of the files unisc.dtx
35 % unisc.ins
36 % and the derived file unisc.sty.
37 % \fi
38 % \iffalse
39 %<*internal>
40 \iffalse
41 %</internal>
42 %<*readme>
43 -------------------------------------------------------
44 Package: unisc
45 Version: v0.2 (29 April, 2022)
46 Author: निरंजन
47 Description: Unicode small caps with Xe/LuaLaTeX.
48 Repository: https://puszcza.gnu.org.ua/projects/unisc
49 License: GPLv3+, GFDLv1.3+
50 -------------------------------------------------------
51 %</readme>
52 %<*internal>
53 \fi
54 %</internal>
55 %<*driver|package>
56 \def\uniscname{unisc}
57 \def\uniscversion{0.2}
58 \def\uniscdate{2022-04-29}
59 \def\uniscdescription{%
60 Unicode small caps with Xe/LuaLaTeX.%
61 }
62 %</driver|package>
63 %<*driver>
64 \documentclass{l3doc}
65 \usepackage{xcolor}
66 \usepackage{fontawesome5}
67 \usepackage{hologo}
68 \DeclareRobustCommand\XeLaTeX{\hologo{XeLaTeX}}
69 \usepackage{unisc}
70 \usepackage{hyperref,hyperxmp}
71 \hypersetup{%
72 unicode,%
73 colorlinks,%
74 urlcolor=blue!60!black,%
75 linkcolor=red!60!black,%
76 citecolor=green!60!black,%
77 pdftitle={The unisc package},%
78 pdfauthor={निरंजन},%
79 pdfsubject={\uniscdescription},%
80 pdfcreator={निरंजन},%
81 pdfkeywords={Unicode, small caps, LaTeX},%
82 pdfcopyright={%
83 The LaTeX package unisc\textLF
84 Copyright © 2022 निरंजन\textLF
85 Permission is granted to copy, distribute and/or modify
86 this document under the terms of the GNU Free
87 Documentation License, Version 1.3 or any later version
88 published by the Free Software Foundation; with no
89 Invariant Sections, no Front-Cover Texts, and no
90 Back-Cover Texts. A copy of the license is included in
91 the section entitled “GNU Free Documentation License”.%
92 },%
93 pdflicenseurl={https://www.gnu.org/licenses/fdl-1.3.txt}%
94 }
95 \ExplSyntaxOn
96 \pdf_version_gset:n{2.0}
97 \ExplSyntaxOff
98 \usepackage{mdframed}
99 \usepackage{fontspec}
100 \newfontfamily\charissil{CharisSIL}
101 \newfontfamily\devanagari[%
102 Script=Devanagari,%
103 Scale=0.8%
104 ]%
105 {Shobhika}
106 \NewCommandCopy\oldamp\&
107 \def\&{\textit{\oldamp}}
108
109 \begin{document}
110 \DocInput{\uniscname.dtx}
111 \end{document}
112 %</driver>
113 % \fi
114 % \title{The \pkg{\uniscname} package}
115 % \author{^^A
116 % {\devanagari निरंजन}\thanks{^^A
117 % \href{mailto:[email protected]}^^A
118 % {\faIcon{envelope} \texttt{[email protected]}}^^A
119 % }^^A
120 % }
121 % \date{^^A
122 % Version \uniscversion\ --- \uniscdate\\[1ex]^^A
123 % {^^A
124 % \small
125 % \faIcon{globe}^^A
126 % \quad
127 % \url{https://puszcza.gnu.org.ua/projects/unisc}\\[0.5ex]^^A
128 % \faIcon{bug}^^A
129 % \quad
130 % \url{https://puszcza.gnu.org.ua/bugs/?group=unisc}^^A
131 % }^^A
132 % }
133 %
134 % \maketitle
135 %
136 % \begin{documentation}
137 % \begin{abstract}
138 % \LaTeX\ produces small caps with
139 % \cs{textsc}\marg{text} or \cs{scshape}. Both of these
140 % commands don't produce small caps in Unicode. If the
141 % output text is copied and pasted somewhere it shows
142 % the same characters used in the input. This package
143 % aims to internally convert all the characters provided
144 % to the commands mentioned above. It assumes that the
145 % file using this package is compiled with Lua/\XeLaTeX\
146 % \& a good Unicode font which has the small caps
147 % characters, e.g.,
148 % \href{https://ctan.org/pkg/charissil}{Charis
149 % SIL}. Please note that as there are no Unicode slots
150 % allotted to upper case small caps, both the lower case
151 % and upper case input will be converted to only one
152 % relevant Unicode character in the output, e.g.,
153 % \verb|\textsc{Hh}| will produce the same character
154 % twice unlike \verb|\oldtextsc{Hh}|.
155 % \end{abstract}
156 %
157 % \tableofcontents
158 %
159 % \vfill
160 %
161 % {^^A
162 % \setlength{\parindent}{0pt}
163 % The \LaTeX\ package \pkg{unisc}
164 %
165 % Copyright © 2022 {\devanagari निरंजन}
166 %
167 % Permission is granted to copy, distribute and/or
168 % modify this document under the terms of the GNU Free
169 % Documentation License, Version 1.3 or any later
170 % version published by the Free Software Foundation;
171 % with no Invariant Sections, no Front-Cover Texts, and
172 % no Back-Cover Texts. A copy of the license is included
173 % in the section entitled ``GNU Free Documentation
174 % License''.^^A
175 % }^^A
176 %
177 % \newpage
178 %
179 % \section{Documentation}
180 %
181 % This package provides the following two macros.
182 %
183 % \subsection{Macros}
184 %
185 % This package renews two basic \LaTeX\ commands, i.e.,
186 % \cs{scshape} \& \cs{textsc}. To keep the original
187 % definitions available for the users, I have copied the
188 % old commands \& provided two of the following macros
189 % which behave exactly like their old variants.
190 %
191 % \begin{function}{\oldscshape}
192 % \begin{syntax}
193 % \{\cs{oldscshape} \meta{text}\}
194 % \end{syntax}
195 % \end{function}
196 %
197 % \begin{function}{\oldtextsc}
198 % \begin{syntax}
199 % \cs{oldtextsc}\marg{text}
200 % \end{syntax}
201 % \end{function}
202 %
203 % \subsection{The \enquote*{x} factor}
204 %
205 % This package doesn't support the small capital shape
206 % of the character \enquote*{x} as there is no Unicode
207 % number allotted for a \enquote*{small capital x} as of
208 % now. The package simply prints the small x (for both
209 % \verb|\textsc{x}| \& \verb|\textsc{X}|) as it is of
210 % the same height of the other small capital letters
211 % along with a warning message that warns the users
212 % about this deviation.
213 %
214 % \subsection{Example}
215 %
216 % \begin{mdframed}
217 % \begin{verbatim}
218 % \documentclass{article}
219 % \usepackage{unisc}
220 % \usepackage{fontspec}
221 % \setmainfont{CharisSIL}% https://ctan.org/pkg/charissil
222
223 % \begin{document}
224 % \noindent\textbf{Fake small caps:}
225 % {\oldscshape hello world} \oldtextsc{hello world}.
226
227 % \noindent\textbf{Unicode small caps:}
228 % {\scshape hello world} \textsc{hello world}.
229 % \end{document}
230 % \end{verbatim}
231 % \end{mdframed}
232 %
233 % This produces the following:
234 %
235 % \begin{mdframed}
236 % \charissil
237 % \noindent\textbf{Fake small caps:}
238 % {\oldscshape hello world} \oldtextsc{hello world}.
239 %
240 % \noindent\textbf{Unicode small caps:}
241 % {\scshape hello world} \textsc{hello world}.
242 % \end{mdframed}
243 % \end{documentation}
244 %
245 % \newpage
246 %
247 % \begin{implementation}
248 % \section{Implementation}
249 % Provide package with its basic information.
250 % \begin{macrocode}
251 %<@@=unisc>
252 %<*package>
253 \ProvidesPackage{unisc}[2022/04/29 v0.2
254 Unicode small caps with Lua/XeLaTeX.]
255 % \end{macrocode}
256 % Load the necessary packages.
257 % \begin{macrocode}
258 \RequirePackage{pgfparser}
259 \RequirePackage{xpatch}
260 % \end{macrocode}
261 % Make copies of old commands.
262 % \begin{macrocode}
263 \NewCommandCopy\oldtextsc\textsc
264 \NewCommandCopy\oldscshape\scshape
265 % \end{macrocode}
266 % As pointed out by Florent Rougon in
267 % \href{https://topanswers.xyz/transcript?room=2050&id=138859#c138859}%
268 % {this} comment; the definition of \cs{oldtextsc} uses
269 % \cs{scshape} twice which needs to be replaced with
270 % \cs{oldscshape}. For that the following patching is done
271 % \& the old definition is retained.
272 % \begin{macrocode}
273 \xpatchcmd{\oldtextsc}{\scshape}{\oldscshape}{}{\ERROR}
274 \xpatchcmd{\oldtextsc}{\scshape}{\oldscshape}{}{\ERROR}
275 % \end{macrocode}
276 % The following code is kindly provided by Jonathan P.\
277 % Spratte on the following thread:
278 % \url{https://topanswers.xyz/tex?q=2005}. I have modified
279 % it a bit as per my needs and my indentation style.
280 % \begin{macrocode}
281 \protected\long\def\unisc@output#1{%
282 \xdef\unisc@outputcontainer{%
283 \unexpanded\expandafter{%
284 \unisc@outputcontainer\unexpanded{#1}%
285 }%
286 }%
287 }
288 \protected\long\def\unisc@outputexpanded#1{%
289 \xdef\unisc@outputcontainer{%
290 \unexpanded\expandafter{\unisc@outputcontainer#1%
291 }%
292 }%
293 }
294 \providecommand\@gobbletwo[2]{}
295 \pgfparserdefunknown{scparser}{initial}{%
296 \let\unisc@initiated\@empty
297 \pgfparserswitch{initiated}%
298 \pgfparserreinsert
299 }
300 \pgfparserset{scparser/silent=true}
301 \pgfparserdefunknown{scparser}{all}{%
302 \expandafter\unisc@output\expandafter{\pgfparserletter}%
303 }
304 \newcommand*\unisc@bgroup{\expandafter{\iffalse}\fi}
305 \newcommand*\unisc@egroup{\iffalse{\fi}}
306 \pgfparserdef{scparser}{all}\begingroup
307 {\begingroup\unisc@outputexpanded\begingroup}
308 \pgfparserdef{scparser}{all}\endgroup
309 {\unisc@checkend\endgroup}
310 \pgfparserdef{scparser}{all}{\meaning\bgroup}{%
311 \unisc@bgroup\unisc@outputexpanded\unisc@bgroup
312 }
313 \pgfparserdef{scparser}{all}{\meaning\egroup}
314 {\unisc@checkend\unisc@egroup}
315 \newcommand\unisc@savedefinition[1]
316 {\unexpanded{\def#1}{\unexpanded\expandafter{#1}}}
317 \protected\def\unisc@checkend#1{%
318 \expanded{%
319 \unexpanded{#1}%
320 \unexpanded{\ifdefined\unisc@initiated}%
321 \unisc@savedefinition\pgfparserstate
322 \unexpanded{\unisc@outputexpanded#1}%
323 \unexpanded{\else}%
324 \unexpanded{\pgfparserswitch{final}}%
325 \unisc@savedefinition\pgfparser@current
326 \unisc@savedefinition\pgfparser@usersname
327 \unexpanded{\fi}%
328 }%
329 }
330 % \end{macrocode}
331 % Following is the code for the replacements of the
332 % regular characters with the Unicode ones.
333 % \begin{macrocode}
334 %% LATIN LETTER SMALL CAPITAL A
335 \pgfparserdef{scparser}{initiated}a%
336 {\unisc@outputexpanded{\symbol{"1D00}}}
337 \pgfparserdef{scparser}{initiated}A%
338 {\unisc@outputexpanded{\symbol{"1D00}}}
339 %% LATIN LETTER SMALL CAPITAL B
340 \pgfparserdef{scparser}{initiated}b%
341 {\unisc@outputexpanded{\symbol{"0299}}}
342 \pgfparserdef{scparser}{initiated}B%
343 {\unisc@outputexpanded{\symbol{"0299}}}
344 %% LATIN LETTER SMALL CAPITAL C
345 \pgfparserdef{scparser}{initiated}c%
346 {\unisc@outputexpanded{\symbol{"1D04}}}
347 \pgfparserdef{scparser}{initiated}C%
348 {\unisc@outputexpanded{\symbol{"1D04}}}
349 %% LATIN LETTER SMALL CAPITAL D
350 \pgfparserdef{scparser}{initiated}d%
351 {\unisc@outputexpanded{\symbol{"1D05}}}
352 \pgfparserdef{scparser}{initiated}D%
353 {\unisc@outputexpanded{\symbol{"1D05}}}
354 %% LATIN LETTER SMALL CAPITAL E
355 \pgfparserdef{scparser}{initiated}e%
356 {\unisc@outputexpanded{\symbol{"1D07}}}
357 \pgfparserdef{scparser}{initiated}E%
358 {\unisc@outputexpanded{\symbol{"1D07}}}
359 %% LATIN LETTER SMALL CAPITAL F
360 \pgfparserdef{scparser}{initiated}f%
361 {\unisc@outputexpanded{\symbol{"A730}}}
362 \pgfparserdef{scparser}{initiated}F%
363 {\unisc@outputexpanded{\symbol{"A730}}}
364 %% LATIN LETTER SMALL CAPITAL G
365 \pgfparserdef{scparser}{initiated}g%
366 {\unisc@outputexpanded{\symbol{"0262}}}
367 \pgfparserdef{scparser}{initiated}G%
368 {\unisc@outputexpanded{\symbol{"0262}}}
369 %% LATIN LETTER SMALL CAPITAL H
370 \pgfparserdef{scparser}{initiated}h%
371 {\unisc@outputexpanded{\symbol{"029C}}}
372 \pgfparserdef{scparser}{initiated}H%
373 {\unisc@outputexpanded{\symbol{"029C}}}
374 %% LATIN LETTER SMALL CAPITAL I
375 \pgfparserdef{scparser}{initiated}i%
376 {\unisc@outputexpanded{\symbol{"026A}}}
377 \pgfparserdef{scparser}{initiated}I%
378 {\unisc@outputexpanded{\symbol{"026A}}}
379 %% LATIN LETTER SMALL CAPITAL J
380 \pgfparserdef{scparser}{initiated}j%
381 {\unisc@outputexpanded{\symbol{"1D0A}}}
382 \pgfparserdef{scparser}{initiated}J%
383 {\unisc@outputexpanded{\symbol{"1D0A}}}
384 %% LATIN LETTER SMALL CAPITAL K
385 \pgfparserdef{scparser}{initiated}k%
386 {\unisc@outputexpanded{\symbol{"1D0B}}}
387 \pgfparserdef{scparser}{initiated}K%
388 {\unisc@outputexpanded{\symbol{"1D0B}}}
389 %% LATIN LETTER SMALL CAPITAL L
390 \pgfparserdef{scparser}{initiated}l%
391 {\unisc@outputexpanded{\symbol{"029F}}}
392 \pgfparserdef{scparser}{initiated}L%
393 {\unisc@outputexpanded{\symbol{"029F}}}
394 %% LATIN LETTER SMALL CAPITAL M
395 \pgfparserdef{scparser}{initiated}m%
396 {\unisc@outputexpanded{\symbol{"1D0D}}}
397 \pgfparserdef{scparser}{initiated}M%
398 {\unisc@outputexpanded{\symbol{"1D0D}}}
399 %% LATIN LETTER SMALL CAPITAL N
400 \pgfparserdef{scparser}{initiated}n%
401 {\unisc@outputexpanded{\symbol{"0274}}}
402 \pgfparserdef{scparser}{initiated}N%
403 {\unisc@outputexpanded{\symbol{"0274}}}
404 %% LATIN LETTER SMALL CAPITAL O
405 \pgfparserdef{scparser}{initiated}o%
406 {\unisc@outputexpanded{\symbol{"1D0F}}}
407 \pgfparserdef{scparser}{initiated}O%
408 {\unisc@outputexpanded{\symbol{"1D0F}}}
409 %% LATIN LETTER SMALL CAPITAL P
410 \pgfparserdef{scparser}{initiated}p%
411 {\unisc@outputexpanded{\symbol{"1D18}}}
412 \pgfparserdef{scparser}{initiated}P%
413 {\unisc@outputexpanded{\symbol{"1D18}}}
414 %% LATIN LETTER SMALL CAPITAL Q
415 \pgfparserdef{scparser}{initiated}q%
416 {\unisc@outputexpanded{\symbol{"A7AF}}}
417 \pgfparserdef{scparser}{initiated}Q%
418 {\unisc@outputexpanded{\symbol{"A7AF}}}
419 %% LATIN LETTER SMALL CAPITAL R
420 \pgfparserdef{scparser}{initiated}r%
421 {\unisc@outputexpanded{\symbol{"0280}}}
422 \pgfparserdef{scparser}{initiated}R%
423 {\unisc@outputexpanded{\symbol{"0280}}}
424 %% LATIN LETTER SMALL CAPITAL S
425 \pgfparserdef{scparser}{initiated}s%
426 {\unisc@outputexpanded{\symbol{"A731}}}
427 \pgfparserdef{scparser}{initiated}S%
428 {\unisc@outputexpanded{\symbol{"A731}}}
429 %% LATIN LETTER SMALL CAPITAL T
430 \pgfparserdef{scparser}{initiated}t%
431 {\unisc@outputexpanded{\symbol{"1D1B}}}
432 \pgfparserdef{scparser}{initiated}T%
433 {\unisc@outputexpanded{\symbol{"1D1B}}}
434 %% LATIN LETTER SMALL CAPITAL U
435 \pgfparserdef{scparser}{initiated}u%
436 {\unisc@outputexpanded{\symbol{"1D1C}}}
437 \pgfparserdef{scparser}{initiated}U%
438 {\unisc@outputexpanded{\symbol{"1D1C}}}
439 %% LATIN LETTER SMALL CAPITAL V
440 \pgfparserdef{scparser}{initiated}v%
441 {\unisc@outputexpanded{\symbol{"1D20}}}
442 \pgfparserdef{scparser}{initiated}V%
443 {\unisc@outputexpanded{\symbol{"1D20}}}
444 %% LATIN LETTER SMALL CAPITAL W
445 \pgfparserdef{scparser}{initiated}w%
446 {\unisc@outputexpanded{\symbol{"1D21}}}
447 \pgfparserdef{scparser}{initiated}W%
448 {\unisc@outputexpanded{\symbol{"1D21}}}
449 %% LATIN LETTER X
450 \pgfparserdef{scparser}{initiated}x{%
451 \unisc@outputexpanded{\symbol{"0078}}%
452 \PackageWarning{unisc}{%
453 You have used the unsupported character `x' with the\MessageBreak
454 \string\textsc\space or \string\scshape\space command%
455 }%
456 }
457 \pgfparserdef{scparser}{initiated}X{%
458 \unisc@outputexpanded{\symbol{"0078}}%
459 \PackageWarning{unisc}{%
460 You have used the unsupported character `X' in the\MessageBreak
461 argument of \string\textsc
462 }%
463 }
464 %% No Unicode number for small capital x as of now.
465 %% \textsc{X} == \textsc{x} for size-consistency.
466 %% LATIN LETTER SMALL CAPITAL Y
467 \pgfparserdef{scparser}{initiated}y%
468 {\unisc@outputexpanded{\symbol{"028F}}}
469 \pgfparserdef{scparser}{initiated}Y%
470 {\unisc@outputexpanded{\symbol{"028F}}}
471 %% LATIN LETTER SMALL CAPITAL Z
472 \pgfparserdef{scparser}{initiated}z%
473 {\unisc@outputexpanded{\symbol{"1D22}}}
474 \pgfparserdef{scparser}{initiated}Z%
475 {\unisc@outputexpanded{\symbol{"1D22}}}
476 %% BLANK SPACE
477 \pgfparserdef{scparser}{initiated}{blank space}%
478 {\unisc@outputexpanded{ }}
479 %% END OF INPUT CHARACTERS
480 \pgfparserdeffinal{scparser}%
481 {\expanded{\unisc@outputcontainer}}
482 % \end{macrocode}
483 % Renew the definitions of \cs{textsc} \& \cs{scshape}
484 % commands.
485 % \begin{macrocode}
486 \AddToHook{begindocument/end}{%
487 \RenewDocumentCommand\scshape{ }{%
488 \ifdefined\unisc@initiated
489 \PackageError{unisc}{Nested use not allowed}{%
490 \string\unisc@initiated\space already defined,
491 this shouldn't happen. Aborting.%
492 }%
493 \expandafter\@gobbletwo
494 \else
495 \global\let\unisc@outputcontainer\@empty
496 \fi
497 \pgfparserparse{scparser}%
498 }
499 \RenewDocumentCommand\textsc{ m }{%
500 \begingroup\scshape #1\endgroup
501 }%
502 }
503 % \end{macrocode}
504 % \begin{macrocode}
505 %</package>
506 % \end{macrocode}
507 % \end{implementation}
508 % \newpage
509 % \addcontentsline{toc}{section}{^^A
510 % GNU Free Documentation License^^A
511 % }
512 % \include{gfdl-tex.tex}
513 % \Finale