musings-deserved.tex /size: 15 Kb    last modification: 2024-01-16 10:21
1% language=us runpath=texruns:manuals/musings
2
3% \enableexperiments[fonts.compact]
4
5\startcomponent musings-deserved
6
7\environment musings-style
8
9\startchapter[title={We deserved it}]
10
11\startsection[title={Introduction}]
12
13Among the first macros we cooked up are the ones that we used to typeset
14chemistry. They come under the \PPCHTEX, and it was mostly done by Hans, Ton and
15Tobias. Over time rendering structures by \PICTEX\ got replaced by \PSTRICKS\ and
16later \METAPOST. When we moved to \MKIV\ all that got reimplemented, this time by
17Hans and Alan and we stuck to \METAPOST. We actually also updated the syntax and,
18because old documents were supposed to be rendered by \MKII\ we took the liberty
19to sacrifice some compatibility for a more complete and consistent feature set.
20However we never came to updating the existing manual and the new one became work
21in progress. We didn't really needed the code and Alan, who did need it, knew
22what was there anyway.
23
24Then Mikael had some questions and it pushed me into manual mode: upgrade the old
25one and combine it with the pending new one. That also made me wonder if we could
26now benefit from some new features in the math engine, which in turn could
27simplify the code base. This is typically something that takes weeks instead of
28hours so better do it right from the start. And, while at it, one then of course
29ends up in looking (again) at arrows (or more specifically: stackers) and from
30that to \UNICODE, which in turn is good for some introspection.
31
32\stopsection
33
34\startsection[title={Implementation}]
35
36Among the (old) complications in dealing with chemistry are the following:
37
38\startitemize[packed]
39\startitem
40    Simple inline chemical formulas (snippets) of the kind \ic { U __92 ^^ 238 ^
41    +} where scripts need to be properly vertically aligned and an upright font
42    is used.
43\stopitem
44\startitem
45    In running text one wants to use \ic {A + B -> C} but also \ic {A + B <-> C}
46    or \ic {A + B <=> C}.
47\stopitem
48\startitem
49    Even more symbolic representations might be on the wish list, think of
50    \ic {A - B -- C --- D}.
51\stopitem
52\stopitemize
53
54There is more but these examples demonstrate a few features: we need prescripts,
55proper spacing, line breaks at preferred spots, and some symbols.
56
57\start
58
59\setupalign[profile]
60% \showglyphs \showmakeup[boxes] \showstruts
61\setupmathstackers[reverse][strut=no]
62
63\startitemize[packed]
64\startitem
65    And of course one also wants to annotate like \ic {A + B ->{here} C} but also
66    \ic {A + B <->{}{there} C} or \ic {A + B <=>{where}{every} C} where the
67    arrows stretch with the text.
68\stopitem
69\startitem
70    It would be nice if we can also use the advanced alignment options that are
71    available in math but discussing this is beyond this musing.
72\stopitem
73\stopitemize
74
75\stop
76
77\stopsection
78
79\startsection[title=Unicode]
80
81Implementing the above has never been that hard but just became a little easier
82in \LMTX. However, when doing that I wondered if there were more than the already
83present symbols to be taken care of. And so I did a search on the internet for
84\quotation {unicode and chemistry}. One of the first hits was \quotation {Five
85symbols used in chemistry L2/23-193}, a request for some more arrows. One can
86search the web for it and see if it is still around. When staring at I wondered a
87bit about the descriptions:
88
89\starttyping
90BALANCED EQUILIBRIUM ARROW
91EQUILIBRIUM ARROW LYING TOWARD THE RIGHT
92EQUILIBRIUM ARROW LYING TOWARD THE LEFT
93REACTION DOES NOT PROCEED
94STANDARD STATE SYMBOL
95\stoptyping
96
97When later I discussed this with Mikael we came to the conclusion that \quote
98{LYING} probably means \quote {LEANING} but we're not chemists so we can be
99wrong. The proposed rendering of the first three boils down to arrows with half a
100tip, also known as harpoons: long left and right pointing ones stacked for the
101first and long over short ones for the other two.
102
103\startlinecorrection
104\setupmathstackers[mathematics][strut=no]
105\startcombination[nx=3,ny=1]
106    {\vbox{\offinterlineskip\glyphscale2000
107        \ruledhbox to 2cm{$\mrightharpoonup {\hskip2cm}{}$}
108        \ruledhbox to 2cm{$\mleftharpoondown{\hskip1cm}{}\hss$}
109    }} {}
110    {\vbox{\offinterlineskip\glyphscale2000
111        \ruledhbox to 2cm{$\mrightharpoonup {\hskip2cm}{}$}
112        \ruledhbox to 2cm{$\mleftharpoondown{\hskip2cm}{}$}
113    }} {}
114    {\vbox{\offinterlineskip\glyphscale2000
115        \ruledhbox to 2cm{$\mleftharpoonup{\hskip2cm}{}$}
116        \ruledhbox to 2cm{\hss$\mrightharpoondown{\hskip1cm}{}$}
117    }} {}
118\stopcombination
119\stoplinecorrection
120
121There are several observation to make here. First of all, there is a whole bunch
122of arrows (stacked and single) that bare descriptions mentioning them being
123arrows. There is no meaning in them. One can even wonder why some are there. So,
124in order to be in sync with that it makes more sense to add a few more harpoons.
125Cooking up names like this serves no purpose.
126
127If we look at the proposed shapes (which are actually different from those used
128in \TEX\ packages that are references) one can actually wonder about the way
129these are supposed to stretch. The short variant is not different from existing
130double harpoons in which case the meaning is lost. Then when we go longer we get
131this empty space and then we should wonder how the extensible should kick in: how
132do the left- and rightmost fixed glyphs and the one or two middle repeated ones
133behave?
134
135\startlinecorrection
136\setupmathstackers[mathematics][strut=no]
137\startcombination[nx=3,ny=1]
138    {\vbox{\offinterlineskip\glyphscale2000
139        \ruledhbox to 1cm{$\mrightharpoonup {\hskip1cm}{}$}
140        \ruledhbox to 1cm{$\mleftharpoondown{\hskip1cm}{}\hss$}
141    }} {}
142    {\vbox{\offinterlineskip\glyphscale2000
143        \ruledhbox to 1cm{$\mrightharpoonup {\hskip1cm}{}$}
144        \ruledhbox to 1cm{$\mleftharpoondown{\hskip1cm}{}$}
145    }} {}
146    {\vbox{\offinterlineskip\glyphscale2000
147        \ruledhbox to 1cm{$\mleftharpoonup{\hskip1cm}{}$}
148        \ruledhbox to 1cm{\hss$\mrightharpoondown{\hskip1cm}{}$}
149    }} {}
150\stopcombination
151\stoplinecorrection
152
153Why don't we just use the next three? After all, as with math, how we interpret
154symbols depends on how we define them to be read. Sometimes Mikael and I get a
155good laugh over some of the shapes bound to math code points and we're sure that
156some legend is needed when using them.
157
158\startlinecorrection
159\setupmathstackers[mathematics][strut=no]
160\startcombination[nx=3,ny=1]
161    {\vbox{\offinterlineskip\glyphscale2000
162        \ruledhbox to 2cm{$\mleftrightharpoons{\hskip2cm}{}$}
163    }} {}
164    {\vbox{\offinterlineskip\glyphscale2000
165        \ruledhbox to 2cm{$\mrightharpoonup {\hskip2cm}{}$}
166    }} {}
167    {\vbox{\offinterlineskip\glyphscale2000
168        \ruledhbox to 2cm{$\mleftharpoondown{\hskip2cm}{}\hss$}
169    }} {}
170\stopcombination
171\stoplinecorrection
172
173Of course there are and can be conventions but getting some agreement is not
174trivial. We only have to look at \UNICODE\ math to see some issues, like:
175
176\startitemize[packed]
177\startitem
178    The repertoire of symbols is large but to a large extent somewhat arbitrary:
179    what was known (or assumed) to be used got in there. There is a difference
180    between a left, right and even middle bar, just like there is a left and
181    right brace.
182\stopitem
183\startitem
184    There are alphabets but they come with holes. We're not supposed to
185    distinguish between a Plank constant \quote {h} and variable \quote {h}. We
186    can distinguish the greek uppercase \type {A} from a latin \type {A} so
187    mathematicians are less convincing.
188\stopitem
189\startitem
190    One can define extensible fences with components but not all of them. There
191    are no constructors for arrows. Some likely come from old encodings but
192    why add these and not be consistent.
193\stopitem
194\stopitemize
195
196Plugging a hole in an alphabet is doable. Adding some missing snippets for fences
197is also no big deal, just because we have a limited set. Making bars consistent
198also is not hard. But I don't see it happen soon. After all, we're decades along
199the road and no one bothered much about it till now, and above all, it will never
200be complete. I wonder if there ever has been a good analysis, extensive
201description and a watertight arguing from the \TEX\ community about what should
202go in \UNICODE\ and fonts. It was easy to point to existing fonts and the names
203used in macro packages and that shows.
204
205To the above we can add:
206
207\startitemize[packed]
208\startitem
209    There are some combinations of arrows and e.g.rules missing that could have
210    made adding composed constructs easier when there is demand for that. After
211    all, this is what existing characters are also used for. And these chemistry
212    ones fit into this.
213\stopitem
214\stopitemize
215
216Our solution is to just accept that the \TEX\ community got what it deserved: a
217bit of chaos, unreliable cur'n'paste support, symbols but no meaning, imperfect
218\UNICODE\ coverage and therefore imperfect coverage in fonts. The good news is
219that we can adapt. But we have to be honest: it is not perfect.
220
221\stopsection
222
223\startsection[title=How about]
224
225As mentioned we have a problem with base glyphs versus extensibles and these
226combined hooked things are bad for that. In the chemistry macros the first four
227are the ones that we always had and the last two are examples of how we can
228render the two leaning extras.
229
230\starttabulate[|c||c||]
231\NC \type {<->} \NC \ic {A + B <-> C}\NC \type {<-->} \NC \ic {A + B <--> C} \NC \NR
232\NC \type {->}  \NC \ic {A + B  -> C}\NC \type {-->}  \NC \ic {A + B  --> C} \NC \NR
233\NC \type {<-}  \NC \ic {A + B <-  C}\NC \type {<--}  \NC \ic {A + B <--  C} \NC \NR
234\NC \type {<=>} \NC \ic {A + B <=> C}\NC \type {<==>} \NC \ic {A + B <==> C} \NC \NR
235\ML
236\NC \type {=>}  \NC \ic {A + B  => C}\NC \type {==>}  \NC \ic {A + B  ==> C} \NC \NR
237\NC \type {<=}  \NC \ic {A + B <=  C}\NC \type {<==}  \NC \ic {A + B <==  C} \NC \NR
238\stoptabulate
239
240Watch the longer should arrow. Not al fonts have it as extensible, which
241indicates that not that much thought has been put in usage patterns. That said,
242more interesting would be to use something like this, where we fake a character
243from two existing arrows:
244
245\startlinecorrection
246\switchtobodyfont[cambria]
247\definemathextensible [mathematics] [mleftarrowdashed]  ["21E0]
248\definemathextensible [mathematics] [mrightarrowdashed] ["21E2]
249\setupmathstackers[mathematics][strut=no]
250\startcombination[nx=4,ny=1]
251    {\vbox{\offinterlineskip\glyphscale2000
252        \ruledhbox{$\mrightarrow     {}{}$}
253        \ruledhbox{$\mleftarrowdashed{}{}$}
254    }} {}
255    {\vbox{\offinterlineskip\glyphscale2000
256        \ruledhbox{$\mrightarrow{}{}$}
257        \ruledhbox{$\mleftarrow {}{}$}
258    }} {}
259    {\vbox{\offinterlineskip\glyphscale2000
260        \ruledhbox{$\mrightarrowdashed{}{}$}
261        \ruledhbox{$\mleftarrow       {}{}$}
262    }} {}
263    {\vbox{\offinterlineskip\glyphscale2000
264        \ruledhbox{$\mrightarrowdashed{}{}$}
265        \ruledhbox{$\mleftarrowdashed {}{}$}
266    }} {}
267%     {\vbox{\offinterlineskip\glyphscale2000
268%         \ruledhbox to 2cm{$\mrightarrow     {\hskip2cm}{}$}
269%         \ruledhbox to 2cm{$\mleftarrowdashed{\hskip2cm}{}$}
270%     }} {}
271%     {\vbox{\offinterlineskip\glyphscale2000
272%         \ruledhbox to 2cm{$\mrightarrow{\hskip2cm}{}$}
273%         \ruledhbox to 2cm{$\mleftarrow {\hskip2cm}{}$}
274%     }} {}
275%     {\vbox{\offinterlineskip\glyphscale2000
276%         \ruledhbox to 2cm{$\mrightarrowdashed{\hskip2cm}{}$}
277%         \ruledhbox to 2cm{$\mleftarrow       {\hskip2cm}{}$}
278%     }} {}
279%     {\vbox{\offinterlineskip\glyphscale2000
280%         \ruledhbox to 2cm{$\mrightarrowdashed{\hskip2cm}{}$}
281%         \ruledhbox to 2cm{$\mleftarrowdashed {\hskip2cm}{}$}
282%     }} {}
283\stopcombination
284\stoplinecorrection
285
286However, not all math fonts provide these dashed arrows and therefore here we
287have to use Cambria (here). And even if it has such dashed hashes, they don't
288come with an extensible. I just want to point out that by looking at what we
289already have, it might make more sense to extend some (combinations) of those.
290
291It is good to notice that these arrows come with qualifications like \quotation
292{code for undetermined script}, so one can wonder how much they relate to math.
293Actually the fact that we have these holes in alphabets already indicates that
294math is not really seen as script. Occasionally (old) scripts get added and they
295get lots of code points, while one can argue for sharing there too, but maybe
296their status is higher than the status of math. In \OPENTYPE\ fonts math is seen
297as script but that's because it is basically a selector. One can actually argue
298for chemistry as a math language in fonts.
299
300The main point I want to make here is that adding some new symbol that is
301somewhere used but never made it in \UNICODE\ in the first place needs some
302thought. Especially when used in a setting of formulas, where size matters.
303
304\stopsection
305
306\startsection[title=Also]
307
308In \CONTEXT\ we have stackers: text above and|/|or below an extensible, or
309extensibles above and|/|or below text. The mentioned arrows are using this
310mechanism. However, when playing with \type {\iff}, \typ {\implies} and \typ
311{impliedby} in math mode, we noticed some spacing side effects. Originally these
312double arrows got skips around them but that interfered with our alignment
313mechanism. However, that could be solved without much hassle by letting the
314commands check the nature (class) of the previous atom (an indication of being at
315the start of a next alignment line). In the end that we decided that an extra
316\quote {implication} class was more flexible than adding glue. More interesting
317was the observation that in Latin Modern and some other math fonts these arrows
318have different dimensions, which leads to yet another alignment issue.
319
320Again that could be solved by taking the usage into account but one can wonder
321why the opportunity was lost to make the glyphs consistent with each other, read:
322come up with a proper analysis of requirements based on decades of \TEX\ usage.
323At least there could have been recommended alternates. But wait, aren't
324alternates kind of bad as they demand user intervention (choices)? Sure, but
325there are more examples of alternates, take the \quote {\dotlessi} (dotless i).
326It has a textual code point but is not in the math alphabets, so one needs
327alternates as way out (and yes, fonts then have a blackboard and fraktur dotless
328i).
329
330One can argue that these are visual aspects, but with arrows as well as symbols,
331we have ended up in a somewhat curious inconsistent situation: there are no
332established command names for the single arrows, so there we speak \type
333{\..arrow..} while for some there are names, like \type {\iff}. The same is true
334for characters like the dotless i and j. Some mathematicians use these in the
335same way as some hard- and software vendors put an \quote {i} in front of a
336product name, but in order to get it one has to communicate in terms of \type
337{\dotless.} or somthing with an \type {i} in the macro name.
338
339\stopsection
340
341\startsection[title=Conclusion]
342
343To come back to updating chemistry. It makes no sense to add much more.
344Implementing the left- and right leaning is easy with existing hooks so this is
345what we will do. Proper math fonts have these and how likely is it that existing
346math fonts get new ones? If it ever comes to more chemistry in \UNICODE\ a
347handful of them will not help much. It is probably not that hard to find an
348existing symbol that can act as standard state symbol. In fact, some code points
349have several additional descriptions so we could just add some to existing one.
350It's not like we have gone over the top with doing that for math yet.
351
352\stopsection
353
354\stopchapter
355
356\stopcomponent
357