Debian Codegraph @

pua2ot/doc/pua2ot.tex

raw
1 \documentclass[12pt,letterpaper,openany]{article}
2 \title{pua2ot: A Utility for Junicode}
3 \author{Peter S. Baker}
4 \date{\today}
5
6 \usepackage[MainFeatures={Language=English,StylisticSet=9}]{junicodevf}
7 \setsansfont{Noto Sans}[Scale=MatchLowercase,Numbers=Lowercase]
8
9 \usepackage[hypertexnames=true, plainpages=false, pdfpagelabels]{hyperref}
10 \hypersetup{pdftex, colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue,%
11 urlcolor=blue, pdftitle=, pdfauthor=, pdfsubject=, pdfkeywords=,}
12
13 \usepackage{graphicx}
14 \usepackage[table,dvipsnames]{xcolor}
15
16 \definecolor{GGOrange}{RGB}{240,74,6}
17 \definecolor{BrickRed}{RGB}{146,18,6}
18 \definecolor{myLightPurple}{RGB}{138,43,226}
19 \newcommand\textSourceText[1]{{\color{GGOrange}\textsf{#1}}}
20 \newcommand\textex[1]{\textrm{\textbf{\color{BrickRed}#1}}}
21 \newcommand{\unic}[1]{{\jSmCond\addfontfeature{Numbers={Uppercase,Monospaced}}#1}}
22 \newcommand{\pto}{\textsf{\color{myLightPurple}pua2ot}}
23
24 \begin{document}
25
26 \maketitle
27
28 \section{The scripts}
29
30 Modern best practice, when typesetting documents or creating web pages, is to
31 avoid the use of characters from the Unicode Private Use Area (PUA) whenever
32 possible, instead preferring standard Unicode characters styled with OpenType
33 features.\footnote{For an explanation, see the \textit{Junicode Manual}, §\,4.1}
34 The Medieval Unicode Font Initiative (MUFI), founded before OpenType
35 was widely supported by software, defines more than 850 PUA characters, and
36 Junicode includes all of them. But the font also offers more-accessible
37 alternatives to all but a handful of these characters.
38
39 OpenType is a powerful technology, but it is undeniably more difficult
40 to work with than MUFI’s PUA characters and entities. To copy any character (or its
41 corresponding entity) from the MUFI website and paste it into your text is a
42 straightforward procedure. To do the same job with OpenType features is more
43 complex, requiring users to locate the correct Unicode characters
44 and features and to figure out how to make them work together in various software
45 programs.
46
47 {\pto} automates this task. For each PUA character or MUFI entity in a
48 text or HTML document, the script substitutes a \textbf{base} consisting of
49 one or more standard Unicode characters and, if necessary, applies one or
50 more \textbf{methods} (grounded in OpenType technology) to style this base. For
51 many characters, more than one base is available, and more than one method.
52
53 The methods employed by {\pto} are these:
54
55 \begin{description}
56 \item[otag (OpenType tag).] One or more OpenType features is turned on for a
57 character or sequence of characters in much the same way that, say, italics
58 can be applied to a run of text in a word processor: it is a modal method,
59 which has the advantage of being legible and widely understood but can greatly
60 swell the size of a text containing many PUA characters.
61
62 \item[utag (Unicode tag).] An alternative to the otag method is one (exclusive
63 to Junicode) that uses characters from the Unicode “Tags” range (U+E0020–E007E)
64 as a modeless style of markup in which a single base character is modified by
65 two following tag characters. When used in a browser, tag characters are
66 invisible and do not interfere with searches, but their invisibility can make
67 them difficult to work with. {\pto} can use entities for tag characters to
68 make them visible: the entities are resolved to tag characters when the text
69 is displayed.
70
71 \item[zwj (Zero-width joiner).] The zwj character (U+200D) can be used to signal
72 that two characters should be joined in a ligature: it provides an alternative
73 to otag-style markup. For example, the PUA code point U+EBAC is a ligature of
74 long \textex{s} (ſ) and insular \textex{v} (ꝩ): to obtain an equivalent one can
75 apply the OpenType feature \textSourceText{hlig} (Historic Ligatures) to the
76 base \textex{ſꝩ}—or one can place a zwj between the two characters. This method
77 is similar to the utag method in that it is modeless and employs a character
78 that is typically invisible.
79
80 \item[entity (Junicode entities).] For technical reasons, combining marks
81 encoded in the PUA should not be used, since software cannot position them
82 correctly over their bases. One alternative is to use Junicode entities,
83 which resemble HTML entities but begin with an underscore. For example, in the
84 sequence \textSourceText{a\&\_upmc;}, the entity \textSourceText{\&\_upmc;}
85 represents an upward-curving macron, which will be correctly positioned
86 over the preceding a: \textex{\addfontfeature{StylisticSet=10}a\&\_upmc;}.
87
88 \item[enla (Enlarge axis).] For some forty-five of MUFI’s “enlarged” letters,
89 used to represent the \textit{litterae notabiliores} of medieval manuscripts,
90 one can use Junicode’s Enlarge axis, which allows one to control the size
91 of the letters precisely (on a scale from 0 to 100, where 0 produces a
92 letter the size of other lowercase letters, and 100 produces a lowercase
93 letter the size of a capital—the default value is 32) without using either
94 MUFI’s PUA characters or Junicode’s \textSourceText{ss06} “Enlarged minusucles”
95 feature.
96 \end{description}
97
98 Alternate bases are grouped as follows (their names are followed by the
99 identifiers to be used with the “Alternate bases” option, discussed below):
100
101 \begin{description}
102 \item[Insular (\textSourceText{insular}).] By default, {\pto} replaces Unicode
103 characters described as
104 “insular” because these characters are often not searchable as their
105 alphabetic equivalents. However, since some projects have have good reasons
106 to retain these characters, {\pto}'s default behavior can be overridden (see
107 “Options” below for details).
108
109 \item[Small caps (\textSourceText{smallcap}).] MUFI PUA characters described as
110 “small capitals” are
111 by default replaced by normal alphabetic characters with OpenType markup applied
112 (typically \textSourceText{pcap} “Petite capitals”). But Unicode has characters
113 labeled “small capital.” These are not intended as variants of alphabetic
114 characters (they are instead phonetic characters), and in some software they
115 can’t be searched by their apparent alphabetic equivalents. But if you
116 prefer, the Unicode small caps can be used as a base.
117
118 \item[Punctuation (\textSourceText{punctuation}).] MUFI encodes a number of
119 punctuation marks in the PUA.
120 Often it is difficult to find a plausible Unicode base for these marks;
121 instead, Junicode uses the period as a base for all of them. Where
122 plausible bases are available, {\pto} uses them by default; but you can
123 use the period as a base if you prefer.
124
125 \item[Marks (\textSourceText{mark}).] As with punctuation, so with marks.
126 All of MUFI's combining
127 marks can be handled in Junicode as variants of the macron (U+0304), but
128 where better bases are available, they are used by default. If you prefer,
129 you can use the macron for all PUA-encoded punctuation marks.
130
131 \item[Currency (\textSourceText{currency}).] All of MUFI's PUA-encoded currency
132 symbols are treated by
133 Junicode as variants of U+00A4, Unicode's generic currency sign, but where
134 plausible Unicode bases are available, those are used instead. If you prefer,
135 it is possible to use U+00A4 as the base for all PUA-encoded currency symbols.
136
137 \item[Miscellaneous alphabetic (\textSourceText{alpha}).] For a few alphabetic
138 characters (U+E7E4 ,
139 U+EEFD , U+EEFE , U+F0A7 , U+F0A8 , U+F127 \,) more than one base can be
140 used. The defaults here are chosen to promote accessibility, but these
141 defaults can be overridden.
142 \end{description}
143
144 \noindent For both methods and bases, {\pto} consults a priority list: methods or base
145 classes are listed in order of preference: if more than one method or base class
146 is listed for a PUA character, the one that comes earliest in the priority list
147 is preferred. These lists are discussed further in the “Options” section below.
148
149 Before you do anything else with {\pto}, copy the two font files
150 \textSourceText{JunicodeVF-Roman.woff2} and \textSourceText{JunicodeVF-Italic.woff2}
151 into the \textSourceText{pua2ot/fonts} directory in the unzipped
152 Junicode file tree.
153
154 \subsection{With Graphical User Interface}
155
156 To use {\pto} with a GUI, find the file \textSourceText{pua2ot-gui.html} in
157 the \textSourceText{pua2ot/gui} directory and double-click or
158 drag it into an up-to-date web browser. The program will look like this:
159
160 \begin{figure}[h!]
161 \centering\includegraphics[width=\textwidth]{pua2ot.jpg}
162 \end{figure}
163
164 \noindent The large text-box on the left (initially displaying an excerpt from the
165 Middle English \textit{Ancrene Wisse}) is the \textbf{Source Box}; it shows the
166 text with PUA characters or entities. The text-box
167 on the right is the \textbf{Destination Box}: it displays the result of the
168 conversion. These two boxes should look the same: their sameness assures you that
169 the conversion has gone well.
170
171 Immediately below the text boxes are options that affect their operation.
172 To load a text or html file, click the “Choose File” button (“Browse” in some
173 browsers) or drag the file into the
174 Source Box. To edit the text, check the “Edit Source” box: you can type or
175 paste in text when editing is enabled. To see which
176 characters in the source are being replaced, check the “Mark Replaced Chars in
177 Source” box. To view the code that underlies the text displayed in the
178 Destination Box, check the “Show Code” box. To export the converted text,
179 click the “Download” or the “Copy” button.
180
181 To skip the conversion of any element of an HTML file, add the class
182 \textSourceText{noconv} to the element. You can add a
183 \textSourceText{{\textless}span{\textgreater}} with
184 class \textSourceText{noconv} to skip an arbitrary stretch of text.
185
186 The other options on the page affect the conversion. These are explained below,
187 in the “Options” section.
188
189 \subsection{Embedded in an HTML file}
190
191 The second version of the script converts the {\textless}body{\textgreater}
192 element of any HTML page before it is displayed, with the result that characters
193 that could not be searched will become searchable, and the accessibility of the
194 page will be improved. If the HTML file contains static text, make sure the
195 script file, \textSourceText{pua2ot-embed-min.js}, is
196 in the same folder as your HTML file. Then include
197 these lines at the very end of the {\textless}body{\textgreater}:
198
199 \begin{scriptsize}\begin{verbatim}<script src="pua2ot-embed-min.js"></script>
200 <script class="noconv">
201 // options.utagEntities = false;
202 // options.utagLookup = UTAG_DICT;
203 // options.nonWordTags = ["ss04", "ss05", "ss06", "pcap", "smcp", "hlig"];
204 // options.keepUnicode = false;
205 // options.methodPriority = "compact";
206 // options.prefList = ["utag", "zwj", "otag", "entity"];
207 // options.defaultTags = {"ss10": 1, "cv69": 7};
208 // options.language = "en";
209 // options.basePreferences = [];
210 // options.enlargedScale = 32;
211 // options.charSkip = [];
212 convertAll();
213 </script>\end{verbatim}\end{scriptsize}
214
215 \noindent If your web page loads text dynamically, it won’t work
216 simply to include the command \textSourceText{convertAll()} at the end of the
217 HTML file, as it will likely be executed before the text is loaded. Instead,
218 have the process that loads the text trigger an event when the loading is done
219 and call \textSourceText{convertAll()} from inside the event handler.
220
221 In the html file, include \textSourceText{noconv} in the class list of any element whose
222 content you don't want converted: the script will skip over such elements.
223
224 In the example above, the commented lines before the \textSourceText{convertAll()}
225 command are options, explained in a later section.
226
227 \subsection{Node module}
228
229 The file \textSourceText{pua2ot-common.js} includes instructions for using it as
230 a Node module, but if you are not making changes in the programming you can use
231 \textSourceText{node/pua2ot-node-min.js}, which packages the {\pto}
232 database and program code in a single minified file. The file exports the object
233 \textSourceText{options} (the options it supplies are listed in the next section)
234 and two functions: \textSourceText{pua2otNode.cleanup\_string(s)}, which collapses
235 all sequences of whitespace characters into single spaces, and
236 \textSourceText{pua2otNode.convert(text\_buffer, repl\_ent)}, which converts and returns
237 the text \textSourceText{text\_buffer}, first replacing any MUFI entities if
238 \textSourceText{repl\_ent} is true.
239
240 For an example of how the Node module can be used, consult and run the file
241 \textSourceText{test2.js}. Note especially the \textSourceText{require} statement in
242 line 3, the \textSourceText{options} object in line 13, and the invocation of
243 \textSourceText{convert()} in line 15.
244
245
246 \subsection{Reference page}
247
248 In the \textSourceText{src} folder is a file \textSourceText{charlist.html}. Drag this
249 into a web browser to view a list of all the transformations that {\pto} is capable
250 of. Originally intended as a tool for proofing the database that powers {\pto},
251 the page can also be used to look up the methods for individual PUA codes. Type the
252 hexadecimal code for any of MUFI's PUA characters into the “Filter” box. Alternatively,
253 type any word or phrase (e.g. “combining,” “small capital”) to search for in the
254 “description” column. To view the hexadecimal codes for the Unicode base for any
255 conversion, click on a cell in the “base” column. To view the underlying code for
256 any character, click on any of the last five columns of the row for the character
257 you are interested in. You can copy any of these methods onto the clipboard and
258 paste them into a document: just click the “Copy” button in the dialog that appears
259 when you click on one of the last five cells in a row.
260
261
262 \section{Options}
263
264 In addition to the checkboxes, menus, and text-entry blanks in the web app, the
265 JavaScript program has an \textSourceText{options} object whose properties can be
266 manipulated to affect the program's output.
267
268 \subsection{More legible markup}
269
270 Program default: \textSourceText{options.methodPriority="compact"}.\\
271 By default, {\pto} uses the \textbf{utag} method for most of its
272 conversions of single characters and the \textbf{zwj} method for most ligatures: these
273 two methods occur first in the “compact” preference list. Because the Unicode tags and
274 zero-width joiner employed by these methods are zero-width and invisible, they can
275 make it difficult to diagnose problems in your code. If you set this option to
276 “legible,” {\pto} will prefer the \textbf{otag} and (where appropriate) \textbf{enla}
277 methods, which insert HTML tags into the text so that you can see clearly what the code
278 is doing. If you choose the “legible” option to generate a web page, the HTML file
279 for the page will be noticeably larger than with the “compact” option: you should
280 consider running the output of this script through a utility (e.g. the
281 \href{https://www.npmjs.com/package/html-style-converter}{Javascript HTML Style
282 Converter}) that converts inline styles to a CSS stylesheet.
283
284 \subsection{options.prefList}
285
286 Program default: \textSourceText{options.prefList = [\char"0022utag\char"0022, \char"0022zwj\char"0022,
287 \char"0022enla\char"0022, \char"0022otag\char"0022, \char"0022entity\char"0022]}.\\
288 Not available in the GUI flavor. Use this option to install a custom priority
289 list instead of the two predefined lists labeled “compact” and “legible.”
290 Methods that come earlier in the array are preferred over those that come later.
291
292 \subsection{Use entities for Unicode tags}
293
294 Program default: \textSourceText{options.utagEntities=false}.\\
295 If \textSourceText{true}, {\pto} uses entities to represent Unicode tags. (These are not
296 HTML entities, but unique to Junicode.) This makes the code produced by this script more
297 legible, but the entities make the page somewhat larger and can interfere with searching.
298 The best use of this feature may be to help you spot problems with your Unicode tags
299 and turn it off before publishing your text.
300
301 \subsection{Keep problematic Unicodes}
302
303 Program default: \textSourceText{options.keepUnicode=false}.\\
304 “Problematic Unicodes”
305 are characters that are standard Unicode (not PUA) and look like
306 variants of common characters, but that many applications do not recognize as
307 variants. Examples include dotless i (\textex{ı}, \unic{U+0131}) and the “insular”
308 letter-shapes (e.g. \textex{ꝺ}, \unic{U+A77A}). By default, this script replaces these
309 characters with ones that can be searched as letters of the alphabet (e.g. \textex{ꝺ} as
310 \textex{d}). To retain the “problematic Unicodes,” likely simplifying your markup and
311 making your file smaller, but making your text less accessible in some applications,
312 check this box in the GUI version or set \textSourceText{options.keepUnicode=true}.
313
314 \subsection{Alternate bases}
315
316 Program example: \textSourceText{options.basePreferences=["insular", "punctuation"]}.\\
317 As a large font with many OpenType features, Junicode often provides more than one way
318 to achieve the outcome you want. This option affects the character classes
319 mentioned above, pp. 2–3. Select one or more of the items in the GUI list (use the
320 Shift or Control/Command keys to make multiple selections) or assign an array
321 containing the identifiers for these classes to \textSourceText{options.basePreferences}:
322 {\pto} will use alternate bases for the classes you select.
323
324 \subsection{options.replaceMUFIEntities}
325
326 Program default: \textSourceText{options.replaceMUFIEntities=true}.\\
327 If \textSourceText{true}, MUFI’s entities (those that
328 resolve to PUA code points) are replaced by those code points before any other processing
329 takes place. Set this to \textSourceText{false} if the text you want to convert contains
330 no entities and you want to save a little time processing a large text.
331 Not available in the GUI, where entities are always converted.
332
333 \subsection{Default features}
334
335 Program default: \textSourceText{options.defaultTags=\{\char"0022ss10\char"0022:\,1,\,\char"0022cv69\char"0022:\,7\}}.\\
336 GUI default: \textSourceText{ss10 cv69[7]}.\\
337 You may wish some OpenType features to be on for the whole document. For example,
338 \textSourceText{ss10} “Entities and Tags” must be on in any document that uses Junicode entities or
339 Unicode tags. To manage
340 your text’s OpenType features, this script needs to know about these default features;
341 and when you download or copy your text, they will be recorded in an enclosing {\textless}div{\textgreater}.
342 Note the formats: In the GUI this is a space-separated list of four-letter OpenType tags; if you need
343 to add an index, do so in square brackets immediately after the tag (the format used in the
344 \textit{Junicode Manual}). Elsewhere it is a comma-separated list of key-value pairs, where the keys
345 (four-letter tags identifying OpenType features) are in double quotation marks, followed
346 by a colon and a number (1 means “on,” but some features (especially the \textSourceText{cvnn}
347 “Character Variant” features) require a numerical index).
348
349 \subsection{Non-word tags}
350
351 Program default: \textSourceText{options.nonWordTags=[\char"0022ss04\char"0022,\char"0022ss05\char"0022,\char"0022%
352 ss06\char"0022,\char"0022pcap\char"0022,\char"0022smcp\char"0022,\char"0022hlig\char"0022,%
353 \char"0022enla\char"0022]}.\\
354 GUI default: \textSourceText{ss04 ss05 ss06 pcap smcp hlig enla}.\\
355 When “More legible markup”
356 is checked, the script applies most <span> tags to whole words, but
357 a few to individual characters. This distinction is based on an educated guess as to which OpenType
358 features are appropriate to apply to whole words. Sometimes this guess will be wrong. For example, the
359 word \textit{rectificaꞇionem} (about halfway through the sample \textit{Ancrene Wisse} text) contains two different
360 styles of \textex{t}, but when \textSourceText{cv40} (which transforms default \textex{t} into insular
361 \textex{ꞇ}) is applied to the whole word,
362 that difference is erased. If you add \textSourceText{cv40} to this list, the feature \textSourceText{cv40}
363 will always be applied to single letters rather than whole words. In the GUI version of {\pto},
364 this is a space-separated list of four-letter tags (only tags used by this program are accepted here);
365 elsewhere these tags must be enclosed in
366 quotation marks and separated by commas, and the whole list must be enclosed in square brackets.
367
368 \subsection{Language}
369
370 Program default: \textSourceText{options.language=\char"0022en\char"0022}.\\
371 It is important to set the language properly, both here and in your document, since this script
372 and some of Junicode’s OpenType features behave differently depending on the language. If your
373 language is not in the drop-down list (available
374 only in the GUI), choose “Other” and type in the two-letter code for the language (you can look
375 it up \href{https://www.w3schools.com/tags/ref_language_codes.asp}{here}.).
376
377 \subsection{Enlarge axis scale}
378
379 Program default: \textSourceText{options.enlargedScale=32}.\\
380 When \textSourceText{options.methodPriority="legible"}, or when you use a custom priority list
381 with \textSourceText{“enla”} near the top, {\pto} will invoke Junicode’s Enlarge Axis for
382 “enlarged minuscules.” One advantage of this method is that you can precisely control their
383 size on a scale from 0 (the letter is the same size as other lowercase letters) to 100 (the
384 letter is the same size and weight as a capital). The default is 32, which makes it the same
385 size as the enlarged minuscules produced by other means.
386
387 \subsection{Skip character}
388
389 Program example: \textSourceText{options.charSkip=["0131", "A787", "A77A", "F0AE"]}.\\
390 GUI example: \textSourceText{\jRegular ı A787 A77A }.\\
391 To cause {\pto} to skip over all instances
392 of a character, enter it here. In the GUI, you can type or paste a space-separated
393 list of characters and hexadecimal codes in the blank. In programming, only hexadecimal
394 codes are allowed; they must be
395 enclosed in quotation marks and separated by commas, and the whole list must be enclosed in
396 square brackets.
397
398 \end{document}