summaryrefslogtreecommitdiff
path: root/macros/optex/pkg/minim-pdf.opm
blob: 3c4c0c73317344922ae5228fcb5bcb099c32793c (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
% This is macro package used by OpTeX, see http://petr.olsak.net/optex
% minim-pdf.opm, Michal Vlasák  <lahcim8@gmail.com>, 2022 
% see also https://github.com/vlasakm/optex-minim

\_codedecl \nohyphlang {Minim-PDF for \OpTeX/}
\_namespace{minimpdf}

   \_doc
   Before loading `minim-pdf` we do a few preparations. Most importantly
   adjusting core of minim, which is done in `minim.opm`.
   \_cod

\_load[minim]

\_catcode`\@=11
\_catcode`\:=11

   \_doc
   Minim hooks into language mechanism with standard \eTeX/
   `\uselanguage@hook`. It can then translate language names (e.g
   \"SwissGerman") into BCP 47 language identifiers (e.g. \"de-ch-1901", the
   naming scheme of the `hyph-utf8` package) which are then embedded into
   tagged PDFs. For simplicity, we use what \OpTeX/ calls \"lang-tag" (e.g.
   \"de") which may not be precise enough (i.e. the right thing for Swiss
   German would be \"de-ch") and may even be wrong(?).

   When e.g. `\gswlang` (Swiss German) is used, `\uselang{gsw}\_gswPatt<...>`
   is called in \OpTeX/. We use the fact, the there is mapping from language
   register numbers (`\_gswPatt`) to \"lang-tag"s (\"de"). To avoid confusion
   with any other language mappings, we prefix what we give to minim with `o:`.

   We also don't incorporate the \eTeX/ `\uselanguage@hook`, but call minim's
   callback directly, maybe it will cause less trouble with other packages
   (since we don't pass standard names to the callback) and also gives a better
   idea of what happens.
   \_cod

\_let\.uselang=\_uselang
\_def\_uselang#1#2#3#4{%
   \.uselang{#1}{#2}{#3}{#4}%
   % just set this everytime, doesn't hurt
   \setlanguagecode{o:#1}{\_cs{_lan:\_the#2}}%
   \minim:uselanguagecallback{o:#1}%
}

   \_doc
   If not detected, a few \"dummy" languages would be (in erroneous ways)
   defined by minim: like \"nohyph" and \"undetermined". We define a few dummy
   control sequences, to make minim not define them, since we define them
   ourselves below. They are used in standard way, but their \"ISO codes" are weird:

   \begtt
   \nohyphlang
   \nolanglang
   \uncodedlang
   \undeterminedlang
   \endtt
   \_cod

\_let\lang@nohyph=\_empty
\_let\lang@nolang=\_empty
\_let\lang@uncoded=\_empty
\_let\lang@undetermined=\_empty

\_preplang nohyph       nohyph       und {} 11
\_preplang nolang       nolang       und {} 11
\_preplang uncoded      uncoded      und {} 11
\_preplang undetermined undetermined und {} 11

   \_doc
   Now we actually load `minim-pdf`.
   \_cod

\_input minim-pdf

   \_doc
   Users aren't supposed to define custom languages in \OpTeX/, forbid that.
   \_cod

\_def\_tmp{\errmessage{don't use this command with OpTeX}}
\_let\newnamedddialect=\_tmp
\_let\newnameddllanguage=\_tmp

   \_doc
   Since a language may already be set (at least the default Knuth english),
   then we need to tell minim about it, by reexecuting the language command
   (like `\enlang`), thus calling into minim through the above mentioned hook.
   \_cod

% set the current language again to let minim know what it is
\_cs{\_cs{_lan:\_the\_language}lang}


% catcodes changes don't propage, since this file is loaded with \opinput
\_endnamespace
\_endcode