examples-style-math.tex /size: 6404 b    last modification: 2025-02-21 11:03
1% language=us
2
3\startenvironment examples-style-math
4
5\def\ExampleLanguages{\currentmainlanguage}
6
7\setupframedtext
8  [result]
9  [align=flushleft]
10
11%definefontfeature[fixedwidth][fixedwidth=0.30]
12%definefontfeature[fixedwidth][fixedwidth=0.28]
13\definefontfeature[fixedwidth][fixedwidth=0.27]
14
15% \definefontfallback
16%   [MonoMathMath]
17%   [dejavusansmono.ttf*fixedwidth]
18%   [0x0400-0x600][rscale=.8]
19
20\definefontfallback
21  [MonoMathMath]
22  [cmuntt.otf*fixedwidth]
23  [0x0400-0x600]
24
25\definefontfallback
26  [MonoMathMath]
27  [concrete-math.otf*fixedwidth]
28  [0x0600-0x1FFFF]
29
30\definefontsynonym
31  [MonoMathBase]
32  [lmmono10-regular.otf*fixedwidth]
33  [fallbacks=MonoMathMath]
34
35% \definefontfallback
36%   [MonoTextMath]
37%   [dejavusansmono.ttf*fixedwidth]
38%   [0x0400-0x600][rscale=.8]
39
40\definefontfallback
41  [MonoTextMath]
42  [cmuntt.otf*fixedwidth]
43  [0x0400-0x600]
44
45\definefontfallback
46  [MonoTextMath]
47  [concrete-math.otf]
48  [0x0600-0x1FFFF]
49
50\definefontsynonym
51  [MonoTextBase]
52  [lmmono10-regular.otf]
53  [fallbacks=MonoTextMath]
54
55\definefontsynonym
56  [MonoMathBaseBold]
57  [lmmonolt10-bold.otf*fixedwidth]
58  [fallbacks=MonoMathMath]
59
60\definefont[MyMathFont]    [MonoMathBase]
61\definefont[MyMathFontBold][MonoMathBaseBold]
62\definefont[MyTextFont]    [MonoTextBase]
63
64\setuptyping
65  [style=MyMathFont]
66
67% \setupmathematics[domain=default]
68
69\starttexdefinition protected ShowExampleMeaning #1
70    \begingroup
71        \ifcstok{#1}\currentmainlanguage
72            \darkblue
73        \orelse\ifcstok{#1}{debug}%
74            \darkgray
75        \fi
76        \getmathtextblob{#1}\currentmathblob
77    \endgroup
78    \blank[medium]
79\stoptexdefinition
80
81% \starttexdefinition protected StartExample
82%     \begingroup
83%     \obeylines
84%     \doifnextcharelse[\StartExampleYES\StartExampleNOP
85% \stoptexdefinition
86
87% \starttexdefinition tolerant protected StartExampleYES[#1]
88%     \doifelsemode {issues} {
89%         \definecolor[issuecolor][darkred]
90%         \doifelse {#1} {issue} {
91%             \dostartbuffer[example][StartExample][StopExample]
92%         } {
93%             \endgroup
94%             \gobbleuntil\StopExample
95%         }
96%     } {
97%         \doif {#1} {issue} {
98%             \definecolor[issuecolor][darkred]
99%         }
100%         \dostartbuffer[example][StartExample][StopExample]
101%     }
102% \stoptexdefinition
103
104% \starttexdefinition tolerant protected StartExampleNOP
105%     \doifelsemode {issues} {
106%         \endgroup
107%         \gobbleuntil\StopExample
108%     } {
109%         \dostartbuffer[example][StartExample][StopExample]
110%     }
111% \stoptexdefinition
112
113\starttexdefinition protected StartExample
114    \begingroup
115    \begingroup
116    \obeylines
117    \doifnextcharelse[\StartExampleYES\StartExampleNOP
118\stoptexdefinition
119
120\starttexdefinition tolerant protected StartExampleYES[#1]
121    \endgroup
122    \doifelsemode {issues} {
123        \definecolor[issuecolor][darkred]
124        \doifelse {#1} {issue} {
125            \dostartbuffer[example][StartExample][StopExample]
126        } {
127            \gobbleuntil\StopExample
128        }
129    } {
130        \doif {#1} {issue} {
131            \definecolor[issuecolor][darkred]
132        }
133        \dostartbuffer[example][StartExample][StopExample]
134    }
135\stoptexdefinition
136
137\starttexdefinition tolerant protected StartExampleNOP
138    \endgroup
139    \doifelsemode {issues} {
140        \endgroup
141        \gobbleuntil\StopExample
142    } {
143        \dostartbuffer[example][StartExample][StopExample]
144    }
145\stoptexdefinition
146
147\starttexdefinition protected StopExample
148    \startresult[none][foregroundcolor=issuecolor]
149        \getbuffer[example]
150    \stopresult
151    \vskip5mm
152    \savemathexport[buffer=mmldata,xoption=ascii]
153    \begingroup
154        \MyTextFont \raggedright
155        \processcommacommand[\ExampleLanguages]\ShowExampleMeaning
156    \endgroup
157    \begingroup
158        \switchtobodyfont[6pt]
159      % \switchtobodyfont[7pt]
160      % \let\slxbold\relax
161        \def\slxbold{\MyMathFontBold}%
162        \typebuffer[example][option=TEX]
163        \scratchcounterone\nofbufferlines{mmldata}
164        \ifnum\scratchcounterone>\zerocount
165            \scratchcountertwo\maxbufferwidth{mmldata}
166            \scratchcounterthree\ctxlua{context(
167                \number\textwidth//(\number\scratchcountertwo*\number\emwidth)
168            )}\relax % columns needed
169            \scratchcounterfour\ctxlua{context(
170                \number\textheight//\number\pagetotal
171            )}\relax % available
172            \ifnum\scratchcounterthree=\zerocount
173                \typebuffer[mmldata][option=XML,n=\the\currentmathblob]%
174            \orelse\ifnum\scratchcounterone>\scratchcounterfour
175                \startcolumns[n=\scratchcounterthree,balance=no]
176                    \typebuffer[mmldata][option=XML,n=\the\currentmathblob]%
177                \stopcolumns
178            \else
179                \typebuffer[mmldata][option=XML,n=\the\currentmathblob]%
180            \fi
181        \fi
182    \endgroup
183    \endgroup
184    \page
185\stoptexdefinition
186
187% Setting up math:
188
189% \setupnote[mathnote][location=page]
190% \enabletrackers[math.textblobs]
191
192\disabledirectives[structures.tags.shipout]
193\enabledirectives [structures.tags.math.standalone]
194% \disabledirectives[structures.tags.math.strip]
195
196\setuptagging
197  [state=start]
198
199\definemathgroupset
200  [demogroupset]
201  [every]
202
203\setmathgroupset
204  [demogroupset]
205
206% This depends on the math used:
207
208% \registermathfunction[𝑓]
209% \registermathfunction[𝑔]
210
211% \registermathsymbol[default][en][𝐮][the vector]
212% \registermathsymbol[default][en][𝐯][the vector]
213% \registermathsymbol[default][en][𝖠][the matrix]
214
215% \registermathsymbol[default][en][lowercasebold]           [the vector] % [of]
216% \registermathsymbol[default][en][uppercasesansserifnormal][the matrix]
217
218% \registermathsymbol[default][sv][𝐮][vektorn]
219% \registermathsymbol[default][sv][𝐯][vektorn]
220
221% \registermathsymbol[default][sv][lowercasebold]           [vektorn]
222% \registermathsymbol[default][sv][uppercasesansserifnormal][matrisen]
223
224% \registermathsymbol[default][en][𝒞][the continuous functions]
225% \registermathsymbol[default][sv][𝒞][de kontinuerliga funktionerna]
226
227% Take your choice:
228
229% \def\ExampleLanguages{en,sv}
230% \def\ExampleLanguages{debug,en,sv}
231% \def\ExampleLanguages{debug,en,sv,nl}
232
233% \enablemode[issues]
234
235% \enabletrackers[structures.tags.math.times]
236% \enabletrackers[structures.tags.math.keeplast=mmldata]
237% \enabletrackers[structures.tags.math.save]
238
239\stopenvironment
240