| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2006-2010 Taco Hoekwater <[email protected]> |
| 4 |
|
| 5 |
This file is part of LuaTeX. |
| 6 |
|
| 7 |
LuaTeX is free software; you can redistribute it and/or modify it under the terms |
| 8 |
of the GNU General Public License as published by the Free Software Foundation; |
| 9 |
either version 2 of the License, or (at your option) any later version. |
| 10 |
|
| 11 |
LuaTeX is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 |
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License along with |
| 16 |
LuaTeX; if not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
*/ |
| 19 |
|
| 20 |
/*tex |
| 21 |
|
| 22 |
These are now obsolete because we found otu that no one uses them. A few are used in \CONTEXT\ |
| 23 |
but we can deal with that. Most users moved on to \LUAMETATEX\ where we plenty of ways to |
| 24 |
control the engine. Some code is still present because we need it for legacy progress reports. |
| 25 |
|
| 26 |
\starttyping |
| 27 |
\mathoption |
| 28 |
\mathitalicssmode |
| 29 |
\mathnolimitsmode |
| 30 |
\mathscriptboxmode |
| 31 |
\mathscriptcharmode |
| 32 |
\mathdefaultsmode |
| 33 |
\mathrulethicknessmode |
| 34 |
\mathdelimitersmode |
| 35 |
\stoptyping |
| 36 |
|
| 37 |
Also no longer used are: |
| 38 |
|
| 39 |
\starttyping |
| 40 |
\Umathnolimitsupfactor |
| 41 |
\Umathnolimitsubfactor |
| 42 |
\stoptyping |
| 43 |
|
| 44 |
*/ |
| 45 |
|
| 46 |
/*tex |
| 47 |
|
| 48 |
In traditional \TeX\ the italic correction is added to the width of the |
| 49 |
glyph. This is part of the engine design and related font design. In opentype |
| 50 |
math this is different. There the italic correction had more explicit usage. |
| 51 |
The 1.7 spec says: |
| 52 |
|
| 53 |
\startitemize |
| 54 |
|
| 55 |
\startitem |
| 56 |
{\em italic correction:} When a run of slanted characters is followed by |
| 57 |
a straight character (such as an operator or a delimiter), the italics |
| 58 |
correction of the last glyph is added to its advance width. |
| 59 |
|
| 60 |
When positioning limits on an N-ary operator (e.g., integral sign), the |
| 61 |
horizontal position of the upper limit is moved to the right by ½ of the |
| 62 |
italics correction, while the position of the lower limit is moved to the |
| 63 |
left by the same distance. |
| 64 |
|
| 65 |
When positioning superscripts and subscripts, their default horizontal |
| 66 |
positions are also different by the amount of the italics correction of |
| 67 |
the preceding glyph. |
| 68 |
\stopitem |
| 69 |
|
| 70 |
\startitem |
| 71 |
{\em math kerning:} Set the default horizontal position for the |
| 72 |
superscript as shifted relative to the position of the subscript by the |
| 73 |
italics correction of the base glyph. |
| 74 |
\stopitem |
| 75 |
|
| 76 |
\stopitemize |
| 77 |
|
| 78 |
Before this was specified we had to gamble a bit and assume that cambria was |
| 79 |
the font benchmark and trust our eyes (and msword) for the logic. I must |
| 80 |
admit that I have been fighting these italics in fonts (and the heuristics |
| 81 |
that Lua\TeX\ provided) right from the start (e.g. using Lua based |
| 82 |
postprocessing) but by now we know more and have more fonts to test with. |
| 83 |
More fonts are handy because not all fonts are alike when it comes to |
| 84 |
italics. Axis are another area of concern, as it looks like opentype math |
| 85 |
fonts often already apply that shift. |
| 86 |
|
| 87 |
*/ |
| 88 |
|
| 89 |
/*tex |
| 90 |
|
| 91 |
This is the state per early 2025: |
| 92 |
|
| 93 |
When we started with \OPENTYPE\ math (2005) there was only cambria. The only |
| 94 |
way to test with e.g. Computer Modern was to make a virtual font. One of the |
| 95 |
complications we ran into is italic correction and because the specification |
| 96 |
explicitly binds italic correction to (1) a sequence of text (!) glyphs and |
| 97 |
(2) anchoring limits (as there's only a top anchor and no bttom anchor |
| 98 |
field), we ended up with a split code path. This is also due to the fact that |
| 99 |
when Latin Modern showed up, we wanted to make sure that it rendered okay. |
| 100 |
|
| 101 |
However, when the \TEX\ Gyre fonts were introduced, and other fonts used |
| 102 |
those as template, the heuristics for Latin Modern were sub optimal so we |
| 103 |
introduced ways to control the distance between super and subscript as well |
| 104 |
as limit anchoring for large operators (these cannot really be identified). |
| 105 |
Keep in mind that the italic correction in large operators is not used as |
| 106 |
correction but for anchoring while the \TEX\ machinery always adds italic |
| 107 |
correction to the width and selectively removes it. There is also the fact |
| 108 |
that we don't know to what extend users mix \OPENTYPE\ fonts with traditional |
| 109 |
ones. |
| 110 |
|
| 111 |
In the end we decided to just drop that control, and assume that \OPENTYPE\ |
| 112 |
math fonts are expected to behave like traditional \TEX\ fonts, or: just |
| 113 |
forget about what the specification says about italic correction. As a side |
| 114 |
note: in \CONTEXT\ we already moved on and started treating fonts (in the |
| 115 |
\LUAMETATEX\ default setup) as glyph providers and forget about italic |
| 116 |
correction and the on the average unreliable and often wrong staircase kerns. |
| 117 |
There we take whatever information fits our purpose and assume fonts to be a |
| 118 |
mixed bag. |
| 119 |
|
| 120 |
The result is that math renders similar to traditional (eight bit) rendering |
| 121 |
but that Latin Modern can look kind of bad but as (non \CONTEXT) users are |
| 122 |
accustomed to correcting spacing manually (with |\,| and |\!| etc.) that is |
| 123 |
what is expected. We just fix the fonts runtime. |
| 124 |
|
| 125 |
So, we ditched the control options, went for a hard coded traditional font |
| 126 |
approach and likely will never look back: this is what one gets, |
| 127 |
irrespectable of the specification. A side effect is that in some cases |
| 128 |
\CONTEXT\ users will get worse results but because most already switched to |
| 129 |
\LUAMETATEX\ the impact is not that large. |
| 130 |
|
| 131 |
In 2005 and following years no one could have predicted that the majority of |
| 132 |
math fonts would be designed as traditional \TEX\ fonts and less like the |
| 133 |
reference Cambria font and that anchoring scripts would therefore be italic |
| 134 |
correction driven (also for non italic shapes). So, in retrospect one can |
| 135 |
argue that following the specification was a waste of time although it |
| 136 |
eventually lead to detailed control over these things in the follow up |
| 137 |
engine. However, there we might eventually completely remove all traces of |
| 138 |
italic correction because we don't need it, but that's another story and |
| 139 |
only relevant for \CONTEXT\ \LMTX. |
| 140 |
|
| 141 |
*/ |
| 142 |
|
| 143 |
/*tex |
| 144 |
|
| 145 |
These macros are used to determine if we need to pick up parameters from the |
| 146 |
opentype table or the traditional parameter array. We noticed that some macro |
| 147 |
packages set both tables so we cannot use that for determining if we have a new |
| 148 |
or old font. It's a bit guesswork especially when it comes to italics. |
| 149 |
|
| 150 |
*/ |
| 151 |
|
| 152 |
int permit_math_obsolete = 0; |
| 153 |
|
| 154 |
#define is_new_mathfont(A) ((font_math_params(A) > 0)) |
| 155 |
#define is_old_mathfont(A,B) ((font_math_params(A) == 0) && (font_params(A) >= (B))) |
| 156 |
#define assume_new_math(A) ((font_math_params(A) > 0) && (font_oldmath(A) == 0)) |
| 157 |
|
| 158 |
#include "ptexlib.h" |
| 159 |
#include "lua/luatex-api.h" |
| 160 |
|
| 161 |
#define reset_attributes(p,newatt) do { \ |
| 162 |
delete_attribute_ref(node_attr(p)); \ |
| 163 |
node_attr(p) = newatt; \ |
| 164 |
if (newatt!=null) { \ |
| 165 |
add_node_attr_ref(node_attr(p)); \ |
| 166 |
} \ |
| 167 |
} while (0) |
| 168 |
|
| 169 |
#define DEFINE_MATH_PARAMETERS(A,B,C,D) do { \ |
| 170 |
if (B==text_size) { \ |
| 171 |
def_math_param(A, text_style, (C),D); \ |
| 172 |
def_math_param(A, cramped_text_style, (C),D); \ |
| 173 |
} else if (B==script_size) { \ |
| 174 |
def_math_param(A, script_style, (C),D); \ |
| 175 |
def_math_param(A, cramped_script_style, (C),D); \ |
| 176 |
} else if (B==script_script_size) { \ |
| 177 |
def_math_param(A, script_script_style, (C),D); \ |
| 178 |
def_math_param(A, cramped_script_script_style, (C),D); \ |
| 179 |
} \ |
| 180 |
} while (0) |
| 181 |
|
| 182 |
#define DEFINE_DMATH_PARAMETERS(A,B,C,D) do { \ |
| 183 |
if (B==text_size) { \ |
| 184 |
def_math_param(A, display_style,(C),D); \ |
| 185 |
def_math_param(A, cramped_display_style,(C),D); \ |
| 186 |
} \ |
| 187 |
} while (0) |
| 188 |
|
| 189 |
#define font_MATH_par(a,b) \ |
| 190 |
(font_math_params(a)>=b ? font_math_param(a,b) : undefined_math_parameter) |
| 191 |
|
| 192 |
/*tex |
| 193 |
|
| 194 |
Here are the math parameters that are font-dependant. |
| 195 |
|
| 196 |
Before an mlist is converted to an hlist, \TeX\ makes sure that the fonts in |
| 197 |
family~2 have enough parameters to be math-symbol fonts, and that the fonts |
| 198 |
in family~3 have enough parameters to be math-extension fonts. The |
| 199 |
math-symbol parameters are referred to by using the following macros, which |
| 200 |
take a size code as their parameter; for example, |num1(cur_size)| gives the |
| 201 |
value of the |num1| parameter for the current size. |
| 202 |
|
| 203 |
*/ |
| 204 |
|
| 205 |
#define total_mathsy_params 22 |
| 206 |
#define total_mathex_params 13 |
| 207 |
|
| 208 |
#define mathsy(A,B) font_param(fam_fnt(2,A),B) |
| 209 |
|
| 210 |
/*tex height of `\.x' */ |
| 211 |
|
| 212 |
#define math_x_height(A) mathsy(A,5) |
| 213 |
|
| 214 |
/*tex \.{18mu} */ |
| 215 |
|
| 216 |
#define math_quad(A) mathsy(A,6) |
| 217 |
|
| 218 |
/*tex numerator shift-up in display styles */ |
| 219 |
|
| 220 |
#define num1(A) mathsy(A,8) |
| 221 |
|
| 222 |
/*tex numerator shift-up in non-display, non-\.{\\atop} */ |
| 223 |
|
| 224 |
#define num2(A) mathsy(A,9) |
| 225 |
|
| 226 |
/*tex numerator shift-up in non-display \.{\\atop} */ |
| 227 |
|
| 228 |
#define num3(A) mathsy(A,10) |
| 229 |
|
| 230 |
/*tex denominator shift-down in display styles */ |
| 231 |
|
| 232 |
#define denom1(A) mathsy(A,11) |
| 233 |
|
| 234 |
/*tex denominator shift-down in non-display styles */ |
| 235 |
|
| 236 |
#define denom2(A) mathsy(A,12) |
| 237 |
|
| 238 |
/*tex superscript shift-up in uncramped display style */ |
| 239 |
|
| 240 |
#define sup1(A) mathsy(A,13) |
| 241 |
|
| 242 |
/*tex superscript shift-up in uncramped non-display */ |
| 243 |
|
| 244 |
#define sup2(A) mathsy(A,14) |
| 245 |
|
| 246 |
/*tex superscript shift-up in cramped styles */ |
| 247 |
|
| 248 |
#define sup3(A) mathsy(A,15) |
| 249 |
|
| 250 |
/*tex subscript shift-down if superscript is absent */ |
| 251 |
|
| 252 |
#define sub1(A) mathsy(A,16) |
| 253 |
|
| 254 |
/*tex subscript shift-down if superscript is present */ |
| 255 |
|
| 256 |
#define sub2(A) mathsy(A,17) |
| 257 |
|
| 258 |
/*tex superscript baseline below top of large box */ |
| 259 |
|
| 260 |
#define sup_drop(A) mathsy(A,18) |
| 261 |
|
| 262 |
/*tex subscript baseline below bottom of large box */ |
| 263 |
|
| 264 |
#define sub_drop(A) mathsy(A,19) |
| 265 |
|
| 266 |
/*tex size of \.{\\atopwithdelims} delimiters in display styles */ |
| 267 |
|
| 268 |
#define delim1(A) mathsy(A,20) |
| 269 |
|
| 270 |
/*tex size of \.{\\atopwithdelims} delimiters in non-displays */ |
| 271 |
|
| 272 |
#define delim2(A) mathsy(A,21) |
| 273 |
|
| 274 |
/*tex height of fraction lines above the baseline */ |
| 275 |
|
| 276 |
#define axis_height(A) mathsy(A,22) |
| 277 |
|
| 278 |
/*tex |
| 279 |
|
| 280 |
The math-extension parameters have similar macros, but the size code is |
| 281 |
omitted (since it is always |cur_size| when we refer to such parameters). |
| 282 |
|
| 283 |
*/ |
| 284 |
|
| 285 |
#define mathex(A,B) font_param(fam_fnt(3,A),B) |
| 286 |
|
| 287 |
/*tex thickness of \.{\\over} bars */ |
| 288 |
|
| 289 |
#define default_rule_thickness(A) mathex(A,8) |
| 290 |
|
| 291 |
/*tex minimum clearance above a displayed op */ |
| 292 |
|
| 293 |
#define big_op_spacing1(A) mathex(A,9) |
| 294 |
|
| 295 |
/*tex minimum clearance below a displayed op */ |
| 296 |
|
| 297 |
#define big_op_spacing2(A) mathex(A,10) |
| 298 |
|
| 299 |
/*tex minimum baselineskip above displayed op */ |
| 300 |
|
| 301 |
#define big_op_spacing3(A) mathex(A,11) |
| 302 |
|
| 303 |
/*tex minimum baselineskip below displayed op */ |
| 304 |
|
| 305 |
#define big_op_spacing4(A) mathex(A,12) |
| 306 |
|
| 307 |
/*tex padding above and below displayed limits */ |
| 308 |
|
| 309 |
#define big_op_spacing5(A) mathex(A,13) |
| 310 |
|
| 311 |
/*tex |
| 312 |
|
| 313 |
\LUATEX makes a bunch of extensions cf. the |MATH| table in \OPENTYPE, but |
| 314 |
some of the |MathConstants| values have no matching usage in \LUATEX\ right |
| 315 |
now. |
| 316 |
|
| 317 |
\startitemize |
| 318 |
|
| 319 |
\startitem |
| 320 |
|ScriptPercentScaleDown| |ScriptScriptPercentScaleDown|: These should |
| 321 |
be handled by the macro package, on the engine side there are three |
| 322 |
separate fonts. |
| 323 |
\stopitem |
| 324 |
|
| 325 |
\startitem |
| 326 |
|DelimitedSubFormulaMinHeight|: This is perhaps related to word's |
| 327 |
natural math input? We have no idea what to do about it. |
| 328 |
\stopitem |
| 329 |
|
| 330 |
\startitem |
| 331 |
|MathLeading|: \LUATEX does not currently handle multi-line displays, |
| 332 |
and the parameter does not seem to make much sense elsewhere. |
| 333 |
\stopitem |
| 334 |
|
| 335 |
\startitem |
| 336 |
|FlattenedAccentBaseHeight|: This is based on the |flac| |GSUB| |
| 337 |
feature. It would not be hard to support that, but proper math accent |
| 338 |
placements cf.\ |MATH| needs support for |MathTopAccentAttachment| |
| 339 |
table to be implemented first. |
| 340 |
\stopitem |
| 341 |
|
| 342 |
\stopitemize |
| 343 |
|
| 344 |
*/ |
| 345 |
|
| 346 |
static void math_param_error(const char *param, int style) |
| 347 |
{ |
| 348 |
char s[256]; |
| 349 |
const char *hlp[] = { |
| 350 |
"Sorry, but I can't typeset math unless various parameters have", |
| 351 |
"been set. This is normally done by loading special math fonts", |
| 352 |
"into the math family slots. Your font set is lacking at least", |
| 353 |
"the parameter mentioned earlier.", |
| 354 |
NULL |
| 355 |
}; |
| 356 |
snprintf(s, 256, "Math error: parameter \\Umath%s\\%sstyle is not set", param, math_style_names[style]); |
| 357 |
tex_error(s, hlp); |
| 358 |
return; |
| 359 |
} |
| 360 |
|
| 361 |
static scaled accent_base_height(int f) |
| 362 |
{ |
| 363 |
scaled a; |
| 364 |
if (assume_new_math(f)) { |
| 365 |
a = font_MATH_par(f, AccentBaseHeight); |
| 366 |
if (a == undefined_math_parameter) |
| 367 |
a = x_height(f); |
| 368 |
} else { |
| 369 |
a = x_height(f); |
| 370 |
} |
| 371 |
return a; |
| 372 |
} |
| 373 |
|
| 374 |
/*tex |
| 375 |
|
| 376 |
The non-staticness of this function is for the benefit of |texmath.w|. |
| 377 |
Watch out, this one uses the style! The style and size numbers don't |
| 378 |
match because we have cramped styles. |
| 379 |
|
| 380 |
*/ |
| 381 |
|
| 382 |
scaled get_math_quad_style(int var) |
| 383 |
{ |
| 384 |
scaled a = get_math_param(math_param_quad, var); |
| 385 |
if (a == undefined_math_parameter) { |
| 386 |
math_param_error("quad", var); |
| 387 |
return 0; |
| 388 |
} else { |
| 389 |
return a; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
/*tex |
| 394 |
|
| 395 |
For this reason the next one is different because it is called with a size |
| 396 |
specifier instead of a style specifier. |
| 397 |
|
| 398 |
*/ |
| 399 |
|
| 400 |
static scaled math_axis_size(int b) |
| 401 |
{ |
| 402 |
scaled a; |
| 403 |
int var; |
| 404 |
if (b == script_size) |
| 405 |
var = script_style; |
| 406 |
else if (b == script_script_size) |
| 407 |
var = script_script_style; |
| 408 |
else |
| 409 |
var = text_style; |
| 410 |
a = get_math_param(math_param_axis, var); |
| 411 |
if (a == undefined_math_parameter) { |
| 412 |
math_param_error("axis", var); |
| 413 |
return 0; |
| 414 |
} else { |
| 415 |
return a; |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
scaled get_math_quad_size(int b) |
| 420 |
{ |
| 421 |
int var; |
| 422 |
if (b == script_size) |
| 423 |
var = script_style; |
| 424 |
else if (b == script_script_size) |
| 425 |
var = script_script_style; |
| 426 |
else |
| 427 |
var = text_style; |
| 428 |
return get_math_param(math_param_quad, var); |
| 429 |
} |
| 430 |
|
| 431 |
static scaled minimum_operator_size(int var) |
| 432 |
{ |
| 433 |
scaled a = get_math_param(math_param_operator_size, var); |
| 434 |
return a; |
| 435 |
} |
| 436 |
|
| 437 |
/*tex |
| 438 |
|
| 439 |
Old-style fonts do not define the |radical_rule|. This allows |make_radical| |
| 440 |
to select the backward compatibility code, and it means that we can't raise |
| 441 |
an error here. |
| 442 |
|
| 443 |
*/ |
| 444 |
|
| 445 |
static scaled radical_rule_par(int var) |
| 446 |
{ |
| 447 |
scaled a = get_math_param(math_param_radical_rule, var); |
| 448 |
return a; |
| 449 |
} |
| 450 |
|
| 451 |
/*tex |
| 452 |
|
| 453 |
Now follow all the trivial math parameters. |
| 454 |
|
| 455 |
*/ |
| 456 |
|
| 457 |
#define get_math_param_or_error(a,b) do_get_math_param_or_error(a, math_param_##b, #b) |
| 458 |
#define get_math_param_or_zero(a,b) do_get_math_param_or_zero(a, math_param_##b, #b) |
| 459 |
|
| 460 |
static scaled do_get_math_param_or_error(int var, int param, const char *name) |
| 461 |
{ |
| 462 |
scaled a = get_math_param(param, var); |
| 463 |
if (a == undefined_math_parameter) { |
| 464 |
math_param_error(name, var); |
| 465 |
a = 0; |
| 466 |
} |
| 467 |
return a; |
| 468 |
} |
| 469 |
|
| 470 |
// static scaled do_get_math_param_or_zero(int var, int param, const char *name) |
| 471 |
// { |
| 472 |
// scaled a = get_math_param(param, var); |
| 473 |
// if (a == undefined_math_parameter) { |
| 474 |
// a = 0; |
| 475 |
// } |
| 476 |
// return a; |
| 477 |
// } |
| 478 |
|
| 479 |
/*tex |
| 480 |
|
| 481 |
A variant on a suggestion on the list based on analysis by UV. |
| 482 |
|
| 483 |
*/ |
| 484 |
|
| 485 |
static scaled get_delimiter_height(scaled max_d, scaled max_h, boolean axis) { |
| 486 |
scaled delta, delta1, delta2; |
| 487 |
if (axis) { |
| 488 |
delta2 = max_d + math_axis_size(cur_size); |
| 489 |
} else { |
| 490 |
delta2 = max_d; |
| 491 |
} |
| 492 |
delta1 = max_h + max_d - delta2; |
| 493 |
if (delta2 > delta1) { |
| 494 |
/*tex |delta1| is max distance from axis */ |
| 495 |
delta1 = delta2; |
| 496 |
} |
| 497 |
delta = (delta1 / 500) * delimiter_factor_par; |
| 498 |
delta2 = delta1 + delta1 - delimiter_shortfall_par; |
| 499 |
if (delta < delta2) { |
| 500 |
return delta2; |
| 501 |
} else { |
| 502 |
return delta; |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
#define radical_degree_before(a) get_math_param_or_error(a, radical_degree_before) |
| 507 |
#define radical_degree_after(a) get_math_param_or_error(a, radical_degree_after) |
| 508 |
#define radical_degree_raise(a) get_math_param_or_error(a, radical_degree_raise) |
| 509 |
|
| 510 |
#define connector_overlap_min(a) get_math_param_or_error(a, connector_overlap_min) |
| 511 |
|
| 512 |
#define overbar_rule(a) get_math_param_or_error(a, overbar_rule) |
| 513 |
#define overbar_kern(a) get_math_param_or_error(a, overbar_kern) |
| 514 |
#define overbar_vgap(a) get_math_param_or_error(a, overbar_vgap) |
| 515 |
|
| 516 |
#define underbar_rule(a) get_math_param_or_error(a, underbar_rule) |
| 517 |
#define underbar_kern(a) get_math_param_or_error(a, underbar_kern) |
| 518 |
#define underbar_vgap(a) get_math_param_or_error(a, underbar_vgap) |
| 519 |
|
| 520 |
#define under_delimiter_vgap(a) get_math_param_or_error(a, under_delimiter_vgap) |
| 521 |
#define under_delimiter_bgap(a) get_math_param_or_error(a, under_delimiter_bgap) |
| 522 |
|
| 523 |
#define over_delimiter_vgap(a) get_math_param_or_error(a, over_delimiter_vgap) |
| 524 |
#define over_delimiter_bgap(a) get_math_param_or_error(a, over_delimiter_bgap) |
| 525 |
|
| 526 |
#define radical_vgap(a) get_math_param_or_error(a, radical_vgap) |
| 527 |
#define radical_kern(a) get_math_param_or_error(a, radical_kern) |
| 528 |
|
| 529 |
#define stack_vgap(a) get_math_param_or_error(a, stack_vgap) |
| 530 |
#define stack_num_up(a) get_math_param_or_error(a, stack_num_up) |
| 531 |
#define stack_denom_down(a) get_math_param_or_error(a, stack_denom_down) |
| 532 |
|
| 533 |
#define fraction_rule(a) get_math_param_or_error(a, fraction_rule) |
| 534 |
#define fraction_num_vgap(a) get_math_param_or_error(a, fraction_num_vgap) |
| 535 |
#define fraction_denom_vgap(a) get_math_param_or_error(a, fraction_denom_vgap) |
| 536 |
#define fraction_num_up(a) get_math_param_or_error(a, fraction_num_up) |
| 537 |
#define fraction_denom_down(a) get_math_param_or_error(a, fraction_denom_down) |
| 538 |
#define fraction_del_size_new(a) get_math_param_or_error(a, fraction_del_size) |
| 539 |
/* fraction_del_size_old(a) get_math_param (a, math_param_fraction_del_size) */ |
| 540 |
#define fraction_del_size_old(a) get_math_param_or_error(a, fraction_del_size) |
| 541 |
|
| 542 |
#define skewed_fraction_hgap(a) get_math_param_or_error(a, skewed_fraction_hgap) |
| 543 |
#define skewed_fraction_vgap(a) get_math_param_or_error(a, skewed_fraction_vgap) |
| 544 |
|
| 545 |
#define limit_above_vgap(a) get_math_param_or_error(a, limit_above_vgap) |
| 546 |
#define limit_above_bgap(a) get_math_param_or_error(a, limit_above_bgap) |
| 547 |
#define limit_above_kern(a) get_math_param_or_error(a, limit_above_kern) |
| 548 |
|
| 549 |
#define limit_below_vgap(a) get_math_param_or_error(a, limit_below_vgap) |
| 550 |
#define limit_below_bgap(a) get_math_param_or_error(a, limit_below_bgap) |
| 551 |
#define limit_below_kern(a) get_math_param_or_error(a, limit_below_kern) |
| 552 |
|
| 553 |
#define nolimit_sub_factor(a) get_math_param_or_zero(a, nolimit_sub_factor) |
| 554 |
#define nolimit_sup_factor(a) get_math_param_or_zero(a, nolimit_sup_factor) |
| 555 |
|
| 556 |
#define sub_shift_drop(a) get_math_param_or_error(a, sub_shift_drop) |
| 557 |
#define sup_shift_drop(a) get_math_param_or_error(a, sup_shift_drop) |
| 558 |
#define sub_shift_down(a) get_math_param_or_error(a, sub_shift_down) |
| 559 |
#define sub_sup_shift_down(a) get_math_param_or_error(a, sub_sup_shift_down) |
| 560 |
#define sup_shift_up(a) get_math_param_or_error(a, sup_shift_up) |
| 561 |
#define sub_top_max(a) get_math_param_or_error(a, sub_top_max) |
| 562 |
#define sup_bottom_min(a) get_math_param_or_error(a, sup_bottom_min) |
| 563 |
#define sup_sub_bottom_max(a) get_math_param_or_error(a, sup_sub_bottom_max) |
| 564 |
#define subsup_vgap(a) get_math_param_or_error(a, subsup_vgap) |
| 565 |
|
| 566 |
#define space_after_script(a) get_math_param_or_error(a, space_after_script) |
| 567 |
|
| 568 |
void fixup_math_parameters(int fam_id, int size_id, int f, int lvl) |
| 569 |
{ |
| 570 |
if (is_new_mathfont(f)) { |
| 571 |
|
| 572 |
/*tex Fix all known parameters. */ |
| 573 |
|
| 574 |
DEFINE_MATH_PARAMETERS(math_param_quad, size_id, |
| 575 |
font_size(f), lvl); |
| 576 |
DEFINE_DMATH_PARAMETERS(math_param_quad, size_id, |
| 577 |
font_size(f), lvl); |
| 578 |
DEFINE_MATH_PARAMETERS(math_param_axis, size_id, |
| 579 |
font_MATH_par(f, AxisHeight), lvl); |
| 580 |
DEFINE_DMATH_PARAMETERS(math_param_axis, size_id, |
| 581 |
font_MATH_par(f, AxisHeight), lvl); |
| 582 |
DEFINE_MATH_PARAMETERS(math_param_overbar_kern, size_id, |
| 583 |
font_MATH_par(f, OverbarExtraAscender), lvl); |
| 584 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_kern, size_id, |
| 585 |
font_MATH_par(f, OverbarExtraAscender), lvl); |
| 586 |
DEFINE_MATH_PARAMETERS(math_param_overbar_rule, size_id, |
| 587 |
font_MATH_par(f, OverbarRuleThickness), lvl); |
| 588 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_rule, size_id, |
| 589 |
font_MATH_par(f, OverbarRuleThickness), lvl); |
| 590 |
DEFINE_MATH_PARAMETERS(math_param_overbar_vgap, size_id, |
| 591 |
font_MATH_par(f, OverbarVerticalGap), lvl); |
| 592 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_vgap, size_id, |
| 593 |
font_MATH_par(f, OverbarVerticalGap), lvl); |
| 594 |
DEFINE_MATH_PARAMETERS(math_param_underbar_kern, size_id, |
| 595 |
font_MATH_par(f, UnderbarExtraDescender), lvl); |
| 596 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_kern, size_id, |
| 597 |
font_MATH_par(f, UnderbarExtraDescender), lvl); |
| 598 |
DEFINE_MATH_PARAMETERS(math_param_underbar_rule, size_id, |
| 599 |
font_MATH_par(f, UnderbarRuleThickness), lvl); |
| 600 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_rule, size_id, |
| 601 |
font_MATH_par(f, UnderbarRuleThickness), lvl); |
| 602 |
DEFINE_MATH_PARAMETERS(math_param_underbar_vgap, size_id, |
| 603 |
font_MATH_par(f, UnderbarVerticalGap), lvl); |
| 604 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_vgap, size_id, |
| 605 |
font_MATH_par(f, UnderbarVerticalGap), lvl); |
| 606 |
|
| 607 |
DEFINE_MATH_PARAMETERS(math_param_under_delimiter_vgap, size_id, |
| 608 |
font_MATH_par(f, StretchStackGapAboveMin), lvl); |
| 609 |
DEFINE_DMATH_PARAMETERS(math_param_under_delimiter_vgap, size_id, |
| 610 |
font_MATH_par(f, StretchStackGapAboveMin), lvl); |
| 611 |
DEFINE_MATH_PARAMETERS(math_param_under_delimiter_bgap, size_id, |
| 612 |
font_MATH_par(f, StretchStackBottomShiftDown), lvl); |
| 613 |
DEFINE_DMATH_PARAMETERS(math_param_under_delimiter_bgap, size_id, |
| 614 |
font_MATH_par(f, StretchStackBottomShiftDown), lvl); |
| 615 |
|
| 616 |
DEFINE_MATH_PARAMETERS(math_param_over_delimiter_vgap, size_id, |
| 617 |
font_MATH_par(f, StretchStackGapBelowMin), lvl); |
| 618 |
DEFINE_DMATH_PARAMETERS(math_param_over_delimiter_vgap, size_id, |
| 619 |
font_MATH_par(f, StretchStackGapBelowMin), lvl); |
| 620 |
DEFINE_MATH_PARAMETERS(math_param_over_delimiter_bgap, size_id, |
| 621 |
font_MATH_par(f, StretchStackTopShiftUp), lvl); |
| 622 |
DEFINE_DMATH_PARAMETERS(math_param_over_delimiter_bgap, size_id, |
| 623 |
font_MATH_par(f, StretchStackTopShiftUp), lvl); |
| 624 |
|
| 625 |
DEFINE_MATH_PARAMETERS(math_param_stack_num_up, size_id, |
| 626 |
font_MATH_par(f, StackTopShiftUp), lvl); |
| 627 |
DEFINE_DMATH_PARAMETERS(math_param_stack_num_up, size_id, |
| 628 |
font_MATH_par(f, StackTopDisplayStyleShiftUp), lvl); |
| 629 |
DEFINE_MATH_PARAMETERS(math_param_stack_denom_down, size_id, |
| 630 |
font_MATH_par(f, StackBottomShiftDown), lvl); |
| 631 |
DEFINE_DMATH_PARAMETERS(math_param_stack_denom_down, size_id, |
| 632 |
font_MATH_par(f, StackBottomDisplayStyleShiftDown), lvl); |
| 633 |
DEFINE_MATH_PARAMETERS(math_param_stack_vgap, size_id, |
| 634 |
font_MATH_par(f, StackGapMin), lvl); |
| 635 |
DEFINE_DMATH_PARAMETERS(math_param_stack_vgap, size_id, |
| 636 |
font_MATH_par(f, StackDisplayStyleGapMin), lvl); |
| 637 |
|
| 638 |
DEFINE_MATH_PARAMETERS(math_param_radical_kern, size_id, |
| 639 |
font_MATH_par(f, RadicalExtraAscender), lvl); |
| 640 |
DEFINE_DMATH_PARAMETERS(math_param_radical_kern, size_id, |
| 641 |
font_MATH_par(f, RadicalExtraAscender), lvl); |
| 642 |
|
| 643 |
DEFINE_DMATH_PARAMETERS(math_param_operator_size, size_id, |
| 644 |
font_MATH_par(f, DisplayOperatorMinHeight), lvl); |
| 645 |
|
| 646 |
DEFINE_MATH_PARAMETERS(math_param_radical_rule, size_id, |
| 647 |
font_MATH_par(f, RadicalRuleThickness), lvl); |
| 648 |
DEFINE_DMATH_PARAMETERS(math_param_radical_rule, size_id, |
| 649 |
font_MATH_par(f, RadicalRuleThickness), lvl); |
| 650 |
DEFINE_MATH_PARAMETERS(math_param_radical_vgap, size_id, |
| 651 |
font_MATH_par(f, RadicalVerticalGap), lvl); |
| 652 |
DEFINE_DMATH_PARAMETERS(math_param_radical_vgap, size_id, |
| 653 |
font_MATH_par(f, RadicalDisplayStyleVerticalGap), lvl); |
| 654 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_before, size_id, |
| 655 |
font_MATH_par(f, RadicalKernBeforeDegree), lvl); |
| 656 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_before, size_id, |
| 657 |
font_MATH_par(f, RadicalKernBeforeDegree), lvl); |
| 658 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_after, size_id, |
| 659 |
font_MATH_par(f, RadicalKernAfterDegree), lvl); |
| 660 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_after, size_id, |
| 661 |
font_MATH_par(f, RadicalKernAfterDegree), lvl); |
| 662 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_raise, size_id, |
| 663 |
font_MATH_par(f, RadicalDegreeBottomRaisePercent), lvl); |
| 664 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_raise, size_id, |
| 665 |
font_MATH_par(f, RadicalDegreeBottomRaisePercent), lvl); |
| 666 |
|
| 667 |
if (size_id == text_size) { |
| 668 |
def_math_param(math_param_sup_shift_up, display_style, |
| 669 |
font_MATH_par(f, SuperscriptShiftUp), lvl); |
| 670 |
def_math_param(math_param_sup_shift_up, cramped_display_style, |
| 671 |
font_MATH_par(f, SuperscriptShiftUpCramped), lvl); |
| 672 |
def_math_param(math_param_sup_shift_up, text_style, |
| 673 |
font_MATH_par(f, SuperscriptShiftUp), lvl); |
| 674 |
def_math_param(math_param_sup_shift_up, cramped_text_style, |
| 675 |
font_MATH_par(f, SuperscriptShiftUpCramped), lvl); |
| 676 |
} else if (size_id == script_size) { |
| 677 |
def_math_param(math_param_sup_shift_up, script_style, |
| 678 |
font_MATH_par(f, SuperscriptShiftUp), lvl); |
| 679 |
def_math_param(math_param_sup_shift_up, cramped_script_style, |
| 680 |
font_MATH_par(f, SuperscriptShiftUpCramped), lvl); |
| 681 |
} else if (size_id == script_script_size) { |
| 682 |
def_math_param(math_param_sup_shift_up, script_script_style, |
| 683 |
font_MATH_par(f, SuperscriptShiftUp), lvl); |
| 684 |
def_math_param(math_param_sup_shift_up, cramped_script_script_style, |
| 685 |
font_MATH_par(f, SuperscriptShiftUpCramped), lvl); |
| 686 |
} |
| 687 |
|
| 688 |
DEFINE_MATH_PARAMETERS(math_param_sub_shift_drop, size_id, |
| 689 |
font_MATH_par(f, SubscriptBaselineDropMin), lvl); |
| 690 |
DEFINE_DMATH_PARAMETERS(math_param_sub_shift_drop, size_id, |
| 691 |
font_MATH_par(f, SubscriptBaselineDropMin), lvl); |
| 692 |
DEFINE_MATH_PARAMETERS(math_param_sup_shift_drop, size_id, |
| 693 |
font_MATH_par(f, SuperscriptBaselineDropMax), lvl); |
| 694 |
DEFINE_DMATH_PARAMETERS(math_param_sup_shift_drop, size_id, |
| 695 |
font_MATH_par(f, SuperscriptBaselineDropMax), lvl); |
| 696 |
DEFINE_MATH_PARAMETERS(math_param_sub_shift_down, size_id, |
| 697 |
font_MATH_par(f, SubscriptShiftDown), lvl); |
| 698 |
DEFINE_DMATH_PARAMETERS(math_param_sub_shift_down, size_id, |
| 699 |
font_MATH_par(f, SubscriptShiftDown), lvl); |
| 700 |
|
| 701 |
if (font_MATH_par(f, SubscriptShiftDownWithSuperscript) != undefined_math_parameter) { |
| 702 |
DEFINE_MATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 703 |
font_MATH_par(f, SubscriptShiftDownWithSuperscript), lvl); |
| 704 |
DEFINE_DMATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 705 |
font_MATH_par(f, SubscriptShiftDownWithSuperscript), lvl); |
| 706 |
} else { |
| 707 |
DEFINE_MATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 708 |
font_MATH_par(f, SubscriptShiftDown), lvl); |
| 709 |
DEFINE_DMATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 710 |
font_MATH_par(f, SubscriptShiftDown), lvl); |
| 711 |
} |
| 712 |
|
| 713 |
DEFINE_MATH_PARAMETERS(math_param_sub_top_max, size_id, |
| 714 |
font_MATH_par(f, SubscriptTopMax), lvl); |
| 715 |
DEFINE_DMATH_PARAMETERS(math_param_sub_top_max, size_id, |
| 716 |
font_MATH_par(f, SubscriptTopMax), lvl); |
| 717 |
DEFINE_MATH_PARAMETERS(math_param_sup_bottom_min, size_id, |
| 718 |
font_MATH_par(f, SuperscriptBottomMin), lvl); |
| 719 |
DEFINE_DMATH_PARAMETERS(math_param_sup_bottom_min, size_id, |
| 720 |
font_MATH_par(f, SuperscriptBottomMin), lvl); |
| 721 |
DEFINE_MATH_PARAMETERS(math_param_sup_sub_bottom_max, size_id, |
| 722 |
font_MATH_par(f, SuperscriptBottomMaxWithSubscript), lvl); |
| 723 |
DEFINE_DMATH_PARAMETERS(math_param_sup_sub_bottom_max, size_id, |
| 724 |
font_MATH_par(f, SuperscriptBottomMaxWithSubscript), lvl); |
| 725 |
DEFINE_MATH_PARAMETERS(math_param_subsup_vgap, size_id, |
| 726 |
font_MATH_par(f, SubSuperscriptGapMin), lvl); |
| 727 |
DEFINE_DMATH_PARAMETERS(math_param_subsup_vgap, size_id, |
| 728 |
font_MATH_par(f, SubSuperscriptGapMin), lvl); |
| 729 |
|
| 730 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_vgap, size_id, |
| 731 |
font_MATH_par(f, UpperLimitGapMin), lvl); |
| 732 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_vgap, size_id, |
| 733 |
font_MATH_par(f, UpperLimitGapMin), lvl); |
| 734 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_bgap, size_id, |
| 735 |
font_MATH_par(f, UpperLimitBaselineRiseMin), lvl); |
| 736 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_bgap, size_id, |
| 737 |
font_MATH_par(f, UpperLimitBaselineRiseMin), lvl); |
| 738 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_kern, size_id, |
| 739 |
0, lvl); |
| 740 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_kern, size_id, |
| 741 |
0, lvl); |
| 742 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_vgap, size_id, |
| 743 |
font_MATH_par(f, LowerLimitGapMin), lvl); |
| 744 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_vgap, size_id, |
| 745 |
font_MATH_par(f, LowerLimitGapMin), lvl); |
| 746 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_bgap, size_id, |
| 747 |
font_MATH_par(f, LowerLimitBaselineDropMin), lvl); |
| 748 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_bgap, size_id, |
| 749 |
font_MATH_par(f, LowerLimitBaselineDropMin), lvl); |
| 750 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_kern, size_id, |
| 751 |
0, lvl); |
| 752 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_kern, size_id, |
| 753 |
0, lvl); |
| 754 |
DEFINE_MATH_PARAMETERS(math_param_nolimit_sub_factor, size_id, |
| 755 |
font_MATH_par(f, NoLimitSubFactor), lvl); /* bonus */ |
| 756 |
DEFINE_DMATH_PARAMETERS(math_param_nolimit_sub_factor, size_id, |
| 757 |
font_MATH_par(f, NoLimitSubFactor), lvl); /* bonus */ |
| 758 |
DEFINE_MATH_PARAMETERS(math_param_nolimit_sup_factor, size_id, |
| 759 |
font_MATH_par(f, NoLimitSupFactor), lvl); /* bonus */ |
| 760 |
DEFINE_DMATH_PARAMETERS(math_param_nolimit_sup_factor, size_id, |
| 761 |
font_MATH_par(f, NoLimitSupFactor), lvl); /* bonus */ |
| 762 |
|
| 763 |
DEFINE_MATH_PARAMETERS(math_param_fraction_rule, size_id, |
| 764 |
font_MATH_par(f, FractionRuleThickness), lvl); |
| 765 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_rule, size_id, |
| 766 |
font_MATH_par(f, FractionRuleThickness), lvl); |
| 767 |
DEFINE_MATH_PARAMETERS(math_param_fraction_num_vgap, size_id, |
| 768 |
font_MATH_par(f, FractionNumeratorGapMin), lvl); |
| 769 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_num_vgap, size_id, |
| 770 |
font_MATH_par(f, FractionNumeratorDisplayStyleGapMin), lvl); |
| 771 |
DEFINE_MATH_PARAMETERS(math_param_fraction_num_up, size_id, |
| 772 |
font_MATH_par(f, FractionNumeratorShiftUp), lvl); |
| 773 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_num_up, size_id, |
| 774 |
font_MATH_par(f, FractionNumeratorDisplayStyleShiftUp), lvl); |
| 775 |
DEFINE_MATH_PARAMETERS(math_param_fraction_denom_vgap, size_id, |
| 776 |
font_MATH_par(f, FractionDenominatorGapMin), lvl); |
| 777 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_denom_vgap, size_id, |
| 778 |
font_MATH_par(f,FractionDenominatorDisplayStyleGapMin), lvl); |
| 779 |
DEFINE_MATH_PARAMETERS(math_param_fraction_denom_down, size_id, |
| 780 |
font_MATH_par(f, FractionDenominatorShiftDown), lvl); |
| 781 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_denom_down, size_id, |
| 782 |
font_MATH_par(f, FractionDenominatorDisplayStyleShiftDown), lvl); |
| 783 |
|
| 784 |
DEFINE_MATH_PARAMETERS(math_param_fraction_del_size, size_id, |
| 785 |
font_MATH_par(f, FractionDelimiterSize), lvl); |
| 786 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_del_size, size_id, |
| 787 |
font_MATH_par(f, FractionDelimiterDisplayStyleSize), lvl); |
| 788 |
|
| 789 |
DEFINE_MATH_PARAMETERS(math_param_skewed_fraction_hgap, size_id, |
| 790 |
font_MATH_par(f, SkewedFractionHorizontalGap), lvl); |
| 791 |
DEFINE_DMATH_PARAMETERS(math_param_skewed_fraction_hgap, size_id, |
| 792 |
font_MATH_par(f, SkewedFractionHorizontalGap), lvl); |
| 793 |
DEFINE_MATH_PARAMETERS(math_param_skewed_fraction_vgap, size_id, |
| 794 |
font_MATH_par(f, SkewedFractionVerticalGap), lvl); |
| 795 |
DEFINE_DMATH_PARAMETERS(math_param_skewed_fraction_vgap, size_id, |
| 796 |
font_MATH_par(f, SkewedFractionVerticalGap), lvl); |
| 797 |
|
| 798 |
DEFINE_MATH_PARAMETERS(math_param_space_after_script, size_id, |
| 799 |
font_MATH_par(f, SpaceAfterScript), lvl); |
| 800 |
DEFINE_DMATH_PARAMETERS(math_param_space_after_script, size_id, |
| 801 |
font_MATH_par(f, SpaceAfterScript), lvl); |
| 802 |
|
| 803 |
DEFINE_MATH_PARAMETERS(math_param_connector_overlap_min, size_id, |
| 804 |
font_MATH_par(f, MinConnectorOverlap), lvl); |
| 805 |
DEFINE_DMATH_PARAMETERS(math_param_connector_overlap_min, size_id, |
| 806 |
font_MATH_par(f, MinConnectorOverlap), lvl); |
| 807 |
|
| 808 |
} else if (fam_id == 2 && is_old_mathfont(f, total_mathsy_params)) { |
| 809 |
|
| 810 |
/*tex Fix old-style |sy| parameters. */ |
| 811 |
|
| 812 |
DEFINE_MATH_PARAMETERS(math_param_quad, size_id, |
| 813 |
math_quad(size_id), lvl); |
| 814 |
DEFINE_DMATH_PARAMETERS(math_param_quad, size_id, |
| 815 |
math_quad(size_id), lvl); |
| 816 |
DEFINE_MATH_PARAMETERS(math_param_axis, size_id, |
| 817 |
axis_height(size_id), lvl); |
| 818 |
DEFINE_DMATH_PARAMETERS(math_param_axis, size_id, |
| 819 |
axis_height(size_id), lvl); |
| 820 |
DEFINE_MATH_PARAMETERS(math_param_stack_num_up, size_id, |
| 821 |
num3(size_id), lvl); |
| 822 |
DEFINE_DMATH_PARAMETERS(math_param_stack_num_up, size_id, |
| 823 |
num1(size_id), lvl); |
| 824 |
DEFINE_MATH_PARAMETERS(math_param_stack_denom_down, size_id, |
| 825 |
denom2(size_id), lvl); |
| 826 |
DEFINE_DMATH_PARAMETERS(math_param_stack_denom_down, size_id, |
| 827 |
denom1(size_id), lvl); |
| 828 |
DEFINE_MATH_PARAMETERS(math_param_fraction_num_up, size_id, |
| 829 |
num2(size_id), lvl); |
| 830 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_num_up, size_id, |
| 831 |
num1(size_id), lvl); |
| 832 |
DEFINE_MATH_PARAMETERS(math_param_fraction_denom_down, size_id, |
| 833 |
denom2(size_id), lvl); |
| 834 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_denom_down, size_id, |
| 835 |
denom1(size_id), lvl); |
| 836 |
DEFINE_MATH_PARAMETERS(math_param_fraction_del_size, size_id, |
| 837 |
delim2(size_id), lvl); |
| 838 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_del_size, size_id, |
| 839 |
delim1(size_id), lvl); |
| 840 |
|
| 841 |
DEFINE_MATH_PARAMETERS(math_param_skewed_fraction_hgap, size_id, |
| 842 |
0, lvl); |
| 843 |
DEFINE_DMATH_PARAMETERS(math_param_skewed_fraction_hgap, size_id, |
| 844 |
0, lvl); |
| 845 |
DEFINE_MATH_PARAMETERS(math_param_skewed_fraction_vgap, size_id, |
| 846 |
0, lvl); |
| 847 |
DEFINE_DMATH_PARAMETERS(math_param_skewed_fraction_vgap, size_id, |
| 848 |
0, lvl); |
| 849 |
|
| 850 |
if (size_id == text_size) { |
| 851 |
def_math_param(math_param_sup_shift_up, display_style, |
| 852 |
sup1(size_id), lvl); |
| 853 |
def_math_param(math_param_sup_shift_up, cramped_display_style, |
| 854 |
sup3(size_id), lvl); |
| 855 |
def_math_param(math_param_sup_shift_up, text_style, |
| 856 |
sup2(size_id), lvl); |
| 857 |
def_math_param(math_param_sup_shift_up, cramped_text_style, |
| 858 |
sup3(size_id), lvl); |
| 859 |
} else if (size_id == script_size) { |
| 860 |
def_math_param(math_param_sub_shift_drop, display_style, |
| 861 |
sub_drop(size_id), lvl); |
| 862 |
def_math_param(math_param_sub_shift_drop, cramped_display_style, |
| 863 |
sub_drop(size_id), lvl); |
| 864 |
def_math_param(math_param_sub_shift_drop, text_style, |
| 865 |
sub_drop(size_id), lvl); |
| 866 |
def_math_param(math_param_sub_shift_drop, cramped_text_style, |
| 867 |
sub_drop(size_id), lvl); |
| 868 |
def_math_param(math_param_sup_shift_drop, display_style, |
| 869 |
sup_drop(size_id), lvl); |
| 870 |
def_math_param(math_param_sup_shift_drop, cramped_display_style, |
| 871 |
sup_drop(size_id), lvl); |
| 872 |
def_math_param(math_param_sup_shift_drop, text_style, |
| 873 |
sup_drop(size_id), lvl); |
| 874 |
def_math_param(math_param_sup_shift_drop, cramped_text_style, |
| 875 |
sup_drop(size_id), lvl); |
| 876 |
def_math_param(math_param_sup_shift_up, script_style, |
| 877 |
sup2(size_id), lvl); |
| 878 |
def_math_param(math_param_sup_shift_up, cramped_script_style, |
| 879 |
sup3(size_id), lvl); |
| 880 |
} else if (size_id == script_script_size) { |
| 881 |
def_math_param(math_param_sub_shift_drop, script_style, |
| 882 |
sub_drop(size_id), lvl); |
| 883 |
def_math_param(math_param_sub_shift_drop, cramped_script_style, |
| 884 |
sub_drop(size_id), lvl); |
| 885 |
def_math_param(math_param_sub_shift_drop, script_script_style, |
| 886 |
sub_drop(size_id), lvl); |
| 887 |
def_math_param(math_param_sub_shift_drop, |
| 888 |
cramped_script_script_style, sub_drop(size_id), lvl); |
| 889 |
def_math_param(math_param_sup_shift_drop, script_style, |
| 890 |
sup_drop(size_id), lvl); |
| 891 |
def_math_param(math_param_sup_shift_drop, cramped_script_style, |
| 892 |
sup_drop(size_id), lvl); |
| 893 |
def_math_param(math_param_sup_shift_drop, script_script_style, |
| 894 |
sup_drop(size_id), lvl); |
| 895 |
def_math_param(math_param_sup_shift_drop, |
| 896 |
cramped_script_script_style, sup_drop(size_id), lvl); |
| 897 |
def_math_param(math_param_sup_shift_up, script_script_style, |
| 898 |
sup2(size_id), lvl); |
| 899 |
def_math_param(math_param_sup_shift_up, cramped_script_script_style, |
| 900 |
sup3(size_id), lvl); |
| 901 |
} |
| 902 |
|
| 903 |
DEFINE_MATH_PARAMETERS(math_param_sub_shift_down, size_id, |
| 904 |
sub1(size_id), lvl); |
| 905 |
DEFINE_DMATH_PARAMETERS(math_param_sub_shift_down, size_id, |
| 906 |
sub1(size_id), lvl); |
| 907 |
DEFINE_MATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 908 |
sub2(size_id), lvl); |
| 909 |
DEFINE_DMATH_PARAMETERS(math_param_sub_sup_shift_down, size_id, |
| 910 |
sub2(size_id), lvl); |
| 911 |
DEFINE_MATH_PARAMETERS(math_param_sub_top_max, size_id, |
| 912 |
(abs(math_x_height(size_id) * 4) / 5), lvl); |
| 913 |
DEFINE_DMATH_PARAMETERS(math_param_sub_top_max, size_id, |
| 914 |
(abs(math_x_height(size_id) * 4) / 5), lvl); |
| 915 |
DEFINE_MATH_PARAMETERS(math_param_sup_bottom_min, size_id, |
| 916 |
(abs(math_x_height(size_id)) / 4), lvl); |
| 917 |
DEFINE_DMATH_PARAMETERS(math_param_sup_bottom_min, size_id, |
| 918 |
(abs(math_x_height(size_id)) / 4), lvl); |
| 919 |
DEFINE_MATH_PARAMETERS(math_param_sup_sub_bottom_max, size_id, |
| 920 |
(abs(math_x_height(size_id) * 4) / 5), lvl); |
| 921 |
DEFINE_DMATH_PARAMETERS(math_param_sup_sub_bottom_max, size_id, |
| 922 |
(abs(math_x_height(size_id) * 4) / 5), lvl); |
| 923 |
|
| 924 |
/*tex |
| 925 |
|
| 926 |
The display-size |radical_vgap| is done twice because it needs values |
| 927 |
from both the sy and the ex font. |
| 928 |
|
| 929 |
*/ |
| 930 |
|
| 931 |
DEFINE_DMATH_PARAMETERS(math_param_radical_vgap, size_id, |
| 932 |
(default_rule_thickness(size_id) + (abs(math_x_height(size_id)) / 4)), lvl); |
| 933 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_raise, size_id, |
| 934 |
60, lvl); |
| 935 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_raise, size_id, |
| 936 |
60, lvl); |
| 937 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_before, size_id, |
| 938 |
xn_over_d(get_math_quad_size(size_id), 5, 18), lvl); |
| 939 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_before, size_id, |
| 940 |
xn_over_d(get_math_quad_size(size_id), 5, 18), lvl); |
| 941 |
DEFINE_MATH_PARAMETERS(math_param_radical_degree_after, size_id, |
| 942 |
(-xn_over_d (get_math_quad_size(size_id), 10, 18)), lvl); |
| 943 |
DEFINE_DMATH_PARAMETERS(math_param_radical_degree_after, size_id, |
| 944 |
(-xn_over_d (get_math_quad_size(size_id), 10, 18)), lvl); |
| 945 |
|
| 946 |
} else if (fam_id == 3 && is_old_mathfont(f, total_mathex_params)) { |
| 947 |
|
| 948 |
/*tex Fix old-style |ex| parameters. */ |
| 949 |
|
| 950 |
DEFINE_MATH_PARAMETERS(math_param_overbar_kern, size_id, |
| 951 |
default_rule_thickness(size_id), lvl); |
| 952 |
DEFINE_MATH_PARAMETERS(math_param_overbar_rule, size_id, |
| 953 |
default_rule_thickness(size_id), lvl); |
| 954 |
DEFINE_MATH_PARAMETERS(math_param_overbar_vgap, size_id, |
| 955 |
3 * default_rule_thickness(size_id), lvl); |
| 956 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_kern, size_id, |
| 957 |
default_rule_thickness(size_id), lvl); |
| 958 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_rule, size_id, |
| 959 |
default_rule_thickness(size_id), lvl); |
| 960 |
DEFINE_DMATH_PARAMETERS(math_param_overbar_vgap, size_id, |
| 961 |
3 * default_rule_thickness(size_id), lvl); |
| 962 |
DEFINE_MATH_PARAMETERS(math_param_underbar_kern, size_id, |
| 963 |
default_rule_thickness(size_id), lvl); |
| 964 |
DEFINE_MATH_PARAMETERS(math_param_underbar_rule, size_id, |
| 965 |
default_rule_thickness(size_id), lvl); |
| 966 |
DEFINE_MATH_PARAMETERS(math_param_underbar_vgap, size_id, |
| 967 |
3 * default_rule_thickness(size_id), lvl); |
| 968 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_kern, size_id, |
| 969 |
default_rule_thickness(size_id), lvl); |
| 970 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_rule, size_id, |
| 971 |
default_rule_thickness(size_id), lvl); |
| 972 |
DEFINE_DMATH_PARAMETERS(math_param_underbar_vgap, size_id, |
| 973 |
3 * default_rule_thickness(size_id), lvl); |
| 974 |
DEFINE_MATH_PARAMETERS(math_param_radical_kern, size_id, |
| 975 |
default_rule_thickness(size_id), lvl); |
| 976 |
DEFINE_DMATH_PARAMETERS(math_param_radical_kern, size_id, |
| 977 |
default_rule_thickness(size_id), lvl); |
| 978 |
DEFINE_MATH_PARAMETERS(math_param_radical_vgap, size_id, |
| 979 |
(default_rule_thickness(size_id) + (abs(default_rule_thickness(size_id)) / 4)), lvl); |
| 980 |
DEFINE_MATH_PARAMETERS(math_param_stack_vgap, size_id, |
| 981 |
3 * default_rule_thickness(size_id), lvl); |
| 982 |
DEFINE_DMATH_PARAMETERS(math_param_stack_vgap, size_id, |
| 983 |
7 * default_rule_thickness(size_id), lvl); |
| 984 |
DEFINE_MATH_PARAMETERS(math_param_fraction_rule, size_id, |
| 985 |
default_rule_thickness(size_id), lvl); |
| 986 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_rule, size_id, |
| 987 |
default_rule_thickness(size_id), lvl); |
| 988 |
DEFINE_MATH_PARAMETERS(math_param_fraction_num_vgap, size_id, |
| 989 |
default_rule_thickness(size_id), lvl); |
| 990 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_num_vgap, size_id, |
| 991 |
3 * default_rule_thickness(size_id), lvl); |
| 992 |
DEFINE_MATH_PARAMETERS(math_param_fraction_denom_vgap, size_id, |
| 993 |
default_rule_thickness(size_id), lvl); |
| 994 |
DEFINE_DMATH_PARAMETERS(math_param_fraction_denom_vgap, size_id, |
| 995 |
3 * default_rule_thickness(size_id), lvl); |
| 996 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_vgap, size_id, |
| 997 |
big_op_spacing1(size_id), lvl); |
| 998 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_vgap, size_id, |
| 999 |
big_op_spacing1(size_id), lvl); |
| 1000 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_bgap, size_id, |
| 1001 |
big_op_spacing3(size_id), lvl); |
| 1002 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_bgap, size_id, |
| 1003 |
big_op_spacing3(size_id), lvl); |
| 1004 |
DEFINE_MATH_PARAMETERS(math_param_limit_above_kern, size_id, |
| 1005 |
big_op_spacing5(size_id), lvl); |
| 1006 |
DEFINE_DMATH_PARAMETERS(math_param_limit_above_kern, size_id, |
| 1007 |
big_op_spacing5(size_id), lvl); |
| 1008 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_vgap, size_id, |
| 1009 |
big_op_spacing2(size_id), lvl); |
| 1010 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_vgap, size_id, |
| 1011 |
big_op_spacing2(size_id), lvl); |
| 1012 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_bgap, size_id, |
| 1013 |
big_op_spacing4(size_id), lvl); |
| 1014 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_bgap, size_id, |
| 1015 |
big_op_spacing4(size_id), lvl); |
| 1016 |
DEFINE_MATH_PARAMETERS(math_param_limit_below_kern, size_id, |
| 1017 |
big_op_spacing5(size_id), lvl); |
| 1018 |
DEFINE_DMATH_PARAMETERS(math_param_limit_below_kern, size_id, |
| 1019 |
big_op_spacing5(size_id), lvl); |
| 1020 |
DEFINE_MATH_PARAMETERS(math_param_nolimit_sub_factor, size_id, |
| 1021 |
font_MATH_par(f, NoLimitSubFactor), lvl); /* bonus */ |
| 1022 |
DEFINE_DMATH_PARAMETERS(math_param_nolimit_sub_factor, size_id, |
| 1023 |
font_MATH_par(f, NoLimitSubFactor), lvl); /* bonus */ |
| 1024 |
DEFINE_MATH_PARAMETERS(math_param_nolimit_sup_factor, size_id, |
| 1025 |
font_MATH_par(f, NoLimitSupFactor), lvl); /* bonus */ |
| 1026 |
DEFINE_DMATH_PARAMETERS(math_param_nolimit_sup_factor, size_id, |
| 1027 |
font_MATH_par(f, NoLimitSupFactor), lvl); /* bonus */ |
| 1028 |
DEFINE_MATH_PARAMETERS(math_param_subsup_vgap, size_id, |
| 1029 |
4 * default_rule_thickness(size_id), lvl); |
| 1030 |
DEFINE_DMATH_PARAMETERS(math_param_subsup_vgap, size_id, |
| 1031 |
4 * default_rule_thickness(size_id), lvl); |
| 1032 |
|
| 1033 |
/*tex |
| 1034 |
|
| 1035 |
All of the |space_after_script|s are done in |
| 1036 |
|finalize_math_parameters| because the \.{\\scriptspace} may have |
| 1037 |
been altered by the user. |
| 1038 |
|
| 1039 |
*/ |
| 1040 |
|
| 1041 |
DEFINE_MATH_PARAMETERS(math_param_connector_overlap_min, size_id, |
| 1042 |
0, lvl); |
| 1043 |
DEFINE_DMATH_PARAMETERS(math_param_connector_overlap_min, size_id, |
| 1044 |
0, lvl); |
| 1045 |
|
| 1046 |
DEFINE_MATH_PARAMETERS(math_param_under_delimiter_vgap, size_id, |
| 1047 |
big_op_spacing2(size_id), lvl); |
| 1048 |
DEFINE_DMATH_PARAMETERS(math_param_under_delimiter_vgap, size_id, |
| 1049 |
big_op_spacing2(size_id), lvl); |
| 1050 |
DEFINE_MATH_PARAMETERS(math_param_under_delimiter_bgap, size_id, |
| 1051 |
big_op_spacing4(size_id), lvl); |
| 1052 |
DEFINE_DMATH_PARAMETERS(math_param_under_delimiter_bgap, size_id, |
| 1053 |
big_op_spacing4(size_id), lvl); |
| 1054 |
DEFINE_MATH_PARAMETERS(math_param_over_delimiter_vgap, size_id, |
| 1055 |
big_op_spacing1(size_id), lvl); |
| 1056 |
DEFINE_DMATH_PARAMETERS(math_param_over_delimiter_vgap, size_id, |
| 1057 |
big_op_spacing1(size_id), lvl); |
| 1058 |
DEFINE_MATH_PARAMETERS(math_param_over_delimiter_bgap, size_id, |
| 1059 |
big_op_spacing3(size_id), lvl); |
| 1060 |
DEFINE_DMATH_PARAMETERS(math_param_over_delimiter_bgap, size_id, |
| 1061 |
big_op_spacing3(size_id), lvl); |
| 1062 |
|
| 1063 |
/*tex |
| 1064 |
|
| 1065 |
The display-size |radical_vgap| is done twice because it needs values |
| 1066 |
from both the sy and the ex font. |
| 1067 |
|
| 1068 |
*/ |
| 1069 |
|
| 1070 |
DEFINE_DMATH_PARAMETERS(math_param_radical_vgap, size_id, |
| 1071 |
(default_rule_thickness(size_id) + (abs(math_x_height(size_id)) / 4)), lvl); |
| 1072 |
|
| 1073 |
} |
| 1074 |
} |
| 1075 |
|
| 1076 |
/*tex |
| 1077 |
|
| 1078 |
This needs to be called just at the start of |mlist_to_hlist|, for backward |
| 1079 |
compatibility with \.{\\scriptspace}. |
| 1080 |
|
| 1081 |
*/ |
| 1082 |
|
| 1083 |
static void finalize_math_parameters(void) |
| 1084 |
{ |
| 1085 |
int saved_trace = tracing_assigns_par; |
| 1086 |
tracing_assigns_par = 0; |
| 1087 |
if (get_math_param(math_param_space_after_script, display_style) == undefined_math_parameter) { |
| 1088 |
def_math_param(math_param_space_after_script, display_style, |
| 1089 |
script_space_par, level_one); |
| 1090 |
def_math_param(math_param_space_after_script, text_style, |
| 1091 |
script_space_par, level_one); |
| 1092 |
def_math_param(math_param_space_after_script, script_style, |
| 1093 |
script_space_par, level_one); |
| 1094 |
def_math_param(math_param_space_after_script, script_script_style, |
| 1095 |
script_space_par, level_one); |
| 1096 |
def_math_param(math_param_space_after_script, cramped_display_style, |
| 1097 |
script_space_par, level_one); |
| 1098 |
def_math_param(math_param_space_after_script, cramped_text_style, |
| 1099 |
script_space_par, level_one); |
| 1100 |
def_math_param(math_param_space_after_script, cramped_script_style, |
| 1101 |
script_space_par, level_one); |
| 1102 |
def_math_param(math_param_space_after_script, cramped_script_script_style, |
| 1103 |
script_space_par, level_one); |
| 1104 |
} |
| 1105 |
tracing_assigns_par = saved_trace; |
| 1106 |
} |
| 1107 |
|
| 1108 |
/*tex |
| 1109 |
|
| 1110 |
In order to convert mlists to hlists, i.e., noads to nodes, we need several |
| 1111 |
subroutines that are conveniently dealt with now. |
| 1112 |
|
| 1113 |
Let us first introduce the macros that make it easy to get at the parameters |
| 1114 |
and other font information. A size code, which is a multiple of 256, is added |
| 1115 |
to a family number to get an index into the table of internal font numbers |
| 1116 |
for each combination of family and size. (Be alert: Size codes get larger as |
| 1117 |
the type gets smaller.) |
| 1118 |
|
| 1119 |
*/ |
| 1120 |
|
| 1121 |
static const char *math_size_string(int s) |
| 1122 |
{ |
| 1123 |
if (s == text_size) |
| 1124 |
return "textfont"; |
| 1125 |
else if (s == script_size) |
| 1126 |
return "scriptfont"; |
| 1127 |
else |
| 1128 |
return "scriptscriptfont"; |
| 1129 |
} |
| 1130 |
|
| 1131 |
/*tex |
| 1132 |
|
| 1133 |
When the style changes, the following piece of program computes associated |
| 1134 |
information: |
| 1135 |
|
| 1136 |
*/ |
| 1137 |
|
| 1138 |
#define setup_cur_size(a) do { \ |
| 1139 |
if (a==script_style || a==cramped_script_style) \ |
| 1140 |
cur_size = script_size; \ |
| 1141 |
else if (a==script_script_style || a==cramped_script_script_style) \ |
| 1142 |
cur_size = script_script_size; \ |
| 1143 |
else \ |
| 1144 |
cur_size = text_size; \ |
| 1145 |
} while (0) |
| 1146 |
|
| 1147 |
|
| 1148 |
/*tex |
| 1149 |
|
| 1150 |
A simple routine that creates a flat copy of a nucleus. |
| 1151 |
|
| 1152 |
*/ |
| 1153 |
|
| 1154 |
static pointer math_clone(pointer q) |
| 1155 |
{ |
| 1156 |
pointer x; |
| 1157 |
if (q == null) |
| 1158 |
return null; |
| 1159 |
x = new_node(type(q), 0); |
| 1160 |
reset_attributes(x, node_attr(q)); |
| 1161 |
if (type(q) == math_char_node) { |
| 1162 |
math_fam(x) = math_fam(q); |
| 1163 |
math_character(x) = math_character(q); |
| 1164 |
} else { |
| 1165 |
math_list(x) = math_list(q); |
| 1166 |
} |
| 1167 |
return x; |
| 1168 |
} |
| 1169 |
|
| 1170 |
/*tex |
| 1171 |
|
| 1172 |
Here is a function that returns a pointer to a rule node having a given |
| 1173 |
thickness |t|. The rule will extend horizontally to the boundary of the vlist |
| 1174 |
that eventually contains it. |
| 1175 |
|
| 1176 |
*/ |
| 1177 |
|
| 1178 |
static pointer do_fraction_rule(scaled t, pointer att, halfword some_rule, halfword cur_size, halfword cur_fam) |
| 1179 |
{ |
| 1180 |
pointer p; |
| 1181 |
if (math_rules_mode_par) { |
| 1182 |
p = new_rule(some_rule); |
| 1183 |
rule_math_size(p) = cur_size; |
| 1184 |
rule_math_font(p) = fam_fnt(cur_fam, cur_size); |
| 1185 |
} else { |
| 1186 |
p = new_rule(normal_rule); |
| 1187 |
} |
| 1188 |
rule_dir(p) = math_direction_par; |
| 1189 |
height(p) = t; |
| 1190 |
depth(p) = 0; |
| 1191 |
reset_attributes(p, att); |
| 1192 |
return p; |
| 1193 |
} |
| 1194 |
|
| 1195 |
/*tex |
| 1196 |
|
| 1197 |
The |overbar| function returns a pointer to a vlist box that consists of a |
| 1198 |
given box |b|, above which has been placed a kern of height |k| under a |
| 1199 |
fraction rule of thickness |t| under additional space of height |ht|. |
| 1200 |
|
| 1201 |
*/ |
| 1202 |
|
| 1203 |
static pointer overbar(pointer b, scaled k, scaled t, scaled ht, pointer att, halfword index, halfword cur_size, halfword cur_fam) |
| 1204 |
{ |
| 1205 |
pointer p, q; |
| 1206 |
p = new_kern(k); |
| 1207 |
reset_attributes(p, att); |
| 1208 |
couple_nodes(p,b); |
| 1209 |
q = do_fraction_rule(t, att, index, cur_size, cur_fam); |
| 1210 |
couple_nodes(q,p); |
| 1211 |
p = new_kern(ht); |
| 1212 |
reset_attributes(p, att); |
| 1213 |
couple_nodes(p,q); |
| 1214 |
q = vpackage(p, 0, additional, max_dimen, math_direction_par); |
| 1215 |
reset_attributes(q, att); |
| 1216 |
return q; |
| 1217 |
} |
| 1218 |
|
| 1219 |
/*tex |
| 1220 |
|
| 1221 |
Here is a subroutine that creates a new box, whose list contains a single |
| 1222 |
character, and whose width includes the italic correction for that character. |
| 1223 |
The height or depth of the box will be negative, if the height or depth of |
| 1224 |
the character is negative; thus, this routine may deliver a slightly |
| 1225 |
different result than |hpack| would produce. |
| 1226 |
|
| 1227 |
*/ |
| 1228 |
|
| 1229 |
static pointer char_box(internal_font_number f, int c, pointer bb) |
| 1230 |
{ |
| 1231 |
/*tex The new box and its character node. */ |
| 1232 |
pointer b, p; |
| 1233 |
b = new_null_box(); |
| 1234 |
width(b) = char_width(f, c) + char_italic(f, c); |
| 1235 |
height(b) = char_height(f, c); |
| 1236 |
depth(b) = char_depth(f, c); |
| 1237 |
subtype(b) = math_char_list ; |
| 1238 |
reset_attributes(b, bb); |
| 1239 |
p = new_glyph(f, c); |
| 1240 |
protect_glyph_node(p); |
| 1241 |
reset_attributes(p, bb); |
| 1242 |
list_ptr(b) = p; |
| 1243 |
return b; |
| 1244 |
} |
| 1245 |
|
| 1246 |
/*tex |
| 1247 |
|
| 1248 |
Another handy subroutine computes the height plus depth of a given character: |
| 1249 |
|
| 1250 |
*/ |
| 1251 |
|
| 1252 |
static scaled height_plus_depth(internal_font_number f, int c) |
| 1253 |
{ |
| 1254 |
return (char_height(f, c) + char_depth(f, c)); |
| 1255 |
} |
| 1256 |
|
| 1257 |
/*tex |
| 1258 |
|
| 1259 |
When we build an extensible character, it's handy to have the following |
| 1260 |
subroutine, which puts a given character on top of the characters already in |
| 1261 |
box |b|: |
| 1262 |
|
| 1263 |
*/ |
| 1264 |
|
| 1265 |
static scaled stack_into_box(pointer b, internal_font_number f, int c) |
| 1266 |
{ |
| 1267 |
/*tex New node placed into |b|: */ |
| 1268 |
pointer p, q; |
| 1269 |
/*tex Italic gets added to width. */ |
| 1270 |
p = char_box(f, c, node_attr(b)); |
| 1271 |
if (type(b) == vlist_node) { |
| 1272 |
try_couple_nodes(p,list_ptr(b)); |
| 1273 |
list_ptr(b) = p; |
| 1274 |
height(b) = height(p); |
| 1275 |
if (width(b) < width(p)) |
| 1276 |
width(b) = width(p); |
| 1277 |
return height_plus_depth(f, c); |
| 1278 |
} else { |
| 1279 |
q = list_ptr(b); |
| 1280 |
if (q == null) { |
| 1281 |
list_ptr(b) = p; |
| 1282 |
} else { |
| 1283 |
while (vlink(q) != null) |
| 1284 |
q = vlink(q); |
| 1285 |
couple_nodes(q,p); |
| 1286 |
} |
| 1287 |
if (height(b) < height(p)) |
| 1288 |
height(b) = height(p); |
| 1289 |
if (depth(b) < depth(p)) |
| 1290 |
depth(b) = depth(p); |
| 1291 |
return char_width(f, c); |
| 1292 |
} |
| 1293 |
} |
| 1294 |
|
| 1295 |
static void stack_glue_into_box(pointer b, scaled min, scaled max) { |
| 1296 |
halfword p = new_glue(zero_glue); |
| 1297 |
width(p) = min; |
| 1298 |
stretch(p) = max - min; |
| 1299 |
if (node_attr(b) != null) { |
| 1300 |
reset_attributes(p, node_attr(b)); |
| 1301 |
} |
| 1302 |
if (type(b) == vlist_node) { |
| 1303 |
try_couple_nodes(p,list_ptr(b)); |
| 1304 |
list_ptr(b) = p; |
| 1305 |
} else { |
| 1306 |
halfword q = list_ptr(b); |
| 1307 |
if (q == null) { |
| 1308 |
list_ptr(b) = p; |
| 1309 |
} else { |
| 1310 |
while (vlink(q) != null) { |
| 1311 |
q = vlink(q); |
| 1312 |
} |
| 1313 |
couple_nodes(q,p); |
| 1314 |
} |
| 1315 |
} |
| 1316 |
} |
| 1317 |
|
| 1318 |
/*tex |
| 1319 |
|
| 1320 |
\TeX's most important routine for dealing with formulas is called |
| 1321 |
|mlist_to_hlist|. After a formula has been scanned and represented as an |
| 1322 |
mlist, this routine converts it to an hlist that can be placed into a box or |
| 1323 |
incorporated into the text of a paragraph. The explicit parameter |cur_mlist| |
| 1324 |
points to the first node or noad in the given mlist (and it might be |null|); |
| 1325 |
the parameter |penalties| is |true| if penalty nodes for potential line |
| 1326 |
breaks are to be inserted into the resulting hlist, the parameter |cur_style| |
| 1327 |
is a style code. After |mlist_to_hlist| has acted, |vlink(temp_head)| points |
| 1328 |
to the translated hlist. |
| 1329 |
|
| 1330 |
Since mlists can be inside mlists, the procedure is recursive. And since this |
| 1331 |
is not part of \TeX's inner loop, the program has been written in a manner |
| 1332 |
that stresses compactness over efficiency. |
| 1333 |
|
| 1334 |
*/ |
| 1335 |
|
| 1336 |
/*tex Size code corresponding to |cur_style|: */ |
| 1337 |
|
| 1338 |
int cur_size = 0; |
| 1339 |
|
| 1340 |
static pointer get_delim_box(internal_font_number fnt, halfword chr, scaled v, scaled min_overlap, int horizontal, halfword att) |
| 1341 |
{ |
| 1342 |
int callback_id = callback_defined(make_extensible_callback); |
| 1343 |
if (callback_id > 0) { |
| 1344 |
/*tex |
| 1345 |
This call is not optimized as it hardly makes sense to use it ... special |
| 1346 |
and a it of feature creep too. |
| 1347 |
*/ |
| 1348 |
halfword b = null; |
| 1349 |
run_callback(callback_id, "ddddbN->N",fnt,chr,v,min_overlap,horizontal,att,&b); |
| 1350 |
if (b == null) { |
| 1351 |
/*tex |
| 1352 |
We see this as a signal to do it the \TEX\ way. |
| 1353 |
*/ |
| 1354 |
} else if (type(b) == hlist_node || type(b) == vlist_node) { |
| 1355 |
return b; |
| 1356 |
} else { |
| 1357 |
formatted_error("fonts","invalid extensible character %i created for font %i, [h|v]list expected",chr,fnt); |
| 1358 |
} |
| 1359 |
} |
| 1360 |
return make_extensible(fnt, chr, v, min_overlap, horizontal, att); |
| 1361 |
} |
| 1362 |
|
| 1363 |
pointer make_extensible(internal_font_number fnt, halfword chr, scaled v, scaled min_overlap, int horizontal, halfword att) |
| 1364 |
{ |
| 1365 |
/*tex new box */ |
| 1366 |
pointer b; |
| 1367 |
/*tex natural (maximum) size of the stack */ |
| 1368 |
scaled b_max; |
| 1369 |
/*tex amount of possible shrink in the stack */ |
| 1370 |
scaled s_max; |
| 1371 |
extinfo *cur; |
| 1372 |
extinfo *ext; |
| 1373 |
scaled prev_overlap; |
| 1374 |
/*tex a temporary counter number of extensible pieces */ |
| 1375 |
int i; |
| 1376 |
/*tex number of times to repeat each repeatable item in |ext| */ |
| 1377 |
int with_extenders; |
| 1378 |
int num_extenders, num_normal; |
| 1379 |
scaled a, c, d; |
| 1380 |
b = new_null_box(); |
| 1381 |
with_extenders = -1; |
| 1382 |
num_extenders = 0; |
| 1383 |
num_normal = 0; |
| 1384 |
if (min_overlap < 0) { |
| 1385 |
min_overlap = 0; |
| 1386 |
} |
| 1387 |
if (horizontal) { |
| 1388 |
type(b) = (quarterword) hlist_node; |
| 1389 |
ext = get_charinfo_hor_variants(char_info(fnt,chr)); |
| 1390 |
} else { |
| 1391 |
type(b) = (quarterword) vlist_node; |
| 1392 |
ext = get_charinfo_vert_variants(char_info(fnt,chr)); |
| 1393 |
} |
| 1394 |
if (att != null) { |
| 1395 |
reset_attributes(b,att); |
| 1396 |
} |
| 1397 |
cur = ext; |
| 1398 |
while (cur != NULL) { |
| 1399 |
if (!char_exists(fnt, cur->glyph)) { |
| 1400 |
const char *hlp[] = { |
| 1401 |
"Each glyph part in an extensible item should exist in the font.", |
| 1402 |
"I will give up trying to find a suitable size for now. Fix your font!", |
| 1403 |
NULL |
| 1404 |
}; |
| 1405 |
tex_error("Variant part doesn't exist.", hlp); |
| 1406 |
width(b) = null_delimiter_space_par; |
| 1407 |
return b; |
| 1408 |
} |
| 1409 |
if (cur->extender > 0) |
| 1410 |
num_extenders++; |
| 1411 |
else |
| 1412 |
num_normal++; |
| 1413 |
/*tex No negative overlaps or advances are allowed. */ |
| 1414 |
if (cur->start_overlap < 0 || cur->end_overlap < 0 || cur->advance < 0) { |
| 1415 |
const char *hlp[] = { |
| 1416 |
"All measurements in extensible items should be positive.", |
| 1417 |
"To get around this problem, I have changed the font metrics.", |
| 1418 |
"Fix your font!", |
| 1419 |
NULL |
| 1420 |
}; |
| 1421 |
tex_error("Extensible recipe has negative fields.", hlp); |
| 1422 |
if (cur->start_overlap < 0) |
| 1423 |
cur->start_overlap = 0; |
| 1424 |
if (cur->end_overlap < 0) |
| 1425 |
cur->end_overlap = 0; |
| 1426 |
if (cur->advance < 0) |
| 1427 |
cur->advance = 0; |
| 1428 |
} |
| 1429 |
cur = cur->next; |
| 1430 |
} |
| 1431 |
if (num_normal == 0) { |
| 1432 |
const char *hlp[] = { |
| 1433 |
"Each extensible recipe should have at least one non-repeatable part.", |
| 1434 |
"To get around this problem, I have changed the first part to be", |
| 1435 |
"non-repeatable. Fix your font!", |
| 1436 |
NULL |
| 1437 |
}; |
| 1438 |
tex_error("Extensible recipe has no fixed parts.", hlp); |
| 1439 |
ext->extender = 0; |
| 1440 |
num_normal = 1; |
| 1441 |
num_extenders--; |
| 1442 |
} |
| 1443 |
/*tex |
| 1444 |
|
| 1445 |
|ext| holds a linked list of numerous items that may or may not be |
| 1446 |
repeatable. For the total height, we have to figure out how many items |
| 1447 |
are needed to create a stack of at least |v|. |
| 1448 |
|
| 1449 |
The next |while| loop does that. It has two goals: it finds out the |
| 1450 |
natural height |b_max| of the all the parts needed to reach at least |v|, |
| 1451 |
and it sets |with_extenders| to the number of times each of the |
| 1452 |
repeatable items in |ext| has to be repeated to reach that height. |
| 1453 |
|
| 1454 |
*/ |
| 1455 |
cur = ext; |
| 1456 |
b_max = 0; |
| 1457 |
while (b_max < v && num_extenders > 0) { |
| 1458 |
b_max = 0; |
| 1459 |
prev_overlap = 0; |
| 1460 |
with_extenders++; |
| 1461 |
for (cur = ext; cur != NULL; cur = cur->next) { |
| 1462 |
if (cur->extender == 0) { |
| 1463 |
c = cur->start_overlap; |
| 1464 |
if (min_overlap < c) |
| 1465 |
c = min_overlap; |
| 1466 |
if (prev_overlap < c) |
| 1467 |
c = prev_overlap; |
| 1468 |
a = cur->advance; |
| 1469 |
if (a == 0) { |
| 1470 |
/*tex for tfm fonts */ |
| 1471 |
if (horizontal) { |
| 1472 |
a = char_width(fnt, cur->glyph); |
| 1473 |
} else { |
| 1474 |
a = height_plus_depth(fnt, cur->glyph); |
| 1475 |
} |
| 1476 |
if (a < 0) { |
| 1477 |
formatted_error("fonts","bad extensible character %i in font %i",chr,fnt); |
| 1478 |
} |
| 1479 |
} |
| 1480 |
b_max += a - c; |
| 1481 |
prev_overlap = cur->end_overlap; |
| 1482 |
} else { |
| 1483 |
i = with_extenders; |
| 1484 |
while (i > 0) { |
| 1485 |
c = cur->start_overlap; |
| 1486 |
if (min_overlap < c) |
| 1487 |
c = min_overlap; |
| 1488 |
if (prev_overlap < c) |
| 1489 |
c = prev_overlap; |
| 1490 |
a = cur->advance; |
| 1491 |
if (a == 0) { |
| 1492 |
/*tex for tfm fonts */ |
| 1493 |
if (horizontal) { |
| 1494 |
a = char_width(fnt, cur->glyph); |
| 1495 |
} else { |
| 1496 |
a = height_plus_depth(fnt, cur->glyph); |
| 1497 |
} |
| 1498 |
if (a < 0) { |
| 1499 |
formatted_error("fonts","bad extensible character %i in font %i",chr,fnt); |
| 1500 |
} |
| 1501 |
} |
| 1502 |
b_max += a - c; |
| 1503 |
prev_overlap = cur->end_overlap; |
| 1504 |
i--; |
| 1505 |
} |
| 1506 |
} |
| 1507 |
} |
| 1508 |
} |
| 1509 |
/*tex |
| 1510 |
|
| 1511 |
Assemble box using |with_extenders| copies of each extender, with |
| 1512 |
appropriate glue wherever an overlap occurs. |
| 1513 |
|
| 1514 |
*/ |
| 1515 |
prev_overlap = 0; |
| 1516 |
b_max = 0; |
| 1517 |
s_max = 0; |
| 1518 |
for (cur = ext; cur != NULL; cur = cur->next) { |
| 1519 |
if (cur->extender == 0) { |
| 1520 |
c = cur->start_overlap; |
| 1521 |
if (prev_overlap < c) |
| 1522 |
c = prev_overlap; |
| 1523 |
d = c; |
| 1524 |
if (min_overlap < c) |
| 1525 |
c = min_overlap; |
| 1526 |
if (d > 0) { |
| 1527 |
stack_glue_into_box(b, -d, -c); |
| 1528 |
s_max += (-c) - (-d); |
| 1529 |
b_max -= d; |
| 1530 |
} |
| 1531 |
b_max += stack_into_box(b, fnt, cur->glyph); |
| 1532 |
prev_overlap = cur->end_overlap; |
| 1533 |
i--; |
| 1534 |
} else { |
| 1535 |
i = with_extenders; |
| 1536 |
while (i > 0) { |
| 1537 |
c = cur->start_overlap; |
| 1538 |
if (prev_overlap < c) |
| 1539 |
c = prev_overlap; |
| 1540 |
d = c; |
| 1541 |
if (min_overlap < c) |
| 1542 |
c = min_overlap; |
| 1543 |
if (d > 0) { |
| 1544 |
stack_glue_into_box(b, -d, -c); |
| 1545 |
s_max += (-c) - (-d); |
| 1546 |
b_max -= d; |
| 1547 |
} |
| 1548 |
b_max += stack_into_box(b, fnt, cur->glyph); |
| 1549 |
prev_overlap = cur->end_overlap; |
| 1550 |
i--; |
| 1551 |
} |
| 1552 |
} |
| 1553 |
} |
| 1554 |
/*tex Set glue so as to stretch the connections if needed. */ |
| 1555 |
d = 0; |
| 1556 |
if (v > b_max && s_max > 0) { |
| 1557 |
d = v-b_max; |
| 1558 |
/*tex Don't stretch more than |s_max|. */ |
| 1559 |
if (d > s_max) |
| 1560 |
d = s_max; |
| 1561 |
glue_order(b) = normal; |
| 1562 |
glue_sign(b) = stretching; |
| 1563 |
glue_set(b) = unfloat(d/(float) s_max); |
| 1564 |
b_max += d; |
| 1565 |
} |
| 1566 |
if (horizontal) { |
| 1567 |
width(b) = b_max; |
| 1568 |
subtype(b) = math_h_extensible_list; |
| 1569 |
} else { |
| 1570 |
height(b) = b_max; |
| 1571 |
subtype(b) = math_v_extensible_list; |
| 1572 |
} |
| 1573 |
return b; |
| 1574 |
} |
| 1575 |
|
| 1576 |
/*tex |
| 1577 |
|
| 1578 |
The |var_delimiter| function, which finds or constructs a sufficiently large |
| 1579 |
delimiter, is the most interesting of the auxiliary functions that currently |
| 1580 |
concern us. Given a pointer |d| to a delimiter field in some noad, together |
| 1581 |
with a size code |s| and a vertical distance |v|, this function returns a |
| 1582 |
pointer to a box that contains the smallest variant of |d| whose height plus |
| 1583 |
depth is |v| or more. (And if no variant is large enough, it returns the |
| 1584 |
largest available variant.) In particular, this routine will construct |
| 1585 |
arbitrarily large delimiters from extensible components, if |d| leads to such |
| 1586 |
characters. |
| 1587 |
|
| 1588 |
The value returned is a box whose |shift_amount| has been set so that the box |
| 1589 |
is vertically centered with respect to the axis in the given size. If a |
| 1590 |
built-up symbol is returned, the height of the box before shifting will be |
| 1591 |
the height of its topmost component. |
| 1592 |
|
| 1593 |
*/ |
| 1594 |
|
| 1595 |
static void endless_loop_error(internal_font_number g, int y) |
| 1596 |
{ |
| 1597 |
char s[256]; |
| 1598 |
const char *hlp[] = { |
| 1599 |
"You managed to create a seemingly endless charlist chain in the current", |
| 1600 |
"font. I have counted until 10000 already and still have not escaped, so" |
| 1601 |
"I will jump out of the loop all by myself now. Fix your font!", |
| 1602 |
NULL |
| 1603 |
}; |
| 1604 |
snprintf(s, 256, "Math error: endless loop in charlist (U+%04x in %s)", (int) y, font_name(g)); |
| 1605 |
tex_error(s, hlp); |
| 1606 |
} |
| 1607 |
|
| 1608 |
static pointer do_delimiter(pointer q, pointer d, int s, scaled v, boolean flat, int cur_style, boolean shift, boolean *stack, scaled *delta, int *same) |
| 1609 |
{ |
| 1610 |
/*tex the box that will be constructed */ |
| 1611 |
pointer b; |
| 1612 |
/*tex best-so-far and tentative font codes */ |
| 1613 |
internal_font_number f, g; |
| 1614 |
/*tex best-so-far and tentative character codes */ |
| 1615 |
int c, i, x, y; |
| 1616 |
/*tex height-plus-depth of a tentative character */ |
| 1617 |
scaled u; |
| 1618 |
/*tex largest height-plus-depth so far */ |
| 1619 |
scaled w = 0; |
| 1620 |
/*tex runs through font family members */ |
| 1621 |
int z; |
| 1622 |
/*tex are we trying the ``large'' variant? */ |
| 1623 |
boolean large_attempt = false; |
| 1624 |
/*tex to save the current attribute list */ |
| 1625 |
pointer att = null; |
| 1626 |
int emas = 0 ; |
| 1627 |
boolean do_parts = false; |
| 1628 |
boolean parts_done = false; |
| 1629 |
extinfo *ext; |
| 1630 |
|
| 1631 |
if (d && ! small_fam(d) && ! large_fam(d) && ! small_char(d) && ! large_char(d)) { |
| 1632 |
halfword b = new_null_box(); |
| 1633 |
subtype(b) = math_v_delimiter_list; |
| 1634 |
if (! flat) |
| 1635 |
width(b) = null_delimiter_space_par; |
| 1636 |
node_attr(b) = node_attr(d); |
| 1637 |
node_attr(d) = null; |
| 1638 |
flush_node(d); |
| 1639 |
return b; |
| 1640 |
} |
| 1641 |
|
| 1642 |
x = 0; |
| 1643 |
f = null_font; |
| 1644 |
c = 0; |
| 1645 |
if (d == null) { |
| 1646 |
goto FOUND; |
| 1647 |
} |
| 1648 |
z = small_fam(d); |
| 1649 |
x = small_char(d); |
| 1650 |
i = 0; |
| 1651 |
if (same != NULL) { |
| 1652 |
emas = *same ; |
| 1653 |
same = 0; |
| 1654 |
} |
| 1655 |
while (true) { |
| 1656 |
/*tex |
| 1657 |
|
| 1658 |
The search process is complicated slightly by the facts that some of |
| 1659 |
the characters might not be present in some of the fonts, and they |
| 1660 |
might not be probed in increasing order of height. |
| 1661 |
|
| 1662 |
*/ |
| 1663 |
if ((z != 0) || (x != 0)) { |
| 1664 |
g = fam_fnt(z, s); |
| 1665 |
if (g != null_font) { |
| 1666 |
y = x; |
| 1667 |
CONTINUE: |
| 1668 |
i++; |
| 1669 |
if (char_exists(g, y)) { |
| 1670 |
if (flat) |
| 1671 |
u = char_width(g, y); |
| 1672 |
else |
| 1673 |
u = height_plus_depth(g, y); |
| 1674 |
if (u > w) { |
| 1675 |
f = g; |
| 1676 |
c = y; |
| 1677 |
w = u; |
| 1678 |
if (u >= v) { |
| 1679 |
/* |
| 1680 |
This solves a leftbrace middle being abused as starting point |
| 1681 |
for an extensible bar in cmex. It's the only known case where |
| 1682 |
a middle piece is so large that it makes us consider it a valid |
| 1683 |
sized character. It is large because it braces have variants. The |
| 1684 |
reason why actually these starting points can be somewhat weird |
| 1685 |
(like: the extesible is a bottom parent piece (small) that has a |
| 1686 |
recipe using shared middle pieces and and self references bottom |
| 1687 |
piece usage.) In opentype the extensibles always sit on a complete |
| 1688 |
shape i.e. they are end points in a variant list or a base |
| 1689 |
character. It took two decades to run into an example (HH & MS). |
| 1690 |
*/ |
| 1691 |
if (is_new_mathfont(g)) { |
| 1692 |
goto FOUND; |
| 1693 |
} else if (char_tag(g, y) != ext_tag) { |
| 1694 |
goto FOUND; |
| 1695 |
} |
| 1696 |
} |
| 1697 |
} |
| 1698 |
if (char_tag(g, y) == ext_tag) { |
| 1699 |
f = g; |
| 1700 |
c = y; |
| 1701 |
do_parts = true; |
| 1702 |
goto FOUND; |
| 1703 |
} |
| 1704 |
if (i > 10000) { |
| 1705 |
endless_loop_error(g, y); |
| 1706 |
goto FOUND; |
| 1707 |
} |
| 1708 |
if (char_tag(g, y) == list_tag) { |
| 1709 |
y = char_remainder(g, y); |
| 1710 |
goto CONTINUE; |
| 1711 |
} |
| 1712 |
} |
| 1713 |
} |
| 1714 |
} |
| 1715 |
if (large_attempt) { |
| 1716 |
/*tex There were none large enough. */ |
| 1717 |
goto FOUND; |
| 1718 |
} |
| 1719 |
large_attempt = true; |
| 1720 |
z = large_fam(d); |
| 1721 |
x = large_char(d); |
| 1722 |
} |
| 1723 |
FOUND: |
| 1724 |
if (d != null) { |
| 1725 |
att = node_attr(d); |
| 1726 |
node_attr(d) = null; |
| 1727 |
flush_node(d); |
| 1728 |
} |
| 1729 |
if (f != null_font) { |
| 1730 |
/*tex |
| 1731 |
|
| 1732 |
When the following code is executed, |do_parts| will be true if a |
| 1733 |
built-up symbol is supposed to be returned. |
| 1734 |
|
| 1735 |
*/ |
| 1736 |
ext = NULL; |
| 1737 |
if ((do_parts) && ((!flat && (ext = get_charinfo_vert_variants(char_info(f,c))) != NULL) |
| 1738 |
|| ( flat && (ext = get_charinfo_hor_variants (char_info(f,c))) != NULL))) { |
| 1739 |
parts_done = true; |
| 1740 |
if (flat) { |
| 1741 |
b = get_delim_box(f, c, v, connector_overlap_min(cur_style), 1, att); |
| 1742 |
} else { |
| 1743 |
b = get_delim_box(f, c, v, connector_overlap_min(cur_style), 0, att); |
| 1744 |
} |
| 1745 |
if (delta != NULL) { |
| 1746 |
if (assume_new_math(f)) { |
| 1747 |
*delta = char_vert_italic(f,x); |
| 1748 |
} else { |
| 1749 |
*delta = char_italic(f,x); |
| 1750 |
} |
| 1751 |
} |
| 1752 |
if (stack != NULL) |
| 1753 |
*stack = true ; |
| 1754 |
} else { |
| 1755 |
parts_done = false; |
| 1756 |
if (same != NULL && x == c) { |
| 1757 |
*same = emas; |
| 1758 |
} |
| 1759 |
/*tex |
| 1760 |
Here italic is added to width in traditional fonts which makes the delimiter get |
| 1761 |
the real width. An \OPENTYPE\ font already has the right width. |
| 1762 |
*/ |
| 1763 |
b = char_box(f, c, att); |
| 1764 |
/*tex |
| 1765 |
There is one case where |delta| (ic) gets subtracted but only for a traditional |
| 1766 |
font. In that case the traditional width (which is fake width + italic) becomes |
| 1767 |
less and the delta is added. See (**). (On the mailing list font |ntxexx| was |
| 1768 |
mentioned as test case by MK.) |
| 1769 |
*/ |
| 1770 |
if (delta != NULL) { |
| 1771 |
*delta = char_italic(f, c); |
| 1772 |
} |
| 1773 |
if (stack != NULL) |
| 1774 |
*stack = false ; |
| 1775 |
} |
| 1776 |
} else { |
| 1777 |
b = new_null_box(); |
| 1778 |
reset_attributes(b, att); |
| 1779 |
if (flat) { |
| 1780 |
width(b) = 0; |
| 1781 |
subtype(b) = math_h_delimiter_list; |
| 1782 |
} else { |
| 1783 |
/*tex Use this width if no delimiter was found. */ |
| 1784 |
width(b) = null_delimiter_space_par; |
| 1785 |
subtype(b) = math_v_delimiter_list; |
| 1786 |
} |
| 1787 |
if (delta != NULL) { |
| 1788 |
*delta = 0; |
| 1789 |
} |
| 1790 |
if (stack != NULL) |
| 1791 |
*stack = false ; |
| 1792 |
} |
| 1793 |
if (!flat) { |
| 1794 |
/*tex when emas ~= 0 then we have a non scaled character */ |
| 1795 |
if (emas != 0 && delimitermodesamenos) { |
| 1796 |
/*tex same character and no shift when same forced */ |
| 1797 |
goto DONE; |
| 1798 |
} |
| 1799 |
if (! parts_done && delimitermodecharnos) { |
| 1800 |
/*tex same character and no shift when same forced */ |
| 1801 |
goto DONE; |
| 1802 |
} |
| 1803 |
if (delimitermodenoshift) { |
| 1804 |
/*tex no shift forced */ |
| 1805 |
goto DONE; |
| 1806 |
} |
| 1807 |
/*tex vertical variant */ |
| 1808 |
shift_amount(b) = half(height(b) - depth(b)); |
| 1809 |
if (shift) { |
| 1810 |
shift_amount(b) -= math_axis_size(s); |
| 1811 |
} |
| 1812 |
} |
| 1813 |
DONE: |
| 1814 |
delete_attribute_ref(att); |
| 1815 |
return b; |
| 1816 |
} |
| 1817 |
|
| 1818 |
/*tex |
| 1819 |
|
| 1820 |
The next subroutine is much simpler; it is used for numerators and |
| 1821 |
denominators of fractions as well as for displayed operators and their limits |
| 1822 |
above and below. It takes a given box~|b| and changes it so that the new box |
| 1823 |
is centered in a box of width~|w|. The centering is done by putting \.{\\hss} |
| 1824 |
glue at the left and right of the list inside |b|, then packaging the new |
| 1825 |
box; thus, the actual box might not really be centered, if it already |
| 1826 |
contains infinite glue. |
| 1827 |
|
| 1828 |
The given box might contain a single character whose italic correction has |
| 1829 |
been added to the width of the box; in this case a compensating kern is |
| 1830 |
inserted. |
| 1831 |
|
| 1832 |
*/ |
| 1833 |
|
| 1834 |
static pointer rebox(pointer b, scaled w) |
| 1835 |
{ |
| 1836 |
/*tex temporary registers for list manipulation */ |
| 1837 |
pointer p, q, r, att; |
| 1838 |
/*tex font in a one-character box */ |
| 1839 |
internal_font_number f; |
| 1840 |
/*tex width of a character without italic correction */ |
| 1841 |
scaled v; |
| 1842 |
if ((width(b) != w) && (list_ptr(b) != null)) { |
| 1843 |
if (type(b) == vlist_node) { |
| 1844 |
p = hpack(b, 0, additional, -1); |
| 1845 |
reset_attributes(p, node_attr(b)); |
| 1846 |
b = p; |
| 1847 |
} |
| 1848 |
p = list_ptr(b); |
| 1849 |
att = node_attr(b); |
| 1850 |
add_node_attr_ref(att); |
| 1851 |
if ((is_char_node(p)) && (vlink(p) == null)) { |
| 1852 |
f = font(p); |
| 1853 |
v = char_width(f, character(p)); |
| 1854 |
if (v != width(b)) { |
| 1855 |
q = new_kern(width(b) - v); |
| 1856 |
reset_attributes(q, att); |
| 1857 |
couple_nodes(p,q); |
| 1858 |
} |
| 1859 |
} |
| 1860 |
list_ptr(b) = null; |
| 1861 |
flush_node(b); |
| 1862 |
b = new_glue(ss_glue); |
| 1863 |
reset_attributes(b, att); |
| 1864 |
couple_nodes(b,p); |
| 1865 |
while (vlink(p) != null) |
| 1866 |
p = vlink(p); |
| 1867 |
q = new_glue(ss_glue); |
| 1868 |
reset_attributes(q, att); |
| 1869 |
couple_nodes(p,q); |
| 1870 |
r = hpack(b, w, exactly, -1); |
| 1871 |
reset_attributes(r, att); |
| 1872 |
delete_attribute_ref(att); |
| 1873 |
return r; |
| 1874 |
} else { |
| 1875 |
width(b) = w; |
| 1876 |
return b; |
| 1877 |
} |
| 1878 |
} |
| 1879 |
|
| 1880 |
/*tex |
| 1881 |
|
| 1882 |
Here is a subroutine that creates a new glue specification from another one |
| 1883 |
that is expressed in `\.{mu}', given the value of the math unit. |
| 1884 |
|
| 1885 |
*/ |
| 1886 |
|
| 1887 |
#define mu_mult(A) mult_and_add(n,(A),xn_over_d((A),f,unity),max_dimen) |
| 1888 |
|
| 1889 |
static pointer math_glue(pointer g, scaled m) |
| 1890 |
{ |
| 1891 |
/*tex integer part of |m| */ |
| 1892 |
int n = x_over_n(m, unity); |
| 1893 |
/*tex fraction part of |m| */ |
| 1894 |
scaled f = tex_remainder; |
| 1895 |
/*tex the new glue specification */ |
| 1896 |
pointer p; |
| 1897 |
if (f < 0) { |
| 1898 |
decr(n); |
| 1899 |
f = f + unity; |
| 1900 |
} |
| 1901 |
p = new_node(glue_node, 0); |
| 1902 |
/* convert \.{mu} to \.{pt} */ |
| 1903 |
width(p) = mu_mult(width(g)); |
| 1904 |
stretch_order(p) = stretch_order(g); |
| 1905 |
if (stretch_order(p) == normal) |
| 1906 |
stretch(p) = mu_mult(stretch(g)); |
| 1907 |
else |
| 1908 |
stretch(p) = stretch(g); |
| 1909 |
shrink_order(p) = shrink_order(g); |
| 1910 |
if (shrink_order(p) == normal) |
| 1911 |
shrink(p) = mu_mult(shrink(g)); |
| 1912 |
else |
| 1913 |
shrink(p) = shrink(g); |
| 1914 |
return p; |
| 1915 |
} |
| 1916 |
|
| 1917 |
static void math_glue_to_glue(pointer p, scaled m) |
| 1918 |
{ |
| 1919 |
/*tex integer part of |m| */ |
| 1920 |
int n = x_over_n(m, unity); |
| 1921 |
/*tex fraction part of |m| */ |
| 1922 |
scaled f = tex_remainder; |
| 1923 |
if (f < 0) { |
| 1924 |
decr(n); |
| 1925 |
f = f + unity; |
| 1926 |
} |
| 1927 |
/* convert \.{mu} to \.{pt} */ |
| 1928 |
width(p) = mu_mult(width(p)); |
| 1929 |
if (stretch_order(p) == normal) |
| 1930 |
stretch(p) = mu_mult(stretch(p)); |
| 1931 |
if (shrink_order(p) == normal) |
| 1932 |
shrink(p) = mu_mult(shrink(p)); |
| 1933 |
subtype(p) = normal; |
| 1934 |
} |
| 1935 |
|
| 1936 |
/*tex |
| 1937 |
|
| 1938 |
The |math_kern| subroutine removes |mu_glue| from a kern node, given the |
| 1939 |
value of the math unit. |
| 1940 |
|
| 1941 |
*/ |
| 1942 |
static void math_kern(pointer p, scaled m) |
| 1943 |
{ |
| 1944 |
/*tex integer part of |m| */ |
| 1945 |
int n; |
| 1946 |
/*tex fraction part of |m| */ |
| 1947 |
scaled f; |
| 1948 |
if (subtype(p) == mu_glue) { |
| 1949 |
n = x_over_n(m, unity); |
| 1950 |
f = tex_remainder; |
| 1951 |
if (f < 0) { |
| 1952 |
decr(n); |
| 1953 |
f = f + unity; |
| 1954 |
} |
| 1955 |
width(p) = mu_mult(width(p)); |
| 1956 |
/* this is weird, it's not a italic but explicit_kern */ |
| 1957 |
subtype(p) = italic_kern; |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
void run_mlist_to_hlist(halfword p, boolean penalties, int mstyle) |
| 1962 |
{ |
| 1963 |
int callback_id; |
| 1964 |
int a, sfix, i; |
| 1965 |
if (p == null) { |
| 1966 |
vlink(temp_head) = null; |
| 1967 |
return; |
| 1968 |
} |
| 1969 |
finalize_math_parameters(); |
| 1970 |
callback_id = callback_defined(mlist_to_hlist_callback); |
| 1971 |
if (callback_id > 0) { |
| 1972 |
sfix = lua_gettop(Luas); |
| 1973 |
if (!get_callback(Luas, callback_id)) { |
| 1974 |
lua_settop(Luas, sfix); |
| 1975 |
return; |
| 1976 |
} |
| 1977 |
alink(p) = null ; |
| 1978 |
nodelist_to_lua(Luas, p); |
| 1979 |
lua_push_math_style_name(Luas, mstyle); |
| 1980 |
lua_pushboolean(Luas, penalties); |
| 1981 |
if ((i=lua_pcall(Luas, 3, 1, 0)) != 0) { |
| 1982 |
formatted_warning("mlist to hlist","error: %s",lua_tostring(Luas, -1)); |
| 1983 |
lua_settop(Luas, sfix); |
| 1984 |
luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1)); |
| 1985 |
return; |
| 1986 |
} |
| 1987 |
a = nodelist_from_lua(Luas,-1); |
| 1988 |
/* alink(vlink(a)) = null; */ |
| 1989 |
vlink(temp_head) = a; |
| 1990 |
lua_settop(Luas, sfix); |
| 1991 |
} else if (callback_id == 0) { |
| 1992 |
mlist_to_hlist(p, penalties, mstyle); |
| 1993 |
} else { |
| 1994 |
vlink(temp_head) = null; |
| 1995 |
} |
| 1996 |
} |
| 1997 |
|
| 1998 |
/*tex |
| 1999 |
|
| 2000 |
The recursion in |mlist_to_hlist| is due primarily to a subroutine called |
| 2001 |
|clean_box| that puts a given noad field into a box using a given math style; |
| 2002 |
|mlist_to_hlist| can call |clean_box|, which can call |mlist_to_hlist|. |
| 2003 |
|
| 2004 |
The box returned by |clean_box| is ``clean'' in the sense that its |
| 2005 |
|shift_amount| is zero. |
| 2006 |
|
| 2007 |
*/ |
| 2008 |
|
| 2009 |
static pointer clean_box(pointer p, int s, int cur_style, halfword st) |
| 2010 |
{ |
| 2011 |
/*tex beginning of a list to be boxed */ |
| 2012 |
pointer q; |
| 2013 |
/*tex box to be returned */ |
| 2014 |
pointer x; |
| 2015 |
/*tex temporary pointer */ |
| 2016 |
pointer r; |
| 2017 |
/*tex beginning of mlist to be translated */ |
| 2018 |
pointer mlist = null; |
| 2019 |
switch (type(p)) { |
| 2020 |
case math_char_node: |
| 2021 |
mlist = new_noad(); |
| 2022 |
r = math_clone(p); |
| 2023 |
nucleus(mlist) = r; |
| 2024 |
break; |
| 2025 |
case sub_box_node: |
| 2026 |
q = math_list(p); |
| 2027 |
goto FOUND; |
| 2028 |
break; |
| 2029 |
case sub_mlist_node: |
| 2030 |
mlist = math_list(p); |
| 2031 |
break; |
| 2032 |
default: |
| 2033 |
q = new_null_box(); |
| 2034 |
subtype(q) = math_list_list; |
| 2035 |
goto FOUND; |
| 2036 |
} |
| 2037 |
mlist_to_hlist(mlist, false, s); |
| 2038 |
/*tex recursive call */ |
| 2039 |
q = vlink(temp_head); |
| 2040 |
setup_cur_size(cur_style); |
| 2041 |
FOUND: |
| 2042 |
if (is_char_node(q) || (q == null)) |
| 2043 |
x = hpack(q, 0, additional, -1); |
| 2044 |
else if ((vlink(q) == null) && (type(q) <= vlist_node) && (shift_amount(q) == 0)) |
| 2045 |
/*tex It's already clean. */ |
| 2046 |
x = q; |
| 2047 |
else |
| 2048 |
x = hpack(q, 0, additional, -1); |
| 2049 |
if (x != q && q != null) |
| 2050 |
reset_attributes(x, node_attr(q)); |
| 2051 |
subtype(x) = st; |
| 2052 |
/*tex Here we save memory space in a common case. */ |
| 2053 |
q = list_ptr(x); |
| 2054 |
if (is_char_node(q)) { |
| 2055 |
r = vlink(q); |
| 2056 |
if (r != null) { |
| 2057 |
if (vlink(r) == null) { |
| 2058 |
if (!is_char_node(r)) { |
| 2059 |
if (type(r) == kern_node) { |
| 2060 |
/*tex Unneeded italic correction. */ |
| 2061 |
flush_node(r); |
| 2062 |
vlink(q) = null; |
| 2063 |
} |
| 2064 |
} |
| 2065 |
} |
| 2066 |
} |
| 2067 |
} |
| 2068 |
return x; |
| 2069 |
} |
| 2070 |
|
| 2071 |
/*tex |
| 2072 |
|
| 2073 |
It is convenient to have a procedure that converts a |math_char| field to an |
| 2074 |
``unpacked'' form. The |fetch| routine sets |cur_f| and |cur_c| to the font |
| 2075 |
code and character code of a given noad field. It also takes care of issuing |
| 2076 |
error messages for nonexistent characters; in such cases, |
| 2077 |
|char_exists(cur_f,cur_c)| will be |false| after |fetch| has acted, and the |
| 2078 |
field will also have been reset to |null|. |
| 2079 |
|
| 2080 |
The outputs of |fetch| are placed in global variables. |
| 2081 |
|
| 2082 |
*/ |
| 2083 |
|
| 2084 |
/*tex the |font| field of a |math_char| */ |
| 2085 |
|
| 2086 |
internal_font_number cur_f; |
| 2087 |
|
| 2088 |
/*tex the |character| field of a |math_char| */ |
| 2089 |
|
| 2090 |
int cur_c; |
| 2091 |
|
| 2092 |
/*tex Here we unpack the |math_char| field |a|. */ |
| 2093 |
|
| 2094 |
static void fetch(pointer a) |
| 2095 |
{ |
| 2096 |
cur_c = math_character(a); |
| 2097 |
cur_f = fam_fnt(math_fam(a), cur_size); |
| 2098 |
if (cur_f == null_font) { |
| 2099 |
char *msg; |
| 2100 |
const char *hlp[] = { |
| 2101 |
"Somewhere in the math formula just ended, you used the", |
| 2102 |
"stated character from an undefined font family. For example,", |
| 2103 |
"plain TeX doesn't allow \\it or \\sl in subscripts. Proceed,", |
| 2104 |
"and I'll try to forget that I needed that character.", |
| 2105 |
NULL |
| 2106 |
}; |
| 2107 |
msg = xmalloc(256); |
| 2108 |
snprintf(msg, 255, "\\%s%d is undefined (character %d)", |
| 2109 |
math_size_string(cur_size), (int) math_fam(a), (int) cur_c); |
| 2110 |
tex_error(msg, hlp); |
| 2111 |
free(msg); |
| 2112 |
} else if (!(char_exists(cur_f, cur_c))) { |
| 2113 |
char_warning(cur_f, cur_c); |
| 2114 |
} |
| 2115 |
} |
| 2116 |
|
| 2117 |
/*tex |
| 2118 |
|
| 2119 |
We need to do a lot of different things, so |mlist_to_hlist| makes two passes |
| 2120 |
over the given mlist. |
| 2121 |
|
| 2122 |
The first pass does most of the processing: It removes ``mu'' spacing from |
| 2123 |
glue, it recursively evaluates all subsidiary mlists so that only the |
| 2124 |
top-level mlist remains to be handled, it puts fractions and square roots and |
| 2125 |
such things into boxes, it attaches subscripts and superscripts, and it |
| 2126 |
computes the overall height and depth of the top-level mlist so that the size |
| 2127 |
of delimiters for a |fence_noad| will be known. The hlist resulting from each |
| 2128 |
noad is recorded in that noad's |new_hlist| field, an integer field that |
| 2129 |
replaces the |nucleus| or |thickness|. |
| 2130 |
|
| 2131 |
The second pass eliminates all noads and inserts the correct glue and |
| 2132 |
penalties between nodes. |
| 2133 |
|
| 2134 |
*/ |
| 2135 |
|
| 2136 |
static void assign_new_hlist(pointer q, pointer r) |
| 2137 |
{ |
| 2138 |
switch (type(q)) { |
| 2139 |
case fraction_noad: |
| 2140 |
math_list(numerator(q)) = null; |
| 2141 |
flush_node(numerator(q)); |
| 2142 |
numerator(q) = null; |
| 2143 |
math_list(denominator(q)) = null; |
| 2144 |
flush_node(denominator(q)); |
| 2145 |
denominator(q) = null; |
| 2146 |
break; |
| 2147 |
case radical_noad: |
| 2148 |
case simple_noad: |
| 2149 |
case accent_noad: |
| 2150 |
if (nucleus(q) != null) { |
| 2151 |
math_list(nucleus(q)) = null; |
| 2152 |
flush_node(nucleus(q)); |
| 2153 |
nucleus(q) = null; |
| 2154 |
} |
| 2155 |
break; |
| 2156 |
} |
| 2157 |
new_hlist(q) = r; |
| 2158 |
} |
| 2159 |
|
| 2160 |
#define choose_mlist(A) do { p=A(q); A(q)=null; } while (0) |
| 2161 |
|
| 2162 |
/*tex |
| 2163 |
|
| 2164 |
Most of the actual construction work of |mlist_to_hlist| is done by |
| 2165 |
procedures with names like |make_fraction|, |make_radical|, etc. To |
| 2166 |
illustrate the general setup of such procedures, let's begin with a couple of |
| 2167 |
simple ones. |
| 2168 |
|
| 2169 |
*/ |
| 2170 |
|
| 2171 |
static void make_over(pointer q, int cur_style, int cur_size, int cur_fam) |
| 2172 |
{ |
| 2173 |
/*tex |
| 2174 |
|
| 2175 |
No rule adaption yet, maybe never as overbars should be proper |
| 2176 |
extensibles. |
| 2177 |
|
| 2178 |
*/ |
| 2179 |
pointer p; |
| 2180 |
scaled f, t; |
| 2181 |
scaled used_thickness = overbar_rule(cur_style); |
| 2182 |
scaled used_fam = cur_fam; |
| 2183 |
if (math_rule_thickness_mode_par > 0) { |
| 2184 |
f = noad_fam(q); |
| 2185 |
if (f >= 0) { |
| 2186 |
t = fam_fnt(f,cur_size); |
| 2187 |
if (assume_new_math(t)) { |
| 2188 |
t = font_MATH_par(t, OverbarRuleThickness); |
| 2189 |
if (t != undefined_math_parameter) { |
| 2190 |
used_thickness = t; |
| 2191 |
used_fam = f; |
| 2192 |
} |
| 2193 |
} |
| 2194 |
} |
| 2195 |
} |
| 2196 |
p = overbar(clean_box(nucleus(q), cramped_style(cur_style), cur_style, math_nucleus_list), |
| 2197 |
overbar_vgap(cur_style), used_thickness, overbar_kern(cur_style), |
| 2198 |
node_attr(nucleus(q)), math_over_rule, cur_size, used_fam); |
| 2199 |
subtype(p) = math_over_list; |
| 2200 |
math_list(nucleus(q)) = p; |
| 2201 |
type(nucleus(q)) = sub_box_node; |
| 2202 |
} |
| 2203 |
|
| 2204 |
static void make_under(pointer q, int cur_style, int cur_size, int cur_fam) |
| 2205 |
{ |
| 2206 |
/*tex |
| 2207 |
|
| 2208 |
No rule adaption yet, maybe never as underbars should be proper |
| 2209 |
extensibles. |
| 2210 |
|
| 2211 |
*/ |
| 2212 |
/*tex temporary registers for box construction */ |
| 2213 |
pointer p, x, y, r; |
| 2214 |
/*tex overall height plus depth */ |
| 2215 |
scaled delta; |
| 2216 |
scaled f, t; |
| 2217 |
scaled used_thickness = underbar_rule(cur_style); |
| 2218 |
scaled used_fam = cur_fam; |
| 2219 |
x = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 2220 |
p = new_kern(underbar_vgap(cur_style)); |
| 2221 |
reset_attributes(p, node_attr(q)); |
| 2222 |
couple_nodes(x,p); |
| 2223 |
if (math_rule_thickness_mode_par > 0) { |
| 2224 |
f = noad_fam(q); |
| 2225 |
if (f >= 0) { |
| 2226 |
t = fam_fnt(f,cur_size); |
| 2227 |
if (assume_new_math(t)) { |
| 2228 |
t = font_MATH_par(t, UnderbarRuleThickness); |
| 2229 |
if (t != undefined_math_parameter) { |
| 2230 |
used_thickness = t; |
| 2231 |
used_fam = f; |
| 2232 |
} |
| 2233 |
} |
| 2234 |
} |
| 2235 |
} |
| 2236 |
r = do_fraction_rule(used_thickness, node_attr(q), math_under_rule, cur_size, used_fam); |
| 2237 |
couple_nodes(p,r); |
| 2238 |
y = vpackage(x, 0, additional, max_dimen, math_direction_par); |
| 2239 |
reset_attributes(y, node_attr(q)); |
| 2240 |
subtype(y) = math_under_list; |
| 2241 |
delta = height(y) + depth(y) + underbar_kern(cur_style); |
| 2242 |
height(y) = height(x); |
| 2243 |
depth(y) = delta - height(y); |
| 2244 |
math_list(nucleus(q)) = y; |
| 2245 |
type(nucleus(q)) = sub_box_node; |
| 2246 |
} |
| 2247 |
|
| 2248 |
static void make_vcenter(pointer q) |
| 2249 |
{ |
| 2250 |
/*tex the box that should be centered vertically */ |
| 2251 |
pointer v; |
| 2252 |
/*tex its height plus depth */ |
| 2253 |
scaled delta; |
| 2254 |
v = math_list(nucleus(q)); |
| 2255 |
if (type(v) != vlist_node) |
| 2256 |
confusion("vcenter"); |
| 2257 |
delta = height(v) + depth(v); |
| 2258 |
height(v) = math_axis_size(cur_size) + half(delta); |
| 2259 |
depth(v) = delta - height(v); |
| 2260 |
} |
| 2261 |
|
| 2262 |
/*tex |
| 2263 |
|
| 2264 |
According to the rules in the \.{DVI} file specifications, we ensure |
| 2265 |
alignment between a square root sign and the rule above its nucleus by |
| 2266 |
assuming that the baseline of the square-root symbol is the same as the |
| 2267 |
bottom of the rule. The height of the square-root symbol will be the |
| 2268 |
thickness of the rule, and the depth of the square-root symbol should exceed |
| 2269 |
or equal the height-plus-depth of the nucleus plus a certain minimum |
| 2270 |
clearance~|psi|. The symbol will be placed so that the actual clearance is |
| 2271 |
|psi| plus half the excess. |
| 2272 |
|
| 2273 |
*/ |
| 2274 |
|
| 2275 |
static void make_hextension(pointer q, int cur_style) |
| 2276 |
{ |
| 2277 |
pointer e, p; |
| 2278 |
halfword w; |
| 2279 |
boolean stack = false; |
| 2280 |
e = do_delimiter(q, left_delimiter(q), cur_size, radicalwidth(q), true, cur_style, true, &stack, NULL, NULL); |
| 2281 |
w = width(e); |
| 2282 |
if (!stack&& (radicalwidth(q) != 0) && (radicalwidth(q) != width(e))) { |
| 2283 |
if (radicalmiddle(q)) { |
| 2284 |
p = new_kern(half(radicalwidth(q)-w)); |
| 2285 |
reset_attributes(p, node_attr(q)); |
| 2286 |
couple_nodes(p,e); |
| 2287 |
e = p; |
| 2288 |
w = radicalwidth(q); |
| 2289 |
} else if (radicalexact(q)) { |
| 2290 |
w = radicalwidth(q); |
| 2291 |
} |
| 2292 |
} |
| 2293 |
e = hpack(e, 0, additional, -1); |
| 2294 |
width(e) = w ; |
| 2295 |
reset_attributes(e, node_attr(q)); |
| 2296 |
math_list(nucleus(q)) = e; |
| 2297 |
left_delimiter(q) = null; |
| 2298 |
} |
| 2299 |
|
| 2300 |
static void make_radical(pointer q, int cur_style) |
| 2301 |
{ |
| 2302 |
/*tex temporary registers for box construction */ |
| 2303 |
pointer x, y, p, l1, l2; |
| 2304 |
/*tex dimensions involved in the calculation */ |
| 2305 |
scaled delta, clr, theta, h, f; |
| 2306 |
scaled t, used_fam ; |
| 2307 |
x = clean_box(nucleus(q), cramped_style(cur_style), cur_style, math_nucleus_list); |
| 2308 |
clr = radical_vgap(cur_style); |
| 2309 |
theta = radical_rule_par(cur_style); |
| 2310 |
used_fam = small_fam(left_delimiter(q)); |
| 2311 |
/*tex |
| 2312 |
|
| 2313 |
We can take the rule width from the fam/style of the delimiter or use the |
| 2314 |
most recent math parameters value. |
| 2315 |
|
| 2316 |
*/ |
| 2317 |
if (math_rule_thickness_mode_par > 0) { |
| 2318 |
f = small_fam(left_delimiter(q)); |
| 2319 |
if (f >= 0) { |
| 2320 |
t = fam_fnt(f,cur_size); |
| 2321 |
if (assume_new_math(t)) { |
| 2322 |
t = font_MATH_par(t, RadicalRuleThickness); |
| 2323 |
if (t != undefined_math_parameter) { |
| 2324 |
theta = t; |
| 2325 |
used_fam = f; |
| 2326 |
} |
| 2327 |
} |
| 2328 |
} |
| 2329 |
} |
| 2330 |
if (theta == undefined_math_parameter) { |
| 2331 |
/*tex a real radical */ |
| 2332 |
theta = fraction_rule(cur_style); |
| 2333 |
y = do_delimiter(q, left_delimiter(q), cur_size, height(x) + depth(x) + clr + theta, false, cur_style, true, NULL, NULL, NULL); |
| 2334 |
/*tex |
| 2335 |
|
| 2336 |
If |y| is a composite then set |theta| to the height of its top |
| 2337 |
character, else set it to the height of |y|. |
| 2338 |
|
| 2339 |
*/ |
| 2340 |
l1 = list_ptr(y); |
| 2341 |
if ((l1 != null) && (type(l1) == hlist_node)) { |
| 2342 |
/*tex possible composite */ |
| 2343 |
l2 = list_ptr(l1); |
| 2344 |
if ((l2 != null) && (type(l2) == glyph_node)) { |
| 2345 |
/*tex top character */ |
| 2346 |
theta = char_height(font(l2), character(l2)); |
| 2347 |
} else { |
| 2348 |
theta = height(y); |
| 2349 |
} |
| 2350 |
} else { |
| 2351 |
theta = height(y); |
| 2352 |
} |
| 2353 |
} else { |
| 2354 |
/*tex |
| 2355 |
|
| 2356 |
Not really a radical but we use its node, historical sharing (like in |
| 2357 |
mathml). |
| 2358 |
|
| 2359 |
*/ |
| 2360 |
y = do_delimiter(q, left_delimiter(q), cur_size, height(x) + depth(x) + clr + theta, false, cur_style, true, NULL, NULL, NULL); |
| 2361 |
} |
| 2362 |
/*tex |
| 2363 |
|
| 2364 |
Weird hack, in overbar we use small_fam(left_delimiter(q)) so actually |
| 2365 |
small_fam(0). |
| 2366 |
|
| 2367 |
*/ |
| 2368 |
left_delimiter(q) = null; |
| 2369 |
delta = (depth(y) + height(y) - theta) - (height(x) + depth(x) + clr); |
| 2370 |
if (delta > 0) { |
| 2371 |
/*tex increase the actual clearance */ |
| 2372 |
clr = clr + half(delta); |
| 2373 |
} |
| 2374 |
shift_amount(y) = (height(y) - theta) - (height(x) + clr); |
| 2375 |
h = depth(y) + height(y); |
| 2376 |
p = overbar(x, clr, theta, radical_kern(cur_style), node_attr(y), math_radical_rule, cur_size, used_fam); |
| 2377 |
subtype(p) = math_radical_list; |
| 2378 |
couple_nodes(y,p); |
| 2379 |
if (degree(q) != null) { |
| 2380 |
scaled wr, br, ar; |
| 2381 |
pointer r = clean_box(degree(q), script_script_style, cur_style, math_degree_list); |
| 2382 |
reset_attributes(r, node_attr(degree(q))); |
| 2383 |
wr = width(r); |
| 2384 |
if (wr == 0) { |
| 2385 |
flush_node(r); |
| 2386 |
} else { |
| 2387 |
br = radical_degree_before(cur_style); |
| 2388 |
ar = radical_degree_after(cur_style); |
| 2389 |
if (-ar > (wr + br)) |
| 2390 |
ar = -(wr + br); |
| 2391 |
x = new_kern(ar); |
| 2392 |
reset_attributes(x, node_attr(degree(q))); |
| 2393 |
couple_nodes(x,y); |
| 2394 |
shift_amount(r) = |
| 2395 |
-((xn_over_d(h, radical_degree_raise(cur_style), 100)) - |
| 2396 |
depth(y) - shift_amount(y)); |
| 2397 |
couple_nodes(r,x); |
| 2398 |
x = new_kern(br); |
| 2399 |
reset_attributes(x, node_attr(degree(q))); |
| 2400 |
couple_nodes(x,r); |
| 2401 |
y = x; |
| 2402 |
} |
| 2403 |
/*tex for \.{\\Uroot ..{<list>}{}} : */ |
| 2404 |
math_list(degree(q)) = null; |
| 2405 |
flush_node(degree(q)); |
| 2406 |
} |
| 2407 |
p = hpack(y, 0, additional, -1); |
| 2408 |
reset_attributes(p, node_attr(q)); |
| 2409 |
math_list(nucleus(q)) = p; |
| 2410 |
type(nucleus(q)) = sub_box_node; |
| 2411 |
} |
| 2412 |
|
| 2413 |
/*tex Construct a vlist box: */ |
| 2414 |
|
| 2415 |
static pointer wrapup_over_under_delimiter(pointer x, pointer y, pointer q, scaled shift_up, scaled shift_down, halfword st) |
| 2416 |
{ |
| 2417 |
pointer p; |
| 2418 |
pointer v = new_null_box(); |
| 2419 |
type(v) = vlist_node; |
| 2420 |
subtype(v) = st; |
| 2421 |
height(v) = shift_up + height(x); |
| 2422 |
depth(v) = depth(y) + shift_down; |
| 2423 |
reset_attributes(v, node_attr(q)); |
| 2424 |
p = new_kern((shift_up - depth(x)) - (height(y) - shift_down)); |
| 2425 |
reset_attributes(p, node_attr(q)); |
| 2426 |
couple_nodes(p,y); |
| 2427 |
couple_nodes(x,p); |
| 2428 |
list_ptr(v) = x; |
| 2429 |
return v; |
| 2430 |
} |
| 2431 |
|
| 2432 |
/*tex When |exact| use radicalwidth (|y| is delimiter). */ |
| 2433 |
|
| 2434 |
#define fixup_widths(q,x,y) do { \ |
| 2435 |
if (width(y) >= width(x)) { \ |
| 2436 |
if (radicalwidth(q) != 0) { \ |
| 2437 |
shift_amount(x) += half(width(y)-width(x)) ; \ |
| 2438 |
} \ |
| 2439 |
width(x) = width(y); \ |
| 2440 |
} else { \ |
| 2441 |
if (radicalwidth(q) != 0) { \ |
| 2442 |
shift_amount(y) += half(width(x)-width(y)) ; \ |
| 2443 |
} \ |
| 2444 |
width(y) = width(x); \ |
| 2445 |
} \ |
| 2446 |
} while (0) |
| 2447 |
|
| 2448 |
|
| 2449 |
#define check_radical(q,stack,r,t) do { \ |
| 2450 |
if (!stack && (width(r) >= width(t)) && (radicalwidth(q) != 0) && (radicalwidth(q) != width(r))) { \ |
| 2451 |
if (radicalleft(q)) { \ |
| 2452 |
halfword p = new_kern(radicalwidth(q)-width(r)); \ |
| 2453 |
reset_attributes(p, node_attr(q)); \ |
| 2454 |
couple_nodes(p,r); \ |
| 2455 |
r = hpack(p, 0, additional, -1); \ |
| 2456 |
width(r) = radicalwidth(q); \ |
| 2457 |
reset_attributes(r, node_attr(q)); \ |
| 2458 |
} else if (radicalmiddle(q)) { \ |
| 2459 |
halfword p = new_kern(half(radicalwidth(q)-width(r))); \ |
| 2460 |
reset_attributes(p, node_attr(q)); \ |
| 2461 |
couple_nodes(p,r); \ |
| 2462 |
r = hpack(p, 0, additional, -1); \ |
| 2463 |
width(r) = radicalwidth(q); \ |
| 2464 |
reset_attributes(r, node_attr(q)); \ |
| 2465 |
} else if (radicalright(q)) { \ |
| 2466 |
/*tex also kind of exact compared to vertical */ \ |
| 2467 |
r = hpack(r, 0, additional, -1); \ |
| 2468 |
width(r) = radicalwidth(q); \ |
| 2469 |
reset_attributes(r, node_attr(q)); \ |
| 2470 |
} \ |
| 2471 |
} \ |
| 2472 |
} while (0) |
| 2473 |
|
| 2474 |
#define check_widths(q,p) do { \ |
| 2475 |
if (radicalwidth(q) != 0) { \ |
| 2476 |
wd = radicalwidth(q); \ |
| 2477 |
} else { \ |
| 2478 |
wd = width(p); \ |
| 2479 |
} \ |
| 2480 |
} while (0) |
| 2481 |
|
| 2482 |
/*tex |
| 2483 |
|
| 2484 |
This has the |nucleus| box |x| as a limit above an extensible delimiter |y|. |
| 2485 |
|
| 2486 |
*/ |
| 2487 |
|
| 2488 |
static void make_over_delimiter(pointer q, int cur_style) |
| 2489 |
{ |
| 2490 |
pointer x, y, v; |
| 2491 |
scaled shift_up, shift_down, clr, delta, wd; |
| 2492 |
boolean stack; |
| 2493 |
if (math_defaults_mode_par > 0) |
| 2494 |
x = clean_box(nucleus(q), sup_style(cur_style), cur_style, math_nucleus_list); |
| 2495 |
else |
| 2496 |
x = clean_box(nucleus(q), sub_style(cur_style), cur_style, math_nucleus_list); |
| 2497 |
check_widths(q,x); |
| 2498 |
y = do_delimiter(q, left_delimiter(q), cur_size, wd, true, cur_style, true, &stack, NULL, NULL); |
| 2499 |
left_delimiter(q) = null; |
| 2500 |
check_radical(q,stack,y,x); |
| 2501 |
fixup_widths(q, x, y); |
| 2502 |
shift_up = over_delimiter_bgap(cur_style); |
| 2503 |
shift_down = 0; |
| 2504 |
clr = over_delimiter_vgap(cur_style); |
| 2505 |
delta = clr - ((shift_up - depth(x)) - (height(y) - shift_down)); |
| 2506 |
if (delta > 0) { |
| 2507 |
shift_up = shift_up + delta; |
| 2508 |
} |
| 2509 |
v = wrapup_over_under_delimiter(x, y, q, shift_up, shift_down, math_over_delimiter_list); |
| 2510 |
/*tex This also equals |width(y)|: */ |
| 2511 |
width(v) = width(x); |
| 2512 |
math_list(nucleus(q)) = v; |
| 2513 |
type(nucleus(q)) = sub_box_node; |
| 2514 |
} |
| 2515 |
|
| 2516 |
/*tex |
| 2517 |
|
| 2518 |
This has the extensible delimiter |x| as a limit below |nucleus| box |y|. |
| 2519 |
|
| 2520 |
*/ |
| 2521 |
|
| 2522 |
static void make_under_delimiter(pointer q, int cur_style) |
| 2523 |
{ |
| 2524 |
pointer x, y, v; |
| 2525 |
scaled shift_up, shift_down, clr, delta, wd; |
| 2526 |
boolean stack; |
| 2527 |
if (math_defaults_mode_par > 0) |
| 2528 |
y = clean_box(nucleus(q), sub_style(cur_style), cur_style, math_nucleus_list); |
| 2529 |
else |
| 2530 |
y = clean_box(nucleus(q), sup_style(cur_style), cur_style, math_nucleus_list); |
| 2531 |
check_widths(q,y); |
| 2532 |
x = do_delimiter(q, left_delimiter(q), cur_size, wd, true, cur_style, true, &stack, NULL, NULL); |
| 2533 |
left_delimiter(q) = null; |
| 2534 |
check_radical(q,stack,x,y); |
| 2535 |
fixup_widths(q, x, y); |
| 2536 |
shift_up = 0; |
| 2537 |
shift_down = under_delimiter_bgap(cur_style); |
| 2538 |
clr = under_delimiter_vgap(cur_style); |
| 2539 |
delta = clr - ((shift_up - depth(x)) - (height(y) - shift_down)); |
| 2540 |
if (delta > 0) { |
| 2541 |
shift_down = shift_down + delta; |
| 2542 |
} |
| 2543 |
v = wrapup_over_under_delimiter(x, y, q, shift_up, shift_down, math_under_delimiter_list); |
| 2544 |
/*tex This also equals |width(y)|: */ |
| 2545 |
width(v) = width(y); |
| 2546 |
math_list(nucleus(q)) = v; |
| 2547 |
type(nucleus(q)) = sub_box_node; |
| 2548 |
} |
| 2549 |
|
| 2550 |
/*tex |
| 2551 |
|
| 2552 |
This has the extensible delimiter |x| as a limit above |nucleus| box |y|. |
| 2553 |
|
| 2554 |
*/ |
| 2555 |
|
| 2556 |
static void make_delimiter_over(pointer q, int cur_style) |
| 2557 |
{ |
| 2558 |
pointer x, y, v; |
| 2559 |
scaled shift_up, shift_down, clr, actual, wd; |
| 2560 |
boolean stack; |
| 2561 |
if (math_defaults_mode_par > 0) |
| 2562 |
y = clean_box(nucleus(q), cramped_style(cur_style), cur_style, math_nucleus_list); |
| 2563 |
else |
| 2564 |
y = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 2565 |
check_widths(q,y); |
| 2566 |
x = do_delimiter(q, left_delimiter(q), cur_size + (cur_size == script_script_size ? 0 : 1), wd, true, cur_style, true, &stack, NULL, NULL); |
| 2567 |
left_delimiter(q) = null; |
| 2568 |
check_radical(q,stack,x,y); |
| 2569 |
fixup_widths(q, x, y); |
| 2570 |
shift_up = over_delimiter_bgap(cur_style)-height(x)-depth(x); |
| 2571 |
shift_down = 0; |
| 2572 |
clr = over_delimiter_vgap(cur_style); |
| 2573 |
actual = shift_up - height(y); |
| 2574 |
if (actual < clr) { |
| 2575 |
shift_up = shift_up + (clr-actual); |
| 2576 |
} |
| 2577 |
v = wrapup_over_under_delimiter(x, y, q, shift_up, shift_down, math_over_delimiter_list); |
| 2578 |
/*tex This also equals |width(y)|: */ |
| 2579 |
width(v) = width(x); |
| 2580 |
math_list(nucleus(q)) = v; |
| 2581 |
type(nucleus(q)) = sub_box_node; |
| 2582 |
} |
| 2583 |
|
| 2584 |
/*tex |
| 2585 |
|
| 2586 |
This has the extensible delimiter |y| as a limit below a |nucleus| box |x|. |
| 2587 |
|
| 2588 |
*/ |
| 2589 |
|
| 2590 |
static void make_delimiter_under(pointer q, int cur_style) |
| 2591 |
{ |
| 2592 |
pointer x, y, v; |
| 2593 |
scaled shift_up, shift_down, clr, actual, wd; |
| 2594 |
boolean stack; |
| 2595 |
x = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 2596 |
check_widths(q,x); |
| 2597 |
y = do_delimiter(q, left_delimiter(q), cur_size + (cur_size == script_script_size ? 0 : 1), wd, true, cur_style, true, &stack, NULL, NULL); |
| 2598 |
left_delimiter(q) = null; |
| 2599 |
check_radical(q,stack,y,x); |
| 2600 |
fixup_widths(q, x, y); |
| 2601 |
shift_up = 0; |
| 2602 |
shift_down = under_delimiter_bgap(cur_style) - height(y)-depth(y); |
| 2603 |
clr = under_delimiter_vgap(cur_style); |
| 2604 |
actual = shift_down - depth(x); |
| 2605 |
if (actual<clr) { |
| 2606 |
shift_down += (clr-actual); |
| 2607 |
} |
| 2608 |
v = wrapup_over_under_delimiter(x, y, q, shift_up, shift_down, math_under_delimiter_list); |
| 2609 |
/*tex This also equals |width(y)|: */ |
| 2610 |
width(v) = width(y); |
| 2611 |
math_list(nucleus(q)) = v; |
| 2612 |
type(nucleus(q)) = sub_box_node; |
| 2613 |
} |
| 2614 |
|
| 2615 |
/*tex |
| 2616 |
|
| 2617 |
Slants are not considered when placing accents in math mode. The accenter is |
| 2618 |
centered over the accentee, and the accent width is treated as zero with |
| 2619 |
respect to the size of the final box. |
| 2620 |
|
| 2621 |
*/ |
| 2622 |
|
| 2623 |
#define TOP_CODE 1 |
| 2624 |
#define BOT_CODE 2 |
| 2625 |
#define OVERLAY_CODE 4 |
| 2626 |
#define STRETCH_ACCENT_CODE 8 |
| 2627 |
|
| 2628 |
static boolean compute_accent_skew(pointer q, int flags, scaled *s) |
| 2629 |
{ |
| 2630 |
/*tex temporary register for box construction */ |
| 2631 |
pointer p; |
| 2632 |
/*tex will be true if a top-accent is placed in |s| */ |
| 2633 |
boolean s_is_absolute = false; |
| 2634 |
if (type(nucleus(q)) == math_char_node) { |
| 2635 |
fetch(nucleus(q)); |
| 2636 |
if (assume_new_math(cur_f)) { |
| 2637 |
/*tex |
| 2638 |
There is no bot_accent so let's assume similarity |
| 2639 |
|
| 2640 |
\starttyping |
| 2641 |
if (flags & (TOP_CODE | OVERLAY_CODE)) { |
| 2642 |
*s = char_top_accent(cur_f, cur_c); |
| 2643 |
if (*s != INT_MIN) { |
| 2644 |
s_is_absolute = true; |
| 2645 |
} |
| 2646 |
} else { |
| 2647 |
*s = char_bot_accent(cur_f, cur_c); |
| 2648 |
if (*s != INT_MIN) { |
| 2649 |
s_is_absolute = true; |
| 2650 |
} |
| 2651 |
} |
| 2652 |
\stoptyping |
| 2653 |
*/ |
| 2654 |
*s = char_top_accent(cur_f, cur_c); |
| 2655 |
if (*s != INT_MIN) { |
| 2656 |
s_is_absolute = true; |
| 2657 |
} |
| 2658 |
} else { |
| 2659 |
if (flags & TOP_CODE) { |
| 2660 |
*s = get_kern(cur_f, cur_c, skew_char(cur_f)); |
| 2661 |
} else { |
| 2662 |
*s = 0; |
| 2663 |
} |
| 2664 |
} |
| 2665 |
} else if (type(nucleus(q)) == sub_mlist_node) { |
| 2666 |
/*tex |
| 2667 |
If |nucleus(q)| is a |sub_mlist_node| composed of an |accent_noad| we: |
| 2668 |
|
| 2669 |
\startitemize |
| 2670 |
\startitem |
| 2671 |
use the positioning of the nucleus of that noad, recursing until |
| 2672 |
\stopitem |
| 2673 |
\startitem |
| 2674 |
the inner most |accent_noad|. This way multiple stacked accents |
| 2675 |
are |
| 2676 |
\stopitem |
| 2677 |
\startitem |
| 2678 |
aligned to the inner most one. |
| 2679 |
\stopitem |
| 2680 |
\stoptitemize |
| 2681 |
|
| 2682 |
The vlink test was added in version 1.06, so that we only consider a |
| 2683 |
lone noad: |
| 2684 |
|
| 2685 |
$ |
| 2686 |
\Umathaccent bottom 0 0 "023DF { \Umathaccent fixed 0 0 "00302 { m } r } \quad |
| 2687 |
\Umathaccent bottom 0 0 "023DF { l \Umathaccent fixed 0 0 "00302 { m } r } \quad |
| 2688 |
\Umathaccent bottom 0 0 "023DF { l \Umathaccent fixed 0 0 "00302 { m } } \quad |
| 2689 |
\Umathaccent bottom 0 0 "023DF { \Umathaccent fixed 0 0 "00302 { m } } \quad |
| 2690 |
\Umathaccent bottom 0 0 "023DF { l r } |
| 2691 |
$ |
| 2692 |
|
| 2693 |
*/ |
| 2694 |
p = math_list(nucleus(q)); |
| 2695 |
if (type(p) == accent_noad && vlink(p) == null) { |
| 2696 |
s_is_absolute = compute_accent_skew(p, flags, s); |
| 2697 |
} |
| 2698 |
} else { |
| 2699 |
} |
| 2700 |
|
| 2701 |
return s_is_absolute; |
| 2702 |
} |
| 2703 |
|
| 2704 |
static void do_make_math_accent(pointer q, internal_font_number f, int c, int flags, int cur_style) |
| 2705 |
{ |
| 2706 |
/*tex temporary registers for box construction */ |
| 2707 |
pointer p, r, x, y; |
| 2708 |
/*tex amount to skew the accent to the right */ |
| 2709 |
scaled s; |
| 2710 |
/*tex height of character being accented */ |
| 2711 |
scaled h; |
| 2712 |
/*tex space to remove between accent and accentee */ |
| 2713 |
scaled delta; |
| 2714 |
/*tex width of the accentee, not including sub/superscripts */ |
| 2715 |
scaled w; |
| 2716 |
/*tex will be true if a top-accent is placed in |s| */ |
| 2717 |
boolean s_is_absolute; |
| 2718 |
scaled fraction ; |
| 2719 |
scaled ic = 0; |
| 2720 |
scaled target ; |
| 2721 |
extinfo *ext; |
| 2722 |
pointer attr_p; |
| 2723 |
attr_p = (flags & TOP_CODE ? top_accent_chr(q) : flags & BOT_CODE ? bot_accent_chr(q) : overlay_accent_chr(q)); |
| 2724 |
fraction = accentfraction(q); |
| 2725 |
c = cur_c; |
| 2726 |
f = cur_f; |
| 2727 |
s = 1; |
| 2728 |
if (fraction == 0) { |
| 2729 |
fraction = 1000; |
| 2730 |
} |
| 2731 |
/*tex Compute the amount of skew, or set |s| to an alignment point */ |
| 2732 |
s_is_absolute = compute_accent_skew(q, flags, &s); |
| 2733 |
x = clean_box(nucleus(q), cramped_style(cur_style), cur_style, math_nucleus_list); |
| 2734 |
w = width(x); |
| 2735 |
h = height(x); |
| 2736 |
if (assume_new_math(cur_f) && !s_is_absolute) { |
| 2737 |
s = half(w); |
| 2738 |
s_is_absolute = true; |
| 2739 |
} |
| 2740 |
/*tex Switch to a larger accent if available and appropriate */ |
| 2741 |
y = null; |
| 2742 |
ext = NULL; |
| 2743 |
if (flags & OVERLAY_CODE) { |
| 2744 |
if (fraction > 0) { |
| 2745 |
target = xn_over_d(h,fraction,1000); |
| 2746 |
} else { |
| 2747 |
target = h; |
| 2748 |
} |
| 2749 |
} else { |
| 2750 |
if (fraction > 0) { |
| 2751 |
target = xn_over_d(w,fraction,1000); |
| 2752 |
} else { |
| 2753 |
target = w; |
| 2754 |
} |
| 2755 |
} |
| 2756 |
if ((flags & STRETCH_ACCENT_CODE) && (char_width(f, c) < w)) { |
| 2757 |
while (1) { |
| 2758 |
if ((char_tag(f, c) == ext_tag) && ((ext = get_charinfo_hor_variants(char_info(f, c))) != NULL)) { |
| 2759 |
/*tex a bit weird for an overlay but anyway, here we don't need a factor as we don't step */ |
| 2760 |
y = get_delim_box(f, c, w, connector_overlap_min(cur_style), 1, node_attr(attr_p)); |
| 2761 |
break; |
| 2762 |
} else if (char_tag(f, c) != list_tag) { |
| 2763 |
break; |
| 2764 |
} else { |
| 2765 |
int yy = char_remainder(f, c); |
| 2766 |
if (!char_exists(f, yy)) { |
| 2767 |
break; |
| 2768 |
} else if (flags & OVERLAY_CODE) { |
| 2769 |
if (char_height(f, yy) > target) { |
| 2770 |
break; |
| 2771 |
} |
| 2772 |
} else { |
| 2773 |
if (char_width(f, yy) > target) |
| 2774 |
break; |
| 2775 |
} |
| 2776 |
c = yy; |
| 2777 |
} |
| 2778 |
} |
| 2779 |
} |
| 2780 |
if (y == null) { |
| 2781 |
/*tex italic gets added to width */ |
| 2782 |
y = char_box(f, c, node_attr(attr_p)); |
| 2783 |
} |
| 2784 |
if (flags & TOP_CODE) { |
| 2785 |
if (h < accent_base_height(f)) { |
| 2786 |
delta = h; |
| 2787 |
} else { |
| 2788 |
delta = accent_base_height(f); |
| 2789 |
} |
| 2790 |
} else if (flags & OVERLAY_CODE) { |
| 2791 |
/*tex center the accent vertically around the accentee */ |
| 2792 |
delta = half(height(y) + depth(y) + height(x) + depth(x)); |
| 2793 |
} else { |
| 2794 |
delta = 0; /* hm */ |
| 2795 |
} |
| 2796 |
if ((supscr(q) != null) || (subscr(q) != null)) { |
| 2797 |
if (type(nucleus(q)) == math_char_node) { |
| 2798 |
/*tex swap the subscript and superscript into box |x| */ |
| 2799 |
flush_node_list(x); |
| 2800 |
x = new_noad(); |
| 2801 |
r = math_clone(nucleus(q)); |
| 2802 |
nucleus(x) = r; |
| 2803 |
supscr(x) = supscr(q); |
| 2804 |
supscr(q) = null; |
| 2805 |
subscr(x) = subscr(q); |
| 2806 |
subscr(q) = null; |
| 2807 |
type(nucleus(q)) = sub_mlist_node; |
| 2808 |
math_list(nucleus(q)) = x; |
| 2809 |
x = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 2810 |
delta = delta + height(x) - h; |
| 2811 |
h = height(x); |
| 2812 |
} |
| 2813 |
// } else if ((vlink(q) != null) && (type(nucleus(q)) == math_char_node)) { |
| 2814 |
// /*tex only pure math char nodes */ |
| 2815 |
// internal_font_number f = fam_fnt(math_fam(nucleus(q)),cur_size); |
| 2816 |
} |
| 2817 |
/*tex the top accents of both characters are aligned */ |
| 2818 |
if (s_is_absolute) { |
| 2819 |
scaled sa; |
| 2820 |
if (ext != NULL) { |
| 2821 |
/*tex if the accent is extensible just take the center */ |
| 2822 |
sa = half(width(y)); |
| 2823 |
} else { |
| 2824 |
/*tex |
| 2825 |
There is no bot_accent so let's assume similarity |
| 2826 |
|
| 2827 |
\starttyping |
| 2828 |
if (flags & BOT_CODE) { |
| 2829 |
sa = char_bot_accent(f, c); |
| 2830 |
} else { |
| 2831 |
sa = char_top_accent(f, c); |
| 2832 |
} |
| 2833 |
\stoptyping |
| 2834 |
*/ |
| 2835 |
sa = char_top_accent(f, c); |
| 2836 |
} |
| 2837 |
if (sa == INT_MIN) { |
| 2838 |
/*tex just take the center */ |
| 2839 |
sa = half(width(y)); |
| 2840 |
} |
| 2841 |
if (math_direction_par == dir_TRT) { |
| 2842 |
shift_amount(y) = s + sa - width(y); |
| 2843 |
} else { |
| 2844 |
shift_amount(y) = s - sa; |
| 2845 |
} |
| 2846 |
} else { |
| 2847 |
if (width(y)== 0) { |
| 2848 |
shift_amount(y) = s + w; |
| 2849 |
} else if (math_direction_par == dir_TRT) { |
| 2850 |
shift_amount(y) = s + width(y); /* ok? */ |
| 2851 |
} else { |
| 2852 |
shift_amount(y) = s + half(w - width(y)); |
| 2853 |
} |
| 2854 |
} |
| 2855 |
width(y) = 0; |
| 2856 |
if (flags & (TOP_CODE | OVERLAY_CODE)) { |
| 2857 |
p = new_kern(-delta); |
| 2858 |
reset_attributes(p, node_attr(q)); |
| 2859 |
couple_nodes(p,x); |
| 2860 |
couple_nodes(y,p); |
| 2861 |
} else { |
| 2862 |
couple_nodes(x,y); |
| 2863 |
y = x; |
| 2864 |
} |
| 2865 |
r = vpackage(y, 0, additional, max_dimen, math_direction_par); |
| 2866 |
reset_attributes(r, node_attr(q)); |
| 2867 |
subtype(r) = math_accent_list; |
| 2868 |
width(r) = width(x); |
| 2869 |
y = r; |
| 2870 |
if (flags & (TOP_CODE | OVERLAY_CODE)) { |
| 2871 |
if (height(y) < h) { |
| 2872 |
/*tex make the height of box |y| equal to |h| */ |
| 2873 |
p = new_kern(h - height(y)); |
| 2874 |
reset_attributes(p, node_attr(q)); |
| 2875 |
try_couple_nodes(p,list_ptr(y)); |
| 2876 |
list_ptr(y) = p; |
| 2877 |
height(y) = h; |
| 2878 |
} |
| 2879 |
} else { |
| 2880 |
shift_amount(y) = -(h - height(y)); |
| 2881 |
} |
| 2882 |
if (ic != 0) { |
| 2883 |
/*tex old font codepath has ic built in, new font code doesn't */ |
| 2884 |
width(r) += ic ; |
| 2885 |
} |
| 2886 |
math_list(nucleus(q)) = y; |
| 2887 |
type(nucleus(q)) = sub_box_node; |
| 2888 |
} |
| 2889 |
|
| 2890 |
static void make_math_accent(pointer q, int cur_style) |
| 2891 |
{ |
| 2892 |
int topstretch = !(subtype(q) % 2); |
| 2893 |
int botstretch = !(subtype(q) / 2); |
| 2894 |
|
| 2895 |
if (top_accent_chr(q) != null) { |
| 2896 |
fetch(top_accent_chr(q)); |
| 2897 |
if (char_exists(cur_f, cur_c)) { |
| 2898 |
do_make_math_accent(q, cur_f, cur_c, TOP_CODE | (topstretch ? STRETCH_ACCENT_CODE : 0), cur_style); |
| 2899 |
} |
| 2900 |
flush_node(top_accent_chr(q)); |
| 2901 |
top_accent_chr(q) = null; |
| 2902 |
} |
| 2903 |
if (bot_accent_chr(q) != null) { |
| 2904 |
fetch(bot_accent_chr(q)); |
| 2905 |
if (char_exists(cur_f, cur_c)) { |
| 2906 |
do_make_math_accent(q, cur_f, cur_c, BOT_CODE | (botstretch ? STRETCH_ACCENT_CODE : 0), cur_style); |
| 2907 |
} |
| 2908 |
flush_node(bot_accent_chr(q)); |
| 2909 |
bot_accent_chr(q) = null; |
| 2910 |
} |
| 2911 |
if (overlay_accent_chr(q) != null) { |
| 2912 |
fetch(overlay_accent_chr(q)); |
| 2913 |
if (char_exists(cur_f, cur_c)) { |
| 2914 |
do_make_math_accent(q, cur_f, cur_c, OVERLAY_CODE | STRETCH_ACCENT_CODE, cur_style); |
| 2915 |
} |
| 2916 |
flush_node(overlay_accent_chr(q)); |
| 2917 |
overlay_accent_chr(q) = null; |
| 2918 |
} |
| 2919 |
} |
| 2920 |
|
| 2921 |
/*tex |
| 2922 |
|
| 2923 |
The |make_fraction| procedure is a bit different because it sets |
| 2924 |
|new_hlist(q)| directly rather than making a sub-box. |
| 2925 |
|
| 2926 |
*/ |
| 2927 |
|
| 2928 |
static void make_fraction(pointer q, int cur_style) |
| 2929 |
{ |
| 2930 |
pointer p, p1, p2, v, x, y, z, l, r, m; |
| 2931 |
scaled delta, delta1, delta2, shift_up, shift_down, clr1, clr2, f, t;\ |
| 2932 |
/*tex |
| 2933 |
|
| 2934 |
We can take the rule width from an explicitly set fam, even if a fraction |
| 2935 |
itself has no character, otherwise we just use the math parameter. |
| 2936 |
|
| 2937 |
*/ |
| 2938 |
scaled used_fam = math_rules_fam_par; |
| 2939 |
if (math_rule_thickness_mode_par > 0 && thickness(q) != 0) { |
| 2940 |
f = fraction_fam(q); |
| 2941 |
if (f >= 0) { |
| 2942 |
t = fam_fnt(f,cur_size); |
| 2943 |
if (assume_new_math(t)) { |
| 2944 |
t = font_MATH_par(t, FractionRuleThickness); |
| 2945 |
if (t != undefined_math_parameter) { |
| 2946 |
thickness(q) = t; |
| 2947 |
used_fam = f; |
| 2948 |
} |
| 2949 |
} |
| 2950 |
} |
| 2951 |
} |
| 2952 |
if (thickness(q) == default_code) |
| 2953 |
thickness(q) = fraction_rule(cur_style); |
| 2954 |
/*tex |
| 2955 |
|
| 2956 |
Create equal-width boxes |x| and |z| for the numerator and denominator, |
| 2957 |
and compute the default amounts |shift_up| and |shift_down| by which they |
| 2958 |
are displaced from the baseline. |
| 2959 |
|
| 2960 |
*/ |
| 2961 |
x = clean_box(numerator(q), num_style(cur_style), cur_style, math_numerator_list); |
| 2962 |
z = clean_box(denominator(q), denom_style(cur_style), cur_style, math_denominator_list); |
| 2963 |
if (middle_delimiter(q) != null) { |
| 2964 |
delta = 0; |
| 2965 |
m = do_delimiter(q, middle_delimiter(q), cur_size, delta, false, cur_style, true, NULL, NULL, NULL); |
| 2966 |
middle_delimiter(q) = null; |
| 2967 |
} else { |
| 2968 |
m = null ; |
| 2969 |
if (width(x) < width(z)) { |
| 2970 |
x = rebox(x, width(z)); |
| 2971 |
} else { |
| 2972 |
z = rebox(z, width(x)); |
| 2973 |
} |
| 2974 |
} |
| 2975 |
if (m != null) { |
| 2976 |
shift_up = 0; |
| 2977 |
shift_down = 0; |
| 2978 |
} else if (thickness(q) == 0) { |
| 2979 |
shift_up = stack_num_up(cur_style); |
| 2980 |
shift_down = stack_denom_down(cur_style); |
| 2981 |
/*tex |
| 2982 |
|
| 2983 |
The numerator and denominator must be separated by a certain minimum |
| 2984 |
clearance, called |clr| in the following program. The difference |
| 2985 |
between |clr| and the actual clearance is |2delta|. |
| 2986 |
|
| 2987 |
*/ |
| 2988 |
clr1 = stack_vgap(cur_style); |
| 2989 |
delta = half(clr1 - ((shift_up - depth(x)) - (height(z) - shift_down))); |
| 2990 |
if (delta > 0) { |
| 2991 |
shift_up = shift_up + delta; |
| 2992 |
shift_down = shift_down + delta; |
| 2993 |
} |
| 2994 |
} else { |
| 2995 |
shift_up = fraction_num_up(cur_style); |
| 2996 |
shift_down = fraction_denom_down(cur_style); |
| 2997 |
/*tex |
| 2998 |
|
| 2999 |
In the case of a fraction line, the minimum clearance depends on the |
| 3000 |
actual thickness of the line. |
| 3001 |
|
| 3002 |
*/ |
| 3003 |
clr1 = fraction_num_vgap(cur_style); |
| 3004 |
clr2 = fraction_denom_vgap(cur_style); |
| 3005 |
delta = half(thickness(q)); |
| 3006 |
if (fractionexact(q)) { |
| 3007 |
delta1 = clr1 - ((shift_up - depth(x) ) - (math_axis_size(cur_size) + delta)); |
| 3008 |
delta2 = clr2 - ((shift_down - height(z)) + (math_axis_size(cur_size) - delta)); |
| 3009 |
} else { |
| 3010 |
clr1 = ext_xn_over_d(clr1, thickness(q), fraction_rule(cur_style)); |
| 3011 |
clr2 = ext_xn_over_d(clr2, thickness(q), fraction_rule(cur_style)); |
| 3012 |
delta1 = clr1 - ((shift_up - depth(x) ) - (math_axis_size(cur_size) + delta)); |
| 3013 |
delta2 = clr2 - ((shift_down - height(z)) + (math_axis_size(cur_size) - delta)); |
| 3014 |
} |
| 3015 |
if (delta1 > 0) { |
| 3016 |
shift_up = shift_up + delta1; |
| 3017 |
} |
| 3018 |
if (delta2 > 0) { |
| 3019 |
shift_down = shift_down + delta2; |
| 3020 |
} |
| 3021 |
} |
| 3022 |
if (m != null) { |
| 3023 |
/*tex |
| 3024 |
|
| 3025 |
Construct a hlist box for the fraction, according to |hgap| and |
| 3026 |
|vgap|. |
| 3027 |
|
| 3028 |
*/ |
| 3029 |
shift_up = skewed_fraction_vgap(cur_style); |
| 3030 |
|
| 3031 |
if (!fractionnoaxis(q)) { |
| 3032 |
shift_up += half(math_axis_size(cur_size)); |
| 3033 |
} |
| 3034 |
shift_down = shift_up; |
| 3035 |
v = new_null_box(); |
| 3036 |
reset_attributes(v, node_attr(q)); |
| 3037 |
type(v) = hlist_node; |
| 3038 |
subtype(v) = math_numerator_list; |
| 3039 |
list_ptr(v) = x; |
| 3040 |
width(v) = width(x); |
| 3041 |
height(v) = height(x) + shift_up; |
| 3042 |
depth(v) = depth(x); |
| 3043 |
shift_amount(v) = - shift_up; |
| 3044 |
x = v; |
| 3045 |
v = new_null_box(); |
| 3046 |
reset_attributes(v, node_attr(q)); |
| 3047 |
type(v) = hlist_node; |
| 3048 |
subtype(v) = math_denominator_list; |
| 3049 |
list_ptr(v) = z; |
| 3050 |
width(v) = width(z); |
| 3051 |
height(v) = height(z); |
| 3052 |
depth(v) = depth(z) + shift_down; |
| 3053 |
shift_amount(v) = shift_down; |
| 3054 |
z = v; |
| 3055 |
v = new_null_box(); |
| 3056 |
subtype(v) = math_fraction_list; |
| 3057 |
reset_attributes(v, node_attr(q)); |
| 3058 |
type(v) = hlist_node; |
| 3059 |
if (height(x) > height(z)) { |
| 3060 |
height(v) = height(x); |
| 3061 |
} else { |
| 3062 |
height(v) = height(z); |
| 3063 |
} |
| 3064 |
if (depth(x) > depth(z)) { |
| 3065 |
depth(v) = depth(x); |
| 3066 |
} else { |
| 3067 |
depth(v) = depth(z); |
| 3068 |
} |
| 3069 |
if (height(m) > height(v)) { |
| 3070 |
height(v) = height(m); |
| 3071 |
} |
| 3072 |
if (depth(m) > depth(v)) { |
| 3073 |
depth(v) = depth(m); |
| 3074 |
} |
| 3075 |
if (fractionexact(q)) { |
| 3076 |
delta1 = -half(skewed_fraction_hgap(cur_style)); |
| 3077 |
delta2 = delta1; |
| 3078 |
width(v) = width(x) + width(z) + width(m) - skewed_fraction_hgap(cur_style); |
| 3079 |
} else { |
| 3080 |
delta1 = half(skewed_fraction_hgap(cur_style)-width(m)); |
| 3081 |
delta2 = half(skewed_fraction_hgap(cur_style)+width(m)); |
| 3082 |
width(v) = width(x) + width(z) + skewed_fraction_hgap(cur_style); |
| 3083 |
width(m) = 0; |
| 3084 |
} |
| 3085 |
p1 = new_kern(delta1); |
| 3086 |
reset_attributes(p1, node_attr(q)); |
| 3087 |
p2 = new_kern(delta2); |
| 3088 |
reset_attributes(p2, node_attr(q)); |
| 3089 |
couple_nodes(x,p1); |
| 3090 |
couple_nodes(p1,m); |
| 3091 |
couple_nodes(m,p2); |
| 3092 |
couple_nodes(p2,z); |
| 3093 |
list_ptr(v) = x; |
| 3094 |
} else { |
| 3095 |
/*tex |
| 3096 |
|
| 3097 |
Construct a vlist box for the fraction, according to |shift_up| and |
| 3098 |
|shift_down|. |
| 3099 |
|
| 3100 |
*/ |
| 3101 |
v = new_null_box(); |
| 3102 |
type(v) = vlist_node; |
| 3103 |
subtype(v) = math_fraction_list; |
| 3104 |
height(v) = shift_up + height(x); |
| 3105 |
depth(v) = depth(z) + shift_down; |
| 3106 |
/*tex This also equals |width(z)|. */ |
| 3107 |
width(v) = width(x); |
| 3108 |
reset_attributes(v, node_attr(q)); |
| 3109 |
if (thickness(q) && ! fractionnorule(q)) { |
| 3110 |
y = do_fraction_rule(thickness(q), node_attr(q), math_fraction_rule, cur_size, used_fam); |
| 3111 |
p = new_kern((math_axis_size(cur_size) - delta) - (height(z) - shift_down)); |
| 3112 |
reset_attributes(p, node_attr(q)); |
| 3113 |
couple_nodes(y,p); |
| 3114 |
couple_nodes(p,z); |
| 3115 |
p = new_kern((shift_up - depth(x)) - (math_axis_size(cur_size) + delta)); |
| 3116 |
couple_nodes(p,y); |
| 3117 |
} else { |
| 3118 |
p = new_kern((shift_up - depth(x)) - (height(z) - shift_down)); |
| 3119 |
couple_nodes(p,z); |
| 3120 |
} |
| 3121 |
reset_attributes(p, node_attr(q)); |
| 3122 |
couple_nodes(x,p); |
| 3123 |
list_ptr(v) = x; |
| 3124 |
} |
| 3125 |
/*tex |
| 3126 |
|
| 3127 |
Put the fraction into a box with its delimiters, and make |new_hlist(q)| |
| 3128 |
point to it. |
| 3129 |
|
| 3130 |
*/ |
| 3131 |
if (assume_new_math(cur_f)) { |
| 3132 |
delta = fraction_del_size_new(cur_style); |
| 3133 |
if (delta == undefined_math_parameter) { |
| 3134 |
delta = get_delimiter_height(depth(v), height(v), true); |
| 3135 |
} |
| 3136 |
} else { |
| 3137 |
delta = fraction_del_size_old(cur_style); |
| 3138 |
} |
| 3139 |
l = do_delimiter(q, left_delimiter(q), cur_size, delta, false, cur_style, true, NULL, NULL, NULL); |
| 3140 |
left_delimiter(q) = null; |
| 3141 |
r = do_delimiter(q, right_delimiter(q), cur_size, delta, false, cur_style, true, NULL, NULL, NULL); |
| 3142 |
right_delimiter(q) = null; |
| 3143 |
couple_nodes(l,v); |
| 3144 |
couple_nodes(v,r); |
| 3145 |
y = hpack(l, 0, additional, -1); |
| 3146 |
reset_attributes(y, node_attr(q)); |
| 3147 |
/*tex There can also be a nested one: */ |
| 3148 |
subtype(y) = math_fraction_list; |
| 3149 |
assign_new_hlist(q, y); |
| 3150 |
} |
| 3151 |
|
| 3152 |
/*tex |
| 3153 |
|
| 3154 |
If the nucleus of an |op_noad| is a single character, it is to be centered |
| 3155 |
vertically with respect to the axis, after first being enlarged (via a |
| 3156 |
character list in the font) if we are in display style. The normal convention |
| 3157 |
for placing displayed limits is to put them above and below the operator in |
| 3158 |
display style. |
| 3159 |
|
| 3160 |
The italic correction is removed from the character if there is a subscript |
| 3161 |
and the limits are not being displayed. The |make_op| routine returns the |
| 3162 |
value that should be used as an offset between subscript and superscript. |
| 3163 |
|
| 3164 |
After |make_op| has acted, |subtype(q)| will be |limits| if and only if the |
| 3165 |
limits have been set above and below the operator. In that case, |
| 3166 |
|new_hlist(q)| will already contain the desired final box. |
| 3167 |
|
| 3168 |
*/ |
| 3169 |
|
| 3170 |
static void make_scripts(pointer q, pointer p, scaled it, int cur_style, scaled supshift, scaled subshift); |
| 3171 |
static pointer check_nucleus_complexity(halfword q, scaled * delta, int cur_style, int *same); |
| 3172 |
|
| 3173 |
static scaled make_op(pointer q, int cur_style) |
| 3174 |
{ |
| 3175 |
/*tex offset between subscript and superscript */ |
| 3176 |
scaled delta = 0; |
| 3177 |
/*tex temporary registers for box construction */ |
| 3178 |
pointer p, v, x, y, z; |
| 3179 |
/*tex register for character examination */ |
| 3180 |
int c; |
| 3181 |
/*tex dimensions for box calculation */ |
| 3182 |
scaled shift_up, shift_down; |
| 3183 |
boolean axis_shift = false; |
| 3184 |
int opentype = 0; |
| 3185 |
scaled ok_size; |
| 3186 |
if ((subtype(q) == op_noad_type_normal) && (cur_style < text_style)) { |
| 3187 |
subtype(q) = op_noad_type_limits; |
| 3188 |
} |
| 3189 |
if (type(nucleus(q)) == math_char_node) { |
| 3190 |
fetch(nucleus(q)); |
| 3191 |
if (cur_style < text_style) { |
| 3192 |
/*tex try to make it larger: $\displaystyle \int \limits _a^b f(x)$ */ /* 1 */ |
| 3193 |
ok_size = minimum_operator_size(cur_style); |
| 3194 |
if (ok_size != undefined_math_parameter) { |
| 3195 |
/*tex creating a temporary delimiter is the cleanest way */ |
| 3196 |
y = new_node(delim_node, 0); |
| 3197 |
reset_attributes(y, node_attr(nucleus(q))); |
| 3198 |
small_fam(y) = math_fam(nucleus(q)); |
| 3199 |
small_char(y) = math_character(nucleus(q)); |
| 3200 |
x = do_delimiter(q, y, text_size, ok_size, false, cur_style, true, NULL, &delta, NULL); |
| 3201 |
if (delta != 0) { |
| 3202 |
if ((subscr(q) != null) && (subtype(q) != op_noad_type_limits)) { |
| 3203 |
/*tex |
| 3204 |
Here we (selectively) remove the italic correction that always gets added |
| 3205 |
in a traditional font. See (**). In \OPENTYPE\ mode we insert italic kerns, |
| 3206 |
but in traditional mode it's width manipulation. This actually makes sense |
| 3207 |
because those fonts have a fake width and the italic correction sets that |
| 3208 |
right. |
| 3209 |
*/ |
| 3210 |
width(x) -= delta; |
| 3211 |
} |
| 3212 |
} |
| 3213 |
} else { |
| 3214 |
ok_size = height_plus_depth(cur_f, cur_c) + 1; |
| 3215 |
while ((char_tag(cur_f, cur_c) == list_tag) && height_plus_depth(cur_f, cur_c) < ok_size) { |
| 3216 |
c = char_remainder(cur_f, cur_c); |
| 3217 |
if (!char_exists(cur_f, c)) |
| 3218 |
break; |
| 3219 |
cur_c = c; |
| 3220 |
math_character(nucleus(q)) = c; |
| 3221 |
} |
| 3222 |
delta = char_italic(cur_f, cur_c); |
| 3223 |
x = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 3224 |
if (delta != 0) { |
| 3225 |
if ((subscr(q) != null) && (subtype(q) != op_noad_type_limits)) { |
| 3226 |
/*tex remove italic correction */ |
| 3227 |
width(x) -= delta; |
| 3228 |
} |
| 3229 |
} |
| 3230 |
axis_shift = true; |
| 3231 |
} |
| 3232 |
} else { |
| 3233 |
/*tex normal size: $ \int\limits _a^b f(x)$ */ |
| 3234 |
delta = char_italic(cur_f, cur_c); |
| 3235 |
x = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 3236 |
if (delta != 0) { |
| 3237 |
if ((subscr(q) != null) && (subtype(q) != op_noad_type_limits)) { |
| 3238 |
/*tex remove italic correction */ |
| 3239 |
width(x) -= delta; |
| 3240 |
} |
| 3241 |
} |
| 3242 |
axis_shift = true; |
| 3243 |
} |
| 3244 |
if (axis_shift) { |
| 3245 |
/*tex center vertically */ |
| 3246 |
shift_amount(x) = half(height(x) - depth(x)) - math_axis_size(cur_size); |
| 3247 |
} |
| 3248 |
type(nucleus(q)) = sub_box_node; |
| 3249 |
math_list(nucleus(q)) = x; |
| 3250 |
} |
| 3251 |
opentype = assume_new_math(cur_f); |
| 3252 |
/*tex we now handle op_nod_type_no_limits here too */ |
| 3253 |
if (subtype(q) == op_noad_type_no_limits) { |
| 3254 |
/*tex similar code then the caller (before CHECK_DIMENSIONS) */ |
| 3255 |
p = check_nucleus_complexity(q, &delta, cur_style, NULL); |
| 3256 |
if (opentype) { |
| 3257 |
width(p) -= delta; |
| 3258 |
} |
| 3259 |
if ((subscr(q) == null) && (supscr(q) == null)) { |
| 3260 |
assign_new_hlist(q, p); |
| 3261 |
} else { |
| 3262 |
make_scripts(q, p, delta, cur_style, 0, 0); |
| 3263 |
} |
| 3264 |
} else if (subtype(q) == op_noad_type_limits) { |
| 3265 |
/*tex |
| 3266 |
|
| 3267 |
The following program builds a vlist box |v| for displayed limits. |
| 3268 |
The width of the box is not affected by the fact that the limits may |
| 3269 |
be skewed. |
| 3270 |
|
| 3271 |
*/ |
| 3272 |
x = clean_box(supscr(q), sup_style(cur_style), cur_style, math_sup_list); |
| 3273 |
y = clean_box(nucleus(q), cur_style, cur_style, math_nucleus_list); |
| 3274 |
z = clean_box(subscr(q), sub_style(cur_style), cur_style, math_sub_list); |
| 3275 |
v = new_null_box(); |
| 3276 |
reset_attributes(v, node_attr(q)); |
| 3277 |
type(v) = vlist_node; |
| 3278 |
subtype(v) = math_limits_list; |
| 3279 |
width(v) = width(y); |
| 3280 |
/* rebox fixes the width and ignores italic */ |
| 3281 |
if (width(x) > width(v)) { |
| 3282 |
width(v) = width(x); |
| 3283 |
} |
| 3284 |
if (width(z) > width(v)) { |
| 3285 |
width(v) = width(z); |
| 3286 |
} |
| 3287 |
x = rebox(x, width(v)); |
| 3288 |
y = rebox(y, width(v)); |
| 3289 |
z = rebox(z, width(v)); |
| 3290 |
shift_amount(x) = half(delta); /* sup */ |
| 3291 |
shift_amount(z) = -shift_amount(x); /* sub */ |
| 3292 |
/*tex v is the still empty target */ |
| 3293 |
height(v) = height(y); |
| 3294 |
depth(v) = depth(y); |
| 3295 |
//if (opentype) { |
| 3296 |
// width(v) -= delta; |
| 3297 |
// // delta = 0; |
| 3298 |
//} |
| 3299 |
/*tex |
| 3300 |
|
| 3301 |
Attach the limits to |y| and adjust |height(v)|, |depth(v)| to |
| 3302 |
account for their presence. |
| 3303 |
|
| 3304 |
We use |shift_up| and |shift_down| in the following program for the |
| 3305 |
amount of glue between the displayed operator |y| and its limits |x| |
| 3306 |
and |z|. |
| 3307 |
|
| 3308 |
The vlist inside box |v| will consist of |x| followed by |y| followed |
| 3309 |
by |z|, with kern nodes for the spaces between and around them; |
| 3310 |
|b| is baseline and |v| is the minumum gap. |
| 3311 |
|
| 3312 |
*/ |
| 3313 |
if (supscr(q) == null) { |
| 3314 |
list_ptr(x) = null; |
| 3315 |
flush_node(x); |
| 3316 |
list_ptr(v) = y; |
| 3317 |
} else { |
| 3318 |
shift_up = limit_above_bgap(cur_style) - depth(x); |
| 3319 |
if (shift_up < limit_above_vgap(cur_style)) |
| 3320 |
shift_up = limit_above_vgap(cur_style); |
| 3321 |
p = new_kern(shift_up); |
| 3322 |
reset_attributes(p, node_attr(q)); |
| 3323 |
couple_nodes(p,y); |
| 3324 |
couple_nodes(x,p); |
| 3325 |
p = new_kern(limit_above_kern(cur_style)); |
| 3326 |
reset_attributes(p, node_attr(q)); |
| 3327 |
couple_nodes(p,x); |
| 3328 |
list_ptr(v) = p; |
| 3329 |
height(v) = height(v) + limit_above_kern(cur_style) + height(x) + depth(x) + shift_up; |
| 3330 |
} |
| 3331 |
if (subscr(q) == null) { |
| 3332 |
list_ptr(z) = null; |
| 3333 |
flush_node(z); |
| 3334 |
} else { |
| 3335 |
shift_down = limit_below_bgap(cur_style) - height(z); |
| 3336 |
if (shift_down < limit_below_vgap(cur_style)) |
| 3337 |
shift_down = limit_below_vgap(cur_style); |
| 3338 |
p = new_kern(shift_down); |
| 3339 |
reset_attributes(p, node_attr(q)); |
| 3340 |
couple_nodes(y,p); |
| 3341 |
couple_nodes(p,z); |
| 3342 |
p = new_kern(limit_below_kern(cur_style)); |
| 3343 |
reset_attributes(p, node_attr(q)); |
| 3344 |
couple_nodes(z,p); |
| 3345 |
depth(v) = depth(v) + limit_below_kern(cur_style) + height(z) + depth(z) + shift_down; |
| 3346 |
} |
| 3347 |
if (subscr(q) != null) { |
| 3348 |
math_list(subscr(q)) = null; |
| 3349 |
flush_node(subscr(q)); |
| 3350 |
subscr(q) = null; |
| 3351 |
} |
| 3352 |
if (supscr(q) != null) { |
| 3353 |
math_list(supscr(q)) = null; |
| 3354 |
flush_node(supscr(q)); |
| 3355 |
supscr(q) = null; |
| 3356 |
} |
| 3357 |
assign_new_hlist(q, v); |
| 3358 |
} |
| 3359 |
return delta; |
| 3360 |
} |
| 3361 |
|
| 3362 |
/*tex |
| 3363 |
|
| 3364 |
A ligature found in a math formula does not create a ligature, because there |
| 3365 |
is no question of hyphenation afterwards; the ligature will simply be stored |
| 3366 |
in an ordinary |glyph_node|, after residing in an |ord_noad|. |
| 3367 |
|
| 3368 |
The |type| is converted to |math_text_char| here if we would not want to |
| 3369 |
apply an italic correction to the current character unless it belongs to a |
| 3370 |
math font (i.e., a font with |space=0|). |
| 3371 |
|
| 3372 |
No boundary characters enter into these ligatures. |
| 3373 |
|
| 3374 |
*/ |
| 3375 |
|
| 3376 |
#define simple_char_noad(p) (\ |
| 3377 |
(p != null) && \ |
| 3378 |
(type(p) == simple_noad) && \ |
| 3379 |
(subtype(p) <= punct_noad_type) && \ |
| 3380 |
(type(nucleus(p)) == math_char_node) \ |
| 3381 |
) |
| 3382 |
|
| 3383 |
#define same_nucleus_fam(p,q) \ |
| 3384 |
(math_fam(nucleus(p)) == math_fam(nucleus(q))) |
| 3385 |
|
| 3386 |
static void make_ord(pointer q) |
| 3387 |
{ |
| 3388 |
/*tex the left-side character for lig/kern testing */ |
| 3389 |
int a; |
| 3390 |
/*tex temporary registers for list manipulation */ |
| 3391 |
pointer p, r, s; |
| 3392 |
/*tex a kern */ |
| 3393 |
scaled k; |
| 3394 |
/*tex a ligature */ |
| 3395 |
liginfo lig; |
| 3396 |
RESTART: |
| 3397 |
if (subscr(q) == null && supscr(q) == null && type(nucleus(q)) == math_char_node) { |
| 3398 |
p = vlink(q); |
| 3399 |
if (simple_char_noad(p) && same_nucleus_fam(p,q)) { |
| 3400 |
type(nucleus(q)) = math_text_char_node; |
| 3401 |
fetch(nucleus(q)); |
| 3402 |
a = cur_c; |
| 3403 |
/*tex construct ligatures, quite unlikely in new math fonts */ |
| 3404 |
if ((has_kern(cur_f, a)) || (has_lig(cur_f, a))) { |
| 3405 |
cur_c = math_character(nucleus(p)); |
| 3406 |
/*tex |
| 3407 |
|
| 3408 |
If character |a| has a kern with |cur_c|, attach the kern |
| 3409 |
after~|q|; or if it has a ligature with |cur_c|, combine |
| 3410 |
noads |q| and~|p| appropriately; then |return| if the cursor |
| 3411 |
has moved past a noad, or |goto restart|. |
| 3412 |
|
| 3413 |
Note that a ligature between an |ord_noad| and another kind |
| 3414 |
of noad is replaced by an |ord_noad|, when the two noads |
| 3415 |
collapse into one. |
| 3416 |
|
| 3417 |
We could make a parenthesis (say) change shape when it |
| 3418 |
follows certain letters. Presumably a font designer will |
| 3419 |
define such ligatures only when this convention makes sense. |
| 3420 |
|
| 3421 |
*/ |
| 3422 |
if (disable_lig_par == 0 && has_lig(cur_f, a)) { |
| 3423 |
lig = get_ligature(cur_f, a, cur_c); |
| 3424 |
if (is_valid_ligature(lig)) { |
| 3425 |
/*tex allow a way out of infinite ligature loop */ |
| 3426 |
check_interrupt(); |
| 3427 |
switch (lig_type(lig)) { |
| 3428 |
case 1: |
| 3429 |
/*tex \.{=:\char`\|} */ |
| 3430 |
case 5: |
| 3431 |
/*tex \.{=:\char`\|>} */ |
| 3432 |
math_character(nucleus(q)) = lig_replacement(lig); |
| 3433 |
break; |
| 3434 |
case 2: |
| 3435 |
/*tex \.{\char`\|=:} */ |
| 3436 |
case 6: |
| 3437 |
/*tex \.{\char`\|=:>} */ |
| 3438 |
math_character(nucleus(p)) = lig_replacement(lig); |
| 3439 |
break; |
| 3440 |
case 3: |
| 3441 |
/*tex \.{\char`\|=:\char`\|} */ |
| 3442 |
case 7: |
| 3443 |
/*tex \.{\char`\|=:\char`\|>} */ |
| 3444 |
case 11: |
| 3445 |
/*tex \.{\char`\|=:\char`\|>>} */ |
| 3446 |
r = new_noad(); |
| 3447 |
reset_attributes(r, node_attr(q)); |
| 3448 |
s = new_node(math_char_node, 0); |
| 3449 |
reset_attributes(s, node_attr(q)); |
| 3450 |
nucleus(r) = s; |
| 3451 |
math_character(nucleus(r)) = lig_replacement(lig); |
| 3452 |
math_fam(nucleus(r)) = math_fam(nucleus(q)); |
| 3453 |
couple_nodes(q,r); |
| 3454 |
couple_nodes(r,p); |
| 3455 |
if (lig_type(lig) < 11) { |
| 3456 |
type(nucleus(r)) = math_char_node; |
| 3457 |
} else { |
| 3458 |
/*tex prevent combination */ |
| 3459 |
type(nucleus(r)) = math_text_char_node; |
| 3460 |
} |
| 3461 |
break; |
| 3462 |
default: |
| 3463 |
try_couple_nodes(q,vlink(p)); |
| 3464 |
math_character(nucleus(q)) = lig_replacement(lig); /* \.{=:} */ |
| 3465 |
subscr(q) = subscr(p); |
| 3466 |
supscr(q) = supscr(p); |
| 3467 |
subscr(p) = null ; |
| 3468 |
supscr(p) = null ; |
| 3469 |
flush_node(p); |
| 3470 |
break; |
| 3471 |
} |
| 3472 |
if (lig_type(lig) > 3) |
| 3473 |
return; |
| 3474 |
type(nucleus(q)) = math_char_node; |
| 3475 |
goto RESTART; |
| 3476 |
} |
| 3477 |
} |
| 3478 |
if (disable_kern_par == 0 && has_kern(cur_f, a)) { |
| 3479 |
/*tex todo: should this use mathkerns? */ |
| 3480 |
k = get_kern(cur_f, a, cur_c); |
| 3481 |
if (k != 0) { |
| 3482 |
p = new_kern(k); |
| 3483 |
reset_attributes(p, node_attr(q)); |
| 3484 |
couple_nodes(p,vlink(q)); |
| 3485 |
couple_nodes(q,p); |
| 3486 |
return; |
| 3487 |
} |
| 3488 |
} |
| 3489 |
} |
| 3490 |
} |
| 3491 |
} |
| 3492 |
} |
| 3493 |
|
| 3494 |
/*tex |
| 3495 |
|
| 3496 |
If the fonts for the left and right bits of a mathkern are not both new-style |
| 3497 |
fonts, then return a sentinel value meaning: please use old-style italic |
| 3498 |
correction placement |
| 3499 |
|
| 3500 |
*/ |
| 3501 |
|
| 3502 |
#define MATH_KERN_NOT_FOUND 0x7FFFFFFF |
| 3503 |
|
| 3504 |
/*tex |
| 3505 |
|
| 3506 |
This function tries to find the kern needed for proper cut-ins. The left side |
| 3507 |
doesn't move, but the right side does, so the first order of business is to |
| 3508 |
create a staggered fence line on the left side of the right character. |
| 3509 |
|
| 3510 |
The microsoft spec says that there are four quadrants, but the actual images |
| 3511 |
say. |
| 3512 |
|
| 3513 |
*/ |
| 3514 |
|
| 3515 |
static scaled math_kern_at(internal_font_number f, int c, int side, int v) |
| 3516 |
{ |
| 3517 |
int h, k, numkerns; |
| 3518 |
scaled *kerns_heights; |
| 3519 |
scaled kern = 0; |
| 3520 |
/*tex Known to exist: */ |
| 3521 |
charinfo *co = char_info(f, c); |
| 3522 |
numkerns = get_charinfo_math_kerns(co, side); |
| 3523 |
if (numkerns == 0) |
| 3524 |
return kern; |
| 3525 |
if (side == top_left_kern) { |
| 3526 |
kerns_heights = co->top_left_math_kern_array; |
| 3527 |
} else if (side == bottom_left_kern) { |
| 3528 |
kerns_heights = co->bottom_left_math_kern_array; |
| 3529 |
} else if (side == top_right_kern) { |
| 3530 |
kerns_heights = co->top_right_math_kern_array; |
| 3531 |
} else if (side == bottom_right_kern) { |
| 3532 |
kerns_heights = co->bottom_right_math_kern_array; |
| 3533 |
} else { |
| 3534 |
/*tex Not reached: */ |
| 3535 |
confusion("math_kern_at"); |
| 3536 |
kerns_heights = NULL; |
| 3537 |
exit(1); |
| 3538 |
} |
| 3539 |
if (v < kerns_heights[0]) |
| 3540 |
return kerns_heights[1]; |
| 3541 |
for (k = 0; k < numkerns; k++) { |
| 3542 |
h = kerns_heights[(k * 2)]; |
| 3543 |
kern = kerns_heights[(k * 2) + 1]; |
| 3544 |
if (h > v) { |
| 3545 |
return kern; |
| 3546 |
} |
| 3547 |
} |
| 3548 |
return kern; |
| 3549 |
} |
| 3550 |
|
| 3551 |
static scaled find_math_kern(internal_font_number l_f, int l_c, internal_font_number r_f, int r_c, int cmd, scaled shift) |
| 3552 |
{ |
| 3553 |
scaled corr_height_top = 0, corr_height_bot = 0; |
| 3554 |
scaled krn_l = 0, krn_r = 0, krn = 0; |
| 3555 |
if ((! assume_new_math(l_f)) || (! assume_new_math(r_f)) || (!char_exists(l_f,l_c)) || (!char_exists(r_f,r_c))) |
| 3556 |
return MATH_KERN_NOT_FOUND; |
| 3557 |
if (cmd == sup_mark_cmd) { |
| 3558 |
corr_height_top = char_height(l_f, l_c); |
| 3559 |
/*tex bottom of superscript */ |
| 3560 |
corr_height_bot = -char_depth(r_f, r_c) + shift; |
| 3561 |
krn_l = math_kern_at(l_f, l_c, top_right_kern, corr_height_top); |
| 3562 |
krn_r = math_kern_at(r_f, r_c, bottom_left_kern, corr_height_top); |
| 3563 |
krn = (krn_l + krn_r); |
| 3564 |
krn_l = math_kern_at(l_f, l_c, top_right_kern, corr_height_bot); |
| 3565 |
krn_r = math_kern_at(r_f, r_c, bottom_left_kern, corr_height_bot); |
| 3566 |
if((krn_l + krn_r) >= krn) /* was < */ |
| 3567 |
krn = (krn_l + krn_r); |
| 3568 |
return (krn); |
| 3569 |
} else if (cmd == sub_mark_cmd) { |
| 3570 |
/*tex top of subscript */ |
| 3571 |
corr_height_top = char_height(r_f, r_c) - shift; |
| 3572 |
corr_height_bot = -char_depth(l_f, l_c); |
| 3573 |
krn_l = math_kern_at(l_f, l_c, bottom_right_kern, corr_height_top); |
| 3574 |
krn_r = math_kern_at(r_f, r_c, top_left_kern, corr_height_top); |
| 3575 |
krn = (krn_l + krn_r); |
| 3576 |
krn_l = math_kern_at(l_f, l_c, bottom_right_kern, corr_height_bot); |
| 3577 |
krn_r = math_kern_at(r_f, r_c, top_left_kern, corr_height_bot); |
| 3578 |
if((krn_l + krn_r) >= krn) /* was < */ |
| 3579 |
krn = (krn_l + krn_r); |
| 3580 |
return (krn); |
| 3581 |
} else { |
| 3582 |
confusion("find_math_kern"); |
| 3583 |
} |
| 3584 |
/*tex Not reached: */ |
| 3585 |
return 0; |
| 3586 |
} |
| 3587 |
|
| 3588 |
/*tex Just a small helper: */ |
| 3589 |
|
| 3590 |
static pointer attach_hkern_to_new_hlist(pointer q, scaled delta2, halfword subtyp) |
| 3591 |
{ |
| 3592 |
pointer y; |
| 3593 |
pointer z = new_kern(delta2); |
| 3594 |
if (subtyp != 0) { |
| 3595 |
subtype(z) = subtyp; |
| 3596 |
} |
| 3597 |
reset_attributes(z, node_attr(q)); |
| 3598 |
if (new_hlist(q) == null) { |
| 3599 |
/*tex this is somewhat weird */ |
| 3600 |
new_hlist(q) = z; |
| 3601 |
} else { |
| 3602 |
y = new_hlist(q); |
| 3603 |
while (vlink(y) != null) |
| 3604 |
y = vlink(y); |
| 3605 |
couple_nodes(y,z); |
| 3606 |
} |
| 3607 |
return new_hlist(q); |
| 3608 |
} |
| 3609 |
|
| 3610 |
/*tex |
| 3611 |
|
| 3612 |
The purpose of |make_scripts(q,it)| is to attach the subscript and/or |
| 3613 |
superscript of noad |q| to the list that starts at |new_hlist(q)|, given that |
| 3614 |
subscript and superscript aren't both empty. The superscript will be |
| 3615 |
horizontally shifted over |delta1|, the subscript over |delta2|. |
| 3616 |
|
| 3617 |
We set |shift_down| and |shift_up| to the minimum amounts to shift the |
| 3618 |
baseline of subscripts and superscripts based on the given nucleus. |
| 3619 |
|
| 3620 |
Note: We need to look at a character but also at the first one in a sub list |
| 3621 |
and there we ignore leading kerns and glue. Elsewhere is code that removes |
| 3622 |
kerns assuming that is italic correction. The heuristics are unreliable for |
| 3623 |
the new fonts so eventualy there will be an option to ignore such |
| 3624 |
corrections. |
| 3625 |
|
| 3626 |
We used to use the base characters corner kerns (we only had cambria to test) |
| 3627 |
but now use the ssty ones instead. |
| 3628 |
|
| 3629 |
In the following code the |\mathscriptcharmode| and |\mathscriptboxmode| are |
| 3630 |
still present but they are obsolete. We keep them because older documentation |
| 3631 |
can then be run. |
| 3632 |
|
| 3633 |
*/ |
| 3634 |
|
| 3635 |
#define analyze_script(init,su_n,su_f,su_c) do { \ |
| 3636 |
{ \ |
| 3637 |
int saved_cur_size = cur_size; \ |
| 3638 |
if (cur_size < 2) ++cur_size; \ |
| 3639 |
su_n = init; \ |
| 3640 |
if (su_n != null) { \ |
| 3641 |
if (math_script_char_mode_par > 0 && type(su_n) == math_char_node) { \ |
| 3642 |
fetch(su_n); \ |
| 3643 |
if (char_exists(cur_f, cur_c)) { \ |
| 3644 |
su_f = cur_f; \ |
| 3645 |
su_c = cur_c; \ |
| 3646 |
} else { \ |
| 3647 |
su_n = null; \ |
| 3648 |
} \ |
| 3649 |
} else if (math_script_box_mode_par > 0 && type(su_n) == sub_mlist_node) { \ |
| 3650 |
su_n = math_list(su_n); \ |
| 3651 |
while (su_n != null) { \ |
| 3652 |
if ((type(su_n) == kern_node) || (type(su_n) == glue_node)) { \ |
| 3653 |
su_n = vlink(su_n); \ |
| 3654 |
} else if (type(su_n) == simple_noad) { \ |
| 3655 |
su_n = nucleus(su_n); \ |
| 3656 |
if (type(su_n) == math_char_node) { \ |
| 3657 |
fetch(su_n); \ |
| 3658 |
if (char_exists(cur_f, cur_c)) { \ |
| 3659 |
su_f = cur_f; \ |
| 3660 |
su_c = cur_c; \ |
| 3661 |
} else { \ |
| 3662 |
su_n = null; \ |
| 3663 |
} \ |
| 3664 |
} else { \ |
| 3665 |
su_n = null; \ |
| 3666 |
} \ |
| 3667 |
break; \ |
| 3668 |
} else { \ |
| 3669 |
su_n = null; \ |
| 3670 |
break; \ |
| 3671 |
} \ |
| 3672 |
} \ |
| 3673 |
} else if (type(su_n) == sub_box_node) { \ |
| 3674 |
su_n = math_list(su_n); \ |
| 3675 |
if (su_n != null) { \ |
| 3676 |
if (type(su_n) == hlist_node) { \ |
| 3677 |
su_n = list_ptr(su_n); \ |
| 3678 |
} \ |
| 3679 |
if (su_n != null) { \ |
| 3680 |
if (math_script_box_mode_par == 2) { \ |
| 3681 |
while (su_n != null) { \ |
| 3682 |
if ((type(su_n) == kern_node) || (type(su_n) == glue_node)) { \ |
| 3683 |
su_n = vlink(su_n); \ |
| 3684 |
} else if (type(su_n) == glyph_node) { \ |
| 3685 |
if (char_exists(font(su_n), character(su_n))) { \ |
| 3686 |
su_f = font(su_n); \ |
| 3687 |
su_c = character(su_n); \ |
| 3688 |
} else { \ |
| 3689 |
su_n = null; \ |
| 3690 |
} \ |
| 3691 |
break ; \ |
| 3692 |
} else { \ |
| 3693 |
su_n = null; \ |
| 3694 |
break; \ |
| 3695 |
} \ |
| 3696 |
} \ |
| 3697 |
} else if (math_script_box_mode_par == 3) { \ |
| 3698 |
int boundary = -1; \ |
| 3699 |
while (su_n != null) { \ |
| 3700 |
if ((type(su_n) == boundary_node) && (subtype(su_n) == user_boundary)) { \ |
| 3701 |
boundary = boundary_value(su_n); \ |
| 3702 |
su_n = vlink(su_n); \ |
| 3703 |
} else if ((type(su_n) == kern_node) || (type(su_n) == glue_node)) { \ |
| 3704 |
su_n = vlink(su_n); \ |
| 3705 |
} else if ((boundary > -1) && (type(su_n) == glyph_node)) { \ |
| 3706 |
if (char_exists(font(su_n), character(su_n))) { \ |
| 3707 |
su_f = font(su_n); \ |
| 3708 |
su_c = character(su_n); \ |
| 3709 |
} else { \ |
| 3710 |
su_n = null; \ |
| 3711 |
} \ |
| 3712 |
break ; \ |
| 3713 |
} else { \ |
| 3714 |
su_n = null; \ |
| 3715 |
break; \ |
| 3716 |
} \ |
| 3717 |
} \ |
| 3718 |
} \ |
| 3719 |
} \ |
| 3720 |
} else { \ |
| 3721 |
su_n = null; \ |
| 3722 |
} \ |
| 3723 |
} else { \ |
| 3724 |
su_n = null; \ |
| 3725 |
} \ |
| 3726 |
} \ |
| 3727 |
cur_size = saved_cur_size; \ |
| 3728 |
} \ |
| 3729 |
} while (0) \ |
| 3730 |
|
| 3731 |
|
| 3732 |
#define x_su_style(n,cur_style,su_style) \ |
| 3733 |
(noadoptionnosubscript(n) ? cur_style : su_style(cur_style)) |
| 3734 |
|
| 3735 |
/*tex |
| 3736 |
|
| 3737 |
Here |subshift| and |supshift| are no longer used. We could remove them. |
| 3738 |
|
| 3739 |
*/ |
| 3740 |
|
| 3741 |
static void make_scripts(pointer q, pointer p, scaled it, int cur_style, scaled supshift, scaled subshift) |
| 3742 |
{ |
| 3743 |
pointer x, y, z; |
| 3744 |
scaled shift_up = 0; |
| 3745 |
scaled shift_down = 0; |
| 3746 |
scaled clr = 0; |
| 3747 |
halfword sub_n = null; |
| 3748 |
halfword sup_n = null; |
| 3749 |
halfword subtyp = 0; |
| 3750 |
internal_font_number sub_f = 0; |
| 3751 |
internal_font_number sup_f = 0; |
| 3752 |
int sub_c = 0; |
| 3753 |
int sup_c = 0; |
| 3754 |
scaled delta1 = it; |
| 3755 |
scaled delta2 = 0; |
| 3756 |
switch (type(nucleus(q))) { |
| 3757 |
case math_char_node: |
| 3758 |
case math_text_char_node: |
| 3759 |
if ((subscr(q) == null) && (delta1 != 0)) { |
| 3760 |
/*tex todo: selective italic correction */ |
| 3761 |
x = new_kern(delta1); |
| 3762 |
subtype(x) = italic_kern; |
| 3763 |
reset_attributes(x, node_attr(nucleus(q))); |
| 3764 |
couple_nodes(p,x); |
| 3765 |
delta1 = 0; |
| 3766 |
} |
| 3767 |
} |
| 3768 |
assign_new_hlist(q, p); |
| 3769 |
if (is_char_node(p)) { |
| 3770 |
shift_up = 0; |
| 3771 |
shift_down = 0; |
| 3772 |
} else { |
| 3773 |
z = hpack(p, 0, additional, -1); |
| 3774 |
shift_up = height(z) - sup_shift_drop(cur_style); /* r18 */ |
| 3775 |
shift_down = depth(z) + sub_shift_drop(cur_style); /* r19 */ |
| 3776 |
list_ptr(z) = null; |
| 3777 |
flush_node(z); |
| 3778 |
} |
| 3779 |
if (is_char_node(p)) { |
| 3780 |
/*tex We look at the subscript character (_i) or first character in a list (_{ij}). */ |
| 3781 |
analyze_script(subscr(q),sub_n,sub_f,sub_c); |
| 3782 |
/*tex We look at the superscript character (^i) or first character in a list (^{ij}). */ |
| 3783 |
analyze_script(supscr(q),sup_n,sup_f,sup_c); |
| 3784 |
} |
| 3785 |
if (supscr(q) == null) { |
| 3786 |
/*tex |
| 3787 |
|
| 3788 |
Construct a subscript box |x| when there is no superscript. When |
| 3789 |
there is a subscript without a superscript, the top of the subscript |
| 3790 |
should not exceed the baseline plus four-fifths of the x-height. |
| 3791 |
|
| 3792 |
*/ |
| 3793 |
x = clean_box(subscr(q), (noadoptionnosubscript(q) ? cur_style : sub_style(cur_style)), cur_style, math_sub_list); |
| 3794 |
width(x) = width(x) + space_after_script(cur_style); |
| 3795 |
switch (math_scripts_mode_par) { |
| 3796 |
case 1: |
| 3797 |
shift_down = sub_shift_down(cur_style) ; |
| 3798 |
break; |
| 3799 |
case 2: |
| 3800 |
shift_down = sub_sup_shift_down(cur_style) ; |
| 3801 |
break; |
| 3802 |
case 3: |
| 3803 |
shift_down = sub_sup_shift_down(cur_style) ; |
| 3804 |
break; |
| 3805 |
case 4: |
| 3806 |
shift_down = sub_shift_down(cur_style) + half(sub_sup_shift_down(cur_style)-sub_shift_down(cur_style)) ; |
| 3807 |
break; |
| 3808 |
case 5: |
| 3809 |
shift_down = sub_shift_down(cur_style) ; |
| 3810 |
break; |
| 3811 |
default: |
| 3812 |
if (shift_down < sub_shift_down(cur_style)) |
| 3813 |
shift_down = sub_shift_down(cur_style); |
| 3814 |
clr = height(x) - sub_top_max(cur_style); |
| 3815 |
if (shift_down < clr) |
| 3816 |
shift_down = clr; |
| 3817 |
break; |
| 3818 |
} |
| 3819 |
shift_amount(x) = shift_down; |
| 3820 |
/*tex Now find and correct for horizontal shift. */ |
| 3821 |
subtyp = 0; |
| 3822 |
if (sub_n != null) { |
| 3823 |
delta2 = find_math_kern(font(p), character(p),sub_f,sub_c,sub_mark_cmd, shift_down); |
| 3824 |
if (delta2 == MATH_KERN_NOT_FOUND) { |
| 3825 |
delta2 = subshift ; |
| 3826 |
} else { |
| 3827 |
delta2 = delta2 + subshift ; |
| 3828 |
subtyp = font_kern; |
| 3829 |
} |
| 3830 |
} else { |
| 3831 |
delta2 = subshift ; |
| 3832 |
} |
| 3833 |
if (delta2 != 0) { |
| 3834 |
p = attach_hkern_to_new_hlist(q, delta2, subtyp); |
| 3835 |
} |
| 3836 |
} else { |
| 3837 |
/*tex |
| 3838 |
|
| 3839 |
Construct a superscript box |x|. The bottom of a superscript should |
| 3840 |
never descend below the baseline plus one-fourth of the x-height. |
| 3841 |
|
| 3842 |
*/ |
| 3843 |
x = clean_box(supscr(q), (noadoptionnosupscript(q) ? cur_style : sup_style(cur_style)), cur_style, math_sup_list); |
| 3844 |
width(x) = width(x) + space_after_script(cur_style); |
| 3845 |
switch (math_scripts_mode_par) { |
| 3846 |
case 1: |
| 3847 |
shift_up = sup_shift_up(cur_style); |
| 3848 |
break; |
| 3849 |
case 2: |
| 3850 |
shift_up = sup_shift_up(cur_style) ; |
| 3851 |
break; |
| 3852 |
case 3: |
| 3853 |
shift_up = sup_shift_up(cur_style) + sub_sup_shift_down(cur_style) - sub_shift_down(cur_style) ; |
| 3854 |
break; |
| 3855 |
case 4: |
| 3856 |
shift_up = sup_shift_up(cur_style) + half(sub_sup_shift_down(cur_style)-sub_shift_down(cur_style)) ; |
| 3857 |
break; |
| 3858 |
case 5: |
| 3859 |
shift_up = sup_shift_up(cur_style) + sub_sup_shift_down(cur_style)-sub_shift_down(cur_style) ; |
| 3860 |
break; |
| 3861 |
default: |
| 3862 |
clr = sup_shift_up(cur_style); |
| 3863 |
if (shift_up < clr) |
| 3864 |
shift_up = clr; |
| 3865 |
clr = depth(x) + sup_bottom_min(cur_style); |
| 3866 |
if (shift_up < clr) |
| 3867 |
shift_up = clr; |
| 3868 |
break; |
| 3869 |
} |
| 3870 |
if (subscr(q) == null) { |
| 3871 |
shift_amount(x) = -shift_up; |
| 3872 |
/*tex Now find and correct for horizontal shift. */ |
| 3873 |
subtyp = 0; |
| 3874 |
if (sup_n != null) { |
| 3875 |
clr = find_math_kern(font(p),character(p),sup_f,sup_c,sup_mark_cmd,shift_up); |
| 3876 |
if (clr == MATH_KERN_NOT_FOUND) { |
| 3877 |
clr = supshift ; |
| 3878 |
} else { |
| 3879 |
clr = clr + supshift ; |
| 3880 |
subtyp = font_kern; |
| 3881 |
} |
| 3882 |
} else { |
| 3883 |
clr = supshift; |
| 3884 |
} |
| 3885 |
if (clr != 0) { |
| 3886 |
p = attach_hkern_to_new_hlist(q, clr, subtyp); |
| 3887 |
} |
| 3888 |
} else { |
| 3889 |
/*tex |
| 3890 |
|
| 3891 |
Construct a sub/superscript combination box |x|, with the |
| 3892 |
superscript offset by |delta|. When both subscript and |
| 3893 |
superscript are present, the subscript must be separated from the |
| 3894 |
superscript by at least four times |default_rule_thickness| If |
| 3895 |
this condition would be violated, the subscript moves down, after |
| 3896 |
which both subscript and superscript move up so that the bottom |
| 3897 |
of the superscript is at least as high as the baseline plus |
| 3898 |
four-fifths of the x-height. |
| 3899 |
|
| 3900 |
*/ |
| 3901 |
y = clean_box(subscr(q), (noadoptionnosubscript(q) ? cur_style : sub_style(cur_style)), cur_style, math_sub_list); |
| 3902 |
width(y) = width(y) + space_after_script(cur_style); |
| 3903 |
switch (math_scripts_mode_par) { |
| 3904 |
case 1: |
| 3905 |
shift_down = sub_shift_down(cur_style) ; |
| 3906 |
break; |
| 3907 |
case 2: |
| 3908 |
shift_down = sub_sup_shift_down(cur_style) ; |
| 3909 |
break; |
| 3910 |
case 3: |
| 3911 |
shift_down = sub_sup_shift_down(cur_style) ; |
| 3912 |
break; |
| 3913 |
case 4: |
| 3914 |
shift_down = sub_shift_down(cur_style) + half(sub_sup_shift_down(cur_style)-sub_shift_down(cur_style)) ; |
| 3915 |
break; |
| 3916 |
case 5: |
| 3917 |
shift_down = sub_shift_down(cur_style) ; |
| 3918 |
break; |
| 3919 |
default: |
| 3920 |
if (shift_down < sub_sup_shift_down(cur_style)) |
| 3921 |
shift_down = sub_sup_shift_down(cur_style); |
| 3922 |
clr = subsup_vgap(cur_style) - ((shift_up - depth(x)) - (height(y) - shift_down)); |
| 3923 |
if (clr > 0) { |
| 3924 |
shift_down = shift_down + clr; |
| 3925 |
clr = sup_sub_bottom_max(cur_style) - (shift_up - depth(x)); |
| 3926 |
if (clr > 0) { |
| 3927 |
shift_up = shift_up + clr; |
| 3928 |
shift_down = shift_down - clr; |
| 3929 |
} |
| 3930 |
} |
| 3931 |
break; |
| 3932 |
} |
| 3933 |
/*tex Now find and correct for horizontal shift. */ |
| 3934 |
subtyp = 0; |
| 3935 |
if (sub_n != null) { |
| 3936 |
delta2 = find_math_kern(font(p), character(p),sub_f,sub_c,sub_mark_cmd, shift_down); |
| 3937 |
if (delta2 == MATH_KERN_NOT_FOUND) { |
| 3938 |
delta2 = subshift ; |
| 3939 |
} else { |
| 3940 |
delta2 = delta2 + subshift ; |
| 3941 |
subtyp = font_kern; |
| 3942 |
} |
| 3943 |
} else { |
| 3944 |
delta2 = subshift ; |
| 3945 |
} |
| 3946 |
if (delta2 != 0) { |
| 3947 |
p = attach_hkern_to_new_hlist(q, delta2, subtyp); |
| 3948 |
} |
| 3949 |
/*tex |
| 3950 |
|
| 3951 |
Now the horizontal shift for the superscript; the superscript is |
| 3952 |
also to be shifted by |delta1| (the italic correction). |
| 3953 |
|
| 3954 |
*/ |
| 3955 |
clr = MATH_KERN_NOT_FOUND; |
| 3956 |
if (sup_n != null) { |
| 3957 |
clr = find_math_kern(font(p),character(p),sup_f,sup_c,sup_mark_cmd,shift_up); |
| 3958 |
} |
| 3959 |
/*tex |
| 3960 |
|
| 3961 |
The delta can already have been applied and now be 0. |
| 3962 |
|
| 3963 |
*/ |
| 3964 |
if (delta2 == MATH_KERN_NOT_FOUND) |
| 3965 |
delta2 = - supshift ; |
| 3966 |
else |
| 3967 |
delta2 = delta2 - supshift ; |
| 3968 |
if (clr != MATH_KERN_NOT_FOUND) { |
| 3969 |
shift_amount(x) = clr + delta1 - delta2; |
| 3970 |
} else { |
| 3971 |
shift_amount(x) = delta1 - delta2; |
| 3972 |
} |
| 3973 |
/*tex todo: only if kern != 0 */ |
| 3974 |
p = new_kern((shift_up - depth(x)) - (height(y) - shift_down)); |
| 3975 |
reset_attributes(p, node_attr(q)); |
| 3976 |
couple_nodes(x,p); |
| 3977 |
couple_nodes(p,y); |
| 3978 |
/*tex We end up with funny dimensions. */ |
| 3979 |
x = vpackage(x, 0, additional, max_dimen, math_direction_par); |
| 3980 |
reset_attributes(x, node_attr(q)); |
| 3981 |
subtype(x) = math_scripts_list; |
| 3982 |
shift_amount(x) = shift_down; |
| 3983 |
} |
| 3984 |
} |
| 3985 |
if (new_hlist(q) == null) { |
| 3986 |
new_hlist(q) = x; |
| 3987 |
} else { |
| 3988 |
p = new_hlist(q); |
| 3989 |
while (vlink(p) != null) |
| 3990 |
p = vlink(p); |
| 3991 |
couple_nodes(p,x); |
| 3992 |
} |
| 3993 |
if (subscr(q) != null) { |
| 3994 |
math_list(subscr(q)) = null; |
| 3995 |
flush_node(subscr(q)); |
| 3996 |
subscr(q) = null; |
| 3997 |
} |
| 3998 |
if (supscr(q) != null) { |
| 3999 |
math_list(supscr(q)) = null; |
| 4000 |
flush_node(supscr(q)); |
| 4001 |
supscr(q) = null; |
| 4002 |
} |
| 4003 |
} |
| 4004 |
|
| 4005 |
/*tex |
| 4006 |
|
| 4007 |
The |make_left_right| function constructs a left or right delimiter of the |
| 4008 |
required size and returns the value |open_noad| or |close_noad|. The |
| 4009 |
|left_noad_side| and |right_noad_side| will both be based on the original |
| 4010 |
|style|, so they will have consistent sizes. |
| 4011 |
|
| 4012 |
*/ |
| 4013 |
|
| 4014 |
static small_number make_left_right(pointer q, int style, scaled max_d, scaled max_h) |
| 4015 |
{ |
| 4016 |
scaled delta; |
| 4017 |
pointer tmp, lst; |
| 4018 |
scaled ic = 0; |
| 4019 |
boolean stack = false; |
| 4020 |
boolean axis = false; |
| 4021 |
int same = subtype(q); |
| 4022 |
setup_cur_size(style); |
| 4023 |
if ((delimiterheight(q)!=0) || (delimiterdepth(q)!=0)) { |
| 4024 |
|
| 4025 |
delta = delimiterheight(q) + delimiterdepth(q); |
| 4026 |
tmp = do_delimiter(q, delimiter(q), cur_size, delta, false, style, false, &stack, &ic, &same); |
| 4027 |
delimiteritalic(q) = ic; |
| 4028 |
/*tex |
| 4029 |
|
| 4030 |
Beware, a stacked delimiter has a shift but no corrected height/depth |
| 4031 |
(yet). |
| 4032 |
|
| 4033 |
*/ |
| 4034 |
if (stack) { |
| 4035 |
shift_amount(tmp) = delimiterdepth(q); |
| 4036 |
} |
| 4037 |
if (delimiterexact(q)) { |
| 4038 |
delimiterheight(q) = height(tmp) - shift_amount(tmp); |
| 4039 |
delimiterdepth(q) = depth(tmp) + shift_amount(tmp); |
| 4040 |
} |
| 4041 |
if (delimiteraxis(q)) { |
| 4042 |
delimiterheight(q) += math_axis_size(cur_size); |
| 4043 |
delimiterdepth(q) -= math_axis_size(cur_size); |
| 4044 |
shift_amount(tmp) -= math_axis_size(cur_size); |
| 4045 |
} |
| 4046 |
lst = new_node(hlist_node,0); |
| 4047 |
reset_attributes(lst, node_attr(q)); |
| 4048 |
box_dir(lst) = dir_TLT ; |
| 4049 |
height(lst) = delimiterheight(q); |
| 4050 |
depth(lst) = delimiterdepth(q); |
| 4051 |
width(lst) = width(tmp); |
| 4052 |
list_ptr(lst) = tmp; |
| 4053 |
tmp = lst ; |
| 4054 |
} else { |
| 4055 |
axis = ! delimiternoaxis(q); |
| 4056 |
delta = get_delimiter_height(max_d,max_h,axis); |
| 4057 |
tmp = do_delimiter(q, delimiter(q), cur_size, delta, false, style, axis, &stack, &ic, &same); |
| 4058 |
delimiteritalic(q) = ic; |
| 4059 |
} |
| 4060 |
delimiter(q) = null; |
| 4061 |
assign_new_hlist(q, tmp); |
| 4062 |
delimitersamesize(q) = same; |
| 4063 |
if (delimiterclass(q) >= ord_noad_type) { |
| 4064 |
if (delimiterclass(q) <= inner_noad_type) { |
| 4065 |
return delimiterclass(q); |
| 4066 |
} else { |
| 4067 |
return ord_noad_type; |
| 4068 |
} |
| 4069 |
} else if (subtype(q) == left_noad_side) { |
| 4070 |
return open_noad_type; |
| 4071 |
} else { |
| 4072 |
return close_noad_type; |
| 4073 |
} |
| 4074 |
} |
| 4075 |
|
| 4076 |
#define TEXT_STYLES(A,B) do { \ |
| 4077 |
def_math_param(A,display_style,(B),level_one); \ |
| 4078 |
def_math_param(A,cramped_display_style,(B),level_one); \ |
| 4079 |
def_math_param(A,text_style,(B),level_one); \ |
| 4080 |
def_math_param(A,cramped_text_style,(B),level_one); \ |
| 4081 |
} while (0) |
| 4082 |
|
| 4083 |
#define SCRIPT_STYLES(A,B) do { \ |
| 4084 |
def_math_param(A,script_style,(B),level_one); \ |
| 4085 |
def_math_param(A,cramped_script_style,(B),level_one); \ |
| 4086 |
def_math_param(A,script_script_style,(B),level_one); \ |
| 4087 |
def_math_param(A,cramped_script_script_style,(B),level_one); \ |
| 4088 |
} while (0) |
| 4089 |
|
| 4090 |
#define ALL_STYLES(A,B) do { \ |
| 4091 |
TEXT_STYLES(A,(B)); \ |
| 4092 |
SCRIPT_STYLES(A,(B)); \ |
| 4093 |
} while (0) |
| 4094 |
|
| 4095 |
#define SPLIT_STYLES(A,B,C) do { \ |
| 4096 |
TEXT_STYLES(A,(B)); \ |
| 4097 |
SCRIPT_STYLES(A,(C)); \ |
| 4098 |
} while (0) |
| 4099 |
|
| 4100 |
void initialize_math_spacing(void) |
| 4101 |
{ |
| 4102 |
ALL_STYLES (math_param_ord_ord_spacing, 0); |
| 4103 |
ALL_STYLES (math_param_ord_op_spacing, thin_mu_skip_code); |
| 4104 |
SPLIT_STYLES (math_param_ord_bin_spacing, med_mu_skip_code, 0); |
| 4105 |
SPLIT_STYLES (math_param_ord_rel_spacing, thick_mu_skip_code, 0); |
| 4106 |
ALL_STYLES (math_param_ord_open_spacing, 0); |
| 4107 |
ALL_STYLES (math_param_ord_close_spacing, 0); |
| 4108 |
ALL_STYLES (math_param_ord_punct_spacing, 0); |
| 4109 |
SPLIT_STYLES (math_param_ord_inner_spacing, thin_mu_skip_code, 0); |
| 4110 |
|
| 4111 |
ALL_STYLES (math_param_op_ord_spacing, thin_mu_skip_code); |
| 4112 |
ALL_STYLES (math_param_op_op_spacing, thin_mu_skip_code); |
| 4113 |
ALL_STYLES (math_param_op_bin_spacing, 0); |
| 4114 |
SPLIT_STYLES (math_param_op_rel_spacing, thick_mu_skip_code, 0); |
| 4115 |
ALL_STYLES (math_param_op_open_spacing, 0); |
| 4116 |
ALL_STYLES (math_param_op_close_spacing, 0); |
| 4117 |
ALL_STYLES (math_param_op_punct_spacing, 0); |
| 4118 |
SPLIT_STYLES (math_param_op_inner_spacing, thin_mu_skip_code, 0); |
| 4119 |
|
| 4120 |
SPLIT_STYLES (math_param_bin_ord_spacing, med_mu_skip_code, 0); |
| 4121 |
SPLIT_STYLES (math_param_bin_op_spacing, med_mu_skip_code, 0); |
| 4122 |
ALL_STYLES (math_param_bin_bin_spacing, 0); |
| 4123 |
ALL_STYLES (math_param_bin_rel_spacing, 0); |
| 4124 |
SPLIT_STYLES (math_param_bin_open_spacing, med_mu_skip_code, 0); |
| 4125 |
ALL_STYLES (math_param_bin_close_spacing, 0); |
| 4126 |
ALL_STYLES (math_param_bin_punct_spacing, 0); |
| 4127 |
SPLIT_STYLES (math_param_bin_inner_spacing, med_mu_skip_code, 0); |
| 4128 |
|
| 4129 |
SPLIT_STYLES (math_param_rel_ord_spacing, thick_mu_skip_code, 0); |
| 4130 |
SPLIT_STYLES (math_param_rel_op_spacing, thick_mu_skip_code, 0); |
| 4131 |
ALL_STYLES (math_param_rel_bin_spacing, 0); |
| 4132 |
ALL_STYLES (math_param_rel_rel_spacing, 0); |
| 4133 |
SPLIT_STYLES (math_param_rel_open_spacing, thick_mu_skip_code, 0); |
| 4134 |
ALL_STYLES (math_param_rel_close_spacing, 0); |
| 4135 |
ALL_STYLES (math_param_rel_punct_spacing, 0); |
| 4136 |
SPLIT_STYLES (math_param_rel_inner_spacing, thick_mu_skip_code, 0); |
| 4137 |
|
| 4138 |
ALL_STYLES (math_param_open_ord_spacing, 0); |
| 4139 |
ALL_STYLES (math_param_open_op_spacing, 0); |
| 4140 |
ALL_STYLES (math_param_open_bin_spacing, 0); |
| 4141 |
ALL_STYLES (math_param_open_rel_spacing, 0); |
| 4142 |
ALL_STYLES (math_param_open_open_spacing, 0); |
| 4143 |
ALL_STYLES (math_param_open_close_spacing, 0); |
| 4144 |
ALL_STYLES (math_param_open_punct_spacing, 0); |
| 4145 |
ALL_STYLES (math_param_open_inner_spacing, 0); |
| 4146 |
|
| 4147 |
ALL_STYLES (math_param_close_ord_spacing, 0); |
| 4148 |
ALL_STYLES (math_param_close_op_spacing, thin_mu_skip_code); |
| 4149 |
SPLIT_STYLES (math_param_close_bin_spacing, med_mu_skip_code, 0); |
| 4150 |
SPLIT_STYLES (math_param_close_rel_spacing, thick_mu_skip_code, 0); |
| 4151 |
ALL_STYLES (math_param_close_open_spacing, 0); |
| 4152 |
ALL_STYLES (math_param_close_close_spacing, 0); |
| 4153 |
ALL_STYLES (math_param_close_punct_spacing, 0); |
| 4154 |
SPLIT_STYLES (math_param_close_inner_spacing, thin_mu_skip_code, 0); |
| 4155 |
|
| 4156 |
SPLIT_STYLES (math_param_punct_ord_spacing, thin_mu_skip_code, 0); |
| 4157 |
SPLIT_STYLES (math_param_punct_op_spacing, thin_mu_skip_code, 0); |
| 4158 |
ALL_STYLES (math_param_punct_bin_spacing, 0); |
| 4159 |
SPLIT_STYLES (math_param_punct_rel_spacing, thin_mu_skip_code, 0); |
| 4160 |
SPLIT_STYLES (math_param_punct_open_spacing, thin_mu_skip_code, 0); |
| 4161 |
SPLIT_STYLES (math_param_punct_close_spacing, thin_mu_skip_code, 0); |
| 4162 |
SPLIT_STYLES (math_param_punct_punct_spacing, thin_mu_skip_code, 0); |
| 4163 |
SPLIT_STYLES (math_param_punct_inner_spacing, thin_mu_skip_code, 0); |
| 4164 |
|
| 4165 |
SPLIT_STYLES (math_param_inner_ord_spacing, thin_mu_skip_code, 0); |
| 4166 |
ALL_STYLES (math_param_inner_op_spacing, thin_mu_skip_code); |
| 4167 |
SPLIT_STYLES (math_param_inner_bin_spacing, med_mu_skip_code, 0); |
| 4168 |
SPLIT_STYLES (math_param_inner_rel_spacing, thick_mu_skip_code, 0); |
| 4169 |
SPLIT_STYLES (math_param_inner_open_spacing, thin_mu_skip_code, 0); |
| 4170 |
ALL_STYLES (math_param_inner_close_spacing, 0); |
| 4171 |
SPLIT_STYLES (math_param_inner_punct_spacing, thin_mu_skip_code, 0); |
| 4172 |
SPLIT_STYLES (math_param_inner_inner_spacing, thin_mu_skip_code, 0); |
| 4173 |
} |
| 4174 |
|
| 4175 |
#define both_types(A,B) ((A)*16+(B)) |
| 4176 |
|
| 4177 |
static pointer math_spacing_glue(int l_type, int r_type, int mstyle, scaled mmu) |
| 4178 |
{ |
| 4179 |
int x = -1; |
| 4180 |
pointer z = null; |
| 4181 |
if (l_type == op_noad_type_limits || l_type == op_noad_type_no_limits) |
| 4182 |
l_type = op_noad_type_normal; |
| 4183 |
if (r_type == op_noad_type_limits || r_type == op_noad_type_no_limits) |
| 4184 |
r_type = op_noad_type_normal; |
| 4185 |
switch (both_types(l_type, r_type)) { |
| 4186 |
case both_types(ord_noad_type, ord_noad_type ): x = get_math_param(math_param_ord_ord_spacing,mstyle); break; |
| 4187 |
case both_types(ord_noad_type, op_noad_type_normal): x = get_math_param(math_param_ord_op_spacing,mstyle); break; |
| 4188 |
case both_types(ord_noad_type, bin_noad_type ): x = get_math_param(math_param_ord_bin_spacing,mstyle); break; |
| 4189 |
case both_types(ord_noad_type, rel_noad_type ): x = get_math_param(math_param_ord_rel_spacing,mstyle); break; |
| 4190 |
case both_types(ord_noad_type, open_noad_type ): x = get_math_param(math_param_ord_open_spacing,mstyle); break; |
| 4191 |
case both_types(ord_noad_type, close_noad_type ): x = get_math_param(math_param_ord_close_spacing,mstyle); break; |
| 4192 |
case both_types(ord_noad_type, punct_noad_type ): x = get_math_param(math_param_ord_punct_spacing,mstyle); break; |
| 4193 |
case both_types(ord_noad_type, inner_noad_type ): x = get_math_param(math_param_ord_inner_spacing,mstyle); break; |
| 4194 |
case both_types(op_noad_type_normal, ord_noad_type ): x = get_math_param(math_param_op_ord_spacing,mstyle); break; |
| 4195 |
case both_types(op_noad_type_normal, op_noad_type_normal): x = get_math_param(math_param_op_op_spacing,mstyle); break; |
| 4196 |
/* shouldn't happen */ |
| 4197 |
case both_types(op_noad_type_normal, bin_noad_type ): x = get_math_param(math_param_op_bin_spacing,mstyle); break; |
| 4198 |
/* */ |
| 4199 |
case both_types(op_noad_type_normal, rel_noad_type ): x = get_math_param(math_param_op_rel_spacing,mstyle); break; |
| 4200 |
case both_types(op_noad_type_normal, open_noad_type ): x = get_math_param(math_param_op_open_spacing,mstyle); break; |
| 4201 |
case both_types(op_noad_type_normal, close_noad_type ): x = get_math_param(math_param_op_close_spacing,mstyle); break; |
| 4202 |
case both_types(op_noad_type_normal, punct_noad_type ): x = get_math_param(math_param_op_punct_spacing,mstyle); break; |
| 4203 |
case both_types(op_noad_type_normal, inner_noad_type ): x = get_math_param(math_param_op_inner_spacing,mstyle); break; |
| 4204 |
case both_types(bin_noad_type, ord_noad_type ): x = get_math_param(math_param_bin_ord_spacing,mstyle); break; |
| 4205 |
case both_types(bin_noad_type, op_noad_type_normal): x = get_math_param(math_param_bin_op_spacing,mstyle); break; |
| 4206 |
/* shouldn't happen */ |
| 4207 |
case both_types(bin_noad_type, bin_noad_type ): x = get_math_param(math_param_bin_bin_spacing,mstyle); break; |
| 4208 |
case both_types(bin_noad_type, rel_noad_type ): x = get_math_param(math_param_bin_rel_spacing,mstyle); break; |
| 4209 |
/* */ |
| 4210 |
case both_types(bin_noad_type, open_noad_type ): x = get_math_param(math_param_bin_open_spacing,mstyle); break; |
| 4211 |
/* shouldn't happen */ |
| 4212 |
case both_types(bin_noad_type, close_noad_type ): x = get_math_param(math_param_bin_close_spacing,mstyle); break; |
| 4213 |
case both_types(bin_noad_type, punct_noad_type ): x = get_math_param(math_param_bin_punct_spacing,mstyle); break; |
| 4214 |
/* */ |
| 4215 |
case both_types(bin_noad_type, inner_noad_type ): x = get_math_param(math_param_bin_inner_spacing,mstyle); break; |
| 4216 |
case both_types(rel_noad_type, ord_noad_type ): x = get_math_param(math_param_rel_ord_spacing,mstyle); break; |
| 4217 |
case both_types(rel_noad_type, op_noad_type_normal): x = get_math_param(math_param_rel_op_spacing,mstyle); break; |
| 4218 |
/* shouldn't happen */ |
| 4219 |
case both_types(rel_noad_type, bin_noad_type ): x = get_math_param(math_param_rel_bin_spacing,mstyle); break; |
| 4220 |
/* */ |
| 4221 |
case both_types(rel_noad_type, rel_noad_type ): x = get_math_param(math_param_rel_rel_spacing,mstyle); break; |
| 4222 |
case both_types(rel_noad_type, open_noad_type ): x = get_math_param(math_param_rel_open_spacing,mstyle); break; |
| 4223 |
case both_types(rel_noad_type, close_noad_type ): x = get_math_param(math_param_rel_close_spacing,mstyle); break; |
| 4224 |
case both_types(rel_noad_type, punct_noad_type ): x = get_math_param(math_param_rel_punct_spacing,mstyle); break; |
| 4225 |
case both_types(rel_noad_type, inner_noad_type ): x = get_math_param(math_param_rel_inner_spacing,mstyle); break; |
| 4226 |
case both_types(open_noad_type, ord_noad_type ): x = get_math_param(math_param_open_ord_spacing,mstyle); break; |
| 4227 |
case both_types(open_noad_type, op_noad_type_normal): x = get_math_param(math_param_open_op_spacing,mstyle); break; |
| 4228 |
/* shouldn't happen */ |
| 4229 |
case both_types(open_noad_type, bin_noad_type ): x = get_math_param(math_param_open_bin_spacing,mstyle); break; |
| 4230 |
/* */ |
| 4231 |
case both_types(open_noad_type, rel_noad_type ): x = get_math_param(math_param_open_rel_spacing,mstyle); break; |
| 4232 |
case both_types(open_noad_type, open_noad_type ): x = get_math_param(math_param_open_open_spacing,mstyle); break; |
| 4233 |
case both_types(open_noad_type, close_noad_type ): x = get_math_param(math_param_open_close_spacing,mstyle); break; |
| 4234 |
case both_types(open_noad_type, punct_noad_type ): x = get_math_param(math_param_open_punct_spacing,mstyle); break; |
| 4235 |
case both_types(open_noad_type, inner_noad_type ): x = get_math_param(math_param_open_inner_spacing,mstyle); break; |
| 4236 |
case both_types(close_noad_type, ord_noad_type ): x = get_math_param(math_param_close_ord_spacing,mstyle); break; |
| 4237 |
case both_types(close_noad_type, op_noad_type_normal): x = get_math_param(math_param_close_op_spacing,mstyle); break; |
| 4238 |
case both_types(close_noad_type, bin_noad_type ): x = get_math_param(math_param_close_bin_spacing,mstyle); break; |
| 4239 |
case both_types(close_noad_type, rel_noad_type ): x = get_math_param(math_param_close_rel_spacing,mstyle); break; |
| 4240 |
case both_types(close_noad_type, open_noad_type ): x = get_math_param(math_param_close_open_spacing,mstyle); break; |
| 4241 |
case both_types(close_noad_type, close_noad_type ): x = get_math_param(math_param_close_close_spacing,mstyle); break; |
| 4242 |
case both_types(close_noad_type, punct_noad_type ): x = get_math_param(math_param_close_punct_spacing,mstyle); break; |
| 4243 |
case both_types(close_noad_type, inner_noad_type ): x = get_math_param(math_param_close_inner_spacing,mstyle); break; |
| 4244 |
case both_types(punct_noad_type, ord_noad_type ): x = get_math_param(math_param_punct_ord_spacing,mstyle); break; |
| 4245 |
case both_types(punct_noad_type, op_noad_type_normal): x = get_math_param(math_param_punct_op_spacing,mstyle); break; |
| 4246 |
/* shouldn't happen */ |
| 4247 |
case both_types(punct_noad_type, bin_noad_type ): x = get_math_param(math_param_punct_bin_spacing,mstyle); break; |
| 4248 |
/* */ |
| 4249 |
case both_types(punct_noad_type, rel_noad_type ): x = get_math_param(math_param_punct_rel_spacing,mstyle); break; |
| 4250 |
case both_types(punct_noad_type, open_noad_type ): x = get_math_param(math_param_punct_open_spacing,mstyle); break; |
| 4251 |
case both_types(punct_noad_type, close_noad_type ): x = get_math_param(math_param_punct_close_spacing,mstyle); break; |
| 4252 |
case both_types(punct_noad_type, punct_noad_type ): x = get_math_param(math_param_punct_punct_spacing,mstyle); break; |
| 4253 |
case both_types(punct_noad_type, inner_noad_type ): x = get_math_param(math_param_punct_inner_spacing,mstyle); break; |
| 4254 |
case both_types(inner_noad_type, ord_noad_type ): x = get_math_param(math_param_inner_ord_spacing,mstyle); break; |
| 4255 |
case both_types(inner_noad_type, op_noad_type_normal): x = get_math_param(math_param_inner_op_spacing,mstyle); break; |
| 4256 |
case both_types(inner_noad_type, bin_noad_type ): x = get_math_param(math_param_inner_bin_spacing,mstyle); break; |
| 4257 |
case both_types(inner_noad_type, rel_noad_type ): x = get_math_param(math_param_inner_rel_spacing,mstyle); break; |
| 4258 |
case both_types(inner_noad_type, open_noad_type ): x = get_math_param(math_param_inner_open_spacing,mstyle); break; |
| 4259 |
case both_types(inner_noad_type, close_noad_type ): x = get_math_param(math_param_inner_close_spacing,mstyle); break; |
| 4260 |
case both_types(inner_noad_type, punct_noad_type ): x = get_math_param(math_param_inner_punct_spacing,mstyle); break; |
| 4261 |
case both_types(inner_noad_type, inner_noad_type ): x = get_math_param(math_param_inner_inner_spacing,mstyle); break; |
| 4262 |
} |
| 4263 |
if (x < 0) { |
| 4264 |
confusion("mathspacing"); |
| 4265 |
} |
| 4266 |
if (x != 0) { |
| 4267 |
if (x <= thick_mu_skip_code) { |
| 4268 |
/*tex trap thin/med/thick settings cf.\ old \TeX */ |
| 4269 |
z = math_glue(glue_par(x), mmu); |
| 4270 |
/*tex store a symbolic subtype */ |
| 4271 |
subtype(z) = (quarterword) (x + 1); |
| 4272 |
} else { |
| 4273 |
z = math_glue(x, mmu); |
| 4274 |
} |
| 4275 |
} |
| 4276 |
return z; |
| 4277 |
} |
| 4278 |
|
| 4279 |
static pointer check_nucleus_complexity(halfword q, scaled * delta, int cur_style, int *same) |
| 4280 |
{ |
| 4281 |
pointer p = null; |
| 4282 |
pointer t = null; |
| 4283 |
if (same) { |
| 4284 |
*same = 0; |
| 4285 |
} |
| 4286 |
switch (type(nucleus(q))) { |
| 4287 |
case math_char_node: |
| 4288 |
case math_text_char_node: |
| 4289 |
fetch(nucleus(q)); |
| 4290 |
if (char_exists(cur_f, cur_c)) { |
| 4291 |
/*tex we could look at neighbours */ |
| 4292 |
*delta = char_italic(cur_f, cur_c); |
| 4293 |
p = new_glyph(cur_f, cur_c); |
| 4294 |
protect_glyph_node(p); |
| 4295 |
reset_attributes(p, node_attr(nucleus(q))); |
| 4296 |
// /*tex no italic correction in mid-word of text font */ |
| 4297 |
// if (((type(nucleus(q))) == math_text_char_node) && (space(cur_f) != 0)) { |
| 4298 |
// *delta = 0; |
| 4299 |
// } |
| 4300 |
/*tex so we only add italic correction when we have no scripts */ |
| 4301 |
if ((subscr(q) == null) && (supscr(q) == null) && (*delta != 0)) { |
| 4302 |
pointer x = new_kern(*delta); |
| 4303 |
subtype(x) = italic_kern; |
| 4304 |
reset_attributes(x, node_attr(nucleus(q))); |
| 4305 |
couple_nodes(p,x); |
| 4306 |
*delta = 0; |
| 4307 |
} |
| 4308 |
} |
| 4309 |
break; |
| 4310 |
case sub_box_node: |
| 4311 |
p = math_list(nucleus(q)); |
| 4312 |
break; |
| 4313 |
case sub_mlist_node: |
| 4314 |
t = math_list(nucleus(q)); |
| 4315 |
/*tex Recursive call: */ |
| 4316 |
mlist_to_hlist(t, false, cur_style); |
| 4317 |
if (same != NULL && type(t) == fence_noad && delimitersamesize(t)) { |
| 4318 |
*same = delimitersamesize(t) ; |
| 4319 |
} |
| 4320 |
setup_cur_size(cur_style); |
| 4321 |
p = hpack(vlink(temp_head), 0, additional, -1); |
| 4322 |
reset_attributes(p, node_attr(nucleus(q))); |
| 4323 |
break; |
| 4324 |
default: |
| 4325 |
confusion("mlist2"); |
| 4326 |
} |
| 4327 |
return p; |
| 4328 |
} |
| 4329 |
|
| 4330 |
/*tex |
| 4331 |
|
| 4332 |
Here is the overall plan of |mlist_to_hlist|, and the list of its local |
| 4333 |
variables. |
| 4334 |
|
| 4335 |
*/ |
| 4336 |
|
| 4337 |
void mlist_to_hlist(pointer mlist, boolean penalties, int cur_style) |
| 4338 |
{ |
| 4339 |
/*tex runs through the mlist */ |
| 4340 |
pointer q = mlist; |
| 4341 |
/*tex the most recent noad preceding |q| */ |
| 4342 |
pointer r = null; |
| 4343 |
/*tex tuck global parameter away as local variable */ |
| 4344 |
int style = cur_style; |
| 4345 |
/*tex the |type| of noad |r|, or |op_noad| if |r=null| */ |
| 4346 |
int r_type = simple_noad; |
| 4347 |
/*tex the |subtype| of noad |r| if |r_type| is |fence_noad| */ |
| 4348 |
int r_subtype = op_noad_type_normal; |
| 4349 |
/*tex the effective |type| of noad |q| during the second pass */ |
| 4350 |
int t; |
| 4351 |
/*tex the effective |subtype| of noad |q| during the second pass */ |
| 4352 |
int t_subtype; |
| 4353 |
pointer p = null; |
| 4354 |
pointer pp = null; |
| 4355 |
pointer z = null; |
| 4356 |
int same = 0; |
| 4357 |
/*tex a penalty to be inserted */ |
| 4358 |
int pen; |
| 4359 |
/*tex a penalty to be inserted */ |
| 4360 |
int prepen; |
| 4361 |
/*tex maximum height of the list translated so far */ |
| 4362 |
scaled max_hl = 0; |
| 4363 |
/*tex maximum depth of the list translated so far */ |
| 4364 |
scaled max_d = 0; |
| 4365 |
/*tex italic correction offset for subscript and superscript */ |
| 4366 |
scaled delta; |
| 4367 |
/*tex the math unit width corresponding to |cur_size| */ |
| 4368 |
scaled cur_mu; |
| 4369 |
r_subtype = op_noad_type_normal; |
| 4370 |
setup_cur_size(cur_style); |
| 4371 |
cur_mu = x_over_n(get_math_quad_size(cur_size), 18); |
| 4372 |
if (math_penalties_mode_par) { |
| 4373 |
/*tex |
| 4374 |
We could do this via the callback but it's nice to have it as |
| 4375 |
primitive too. |
| 4376 |
*/ |
| 4377 |
penalties = 1; |
| 4378 |
} |
| 4379 |
while (q != null) { |
| 4380 |
/*tex |
| 4381 |
|
| 4382 |
We use the fact that no character nodes appear in an mlist, hence the |
| 4383 |
field |type(q)| is always present.One of the things we must do on the |
| 4384 |
first pass is change a |bin_noad| to an |ord_noad| if the |bin_noad| |
| 4385 |
is not in the context of a binary operator. The values of |r| and |
| 4386 |
|r_type| make this fairly easy. |
| 4387 |
|
| 4388 |
*/ |
| 4389 |
RESWITCH: |
| 4390 |
delta = 0; |
| 4391 |
switch (type(q)) { |
| 4392 |
case simple_noad: |
| 4393 |
switch (subtype(q)) { |
| 4394 |
case bin_noad_type: |
| 4395 |
switch (r_type) { |
| 4396 |
case simple_noad: |
| 4397 |
switch (r_subtype) { |
| 4398 |
case bin_noad_type: |
| 4399 |
case op_noad_type_normal: |
| 4400 |
case op_noad_type_limits: |
| 4401 |
case op_noad_type_no_limits: |
| 4402 |
case rel_noad_type: |
| 4403 |
case open_noad_type: |
| 4404 |
case punct_noad_type: |
| 4405 |
subtype(q) = ord_noad_type; |
| 4406 |
goto RESWITCH; |
| 4407 |
break; |
| 4408 |
} |
| 4409 |
break; |
| 4410 |
case fence_noad: |
| 4411 |
if (r_subtype == left_noad_side) { |
| 4412 |
/*tex So these can best be the same size. */ |
| 4413 |
subtype(q) = ord_noad_type; |
| 4414 |
goto RESWITCH; |
| 4415 |
} |
| 4416 |
break; |
| 4417 |
} |
| 4418 |
break; |
| 4419 |
case over_noad_type: |
| 4420 |
make_over(q, cur_style, cur_size, math_rules_fam_par); |
| 4421 |
break; |
| 4422 |
case under_noad_type: |
| 4423 |
make_under(q, cur_style, cur_size, math_rules_fam_par); |
| 4424 |
break; |
| 4425 |
case vcenter_noad_type: |
| 4426 |
make_vcenter(q); |
| 4427 |
break; |
| 4428 |
case rel_noad_type: |
| 4429 |
case close_noad_type: |
| 4430 |
case punct_noad_type: |
| 4431 |
if (r_type == simple_noad && r_subtype == bin_noad_type) { |
| 4432 |
/*tex Assumes the same size; can't this go. */ |
| 4433 |
type(r) = simple_noad; |
| 4434 |
subtype(r) = ord_noad_type; |
| 4435 |
} |
| 4436 |
break; |
| 4437 |
case op_noad_type_normal: |
| 4438 |
case op_noad_type_limits: |
| 4439 |
case op_noad_type_no_limits: |
| 4440 |
delta = make_op(q, cur_style); |
| 4441 |
if ((subtype(q) == op_noad_type_limits) || (subtype(q) == op_noad_type_no_limits)) |
| 4442 |
goto CHECK_DIMENSIONS; |
| 4443 |
break; |
| 4444 |
case ord_noad_type: |
| 4445 |
make_ord(q); |
| 4446 |
break; |
| 4447 |
case open_noad_type: |
| 4448 |
case inner_noad_type: |
| 4449 |
break; |
| 4450 |
} |
| 4451 |
break; |
| 4452 |
case fence_noad: |
| 4453 |
if (subtype(q) != left_noad_side) { |
| 4454 |
if (r_type == simple_noad && r_subtype == bin_noad_type) { |
| 4455 |
/*tex Assumes the same size. */ |
| 4456 |
type(r) = simple_noad; |
| 4457 |
subtype(r) = ord_noad_type; |
| 4458 |
} |
| 4459 |
} |
| 4460 |
goto DONE_WITH_NOAD; |
| 4461 |
break; |
| 4462 |
case fraction_noad: |
| 4463 |
make_fraction(q, cur_style); |
| 4464 |
goto CHECK_DIMENSIONS; |
| 4465 |
break; |
| 4466 |
case radical_noad: |
| 4467 |
if (subtype(q) == 7) |
| 4468 |
make_hextension(q, cur_style); |
| 4469 |
else if (subtype(q) == 6) |
| 4470 |
make_delimiter_over(q, cur_style); |
| 4471 |
else if (subtype(q) == 5) |
| 4472 |
make_delimiter_under(q, cur_style); |
| 4473 |
else if (subtype(q) == 4) |
| 4474 |
make_over_delimiter(q, cur_style); |
| 4475 |
else if (subtype(q) == 3) |
| 4476 |
make_under_delimiter(q, cur_style); |
| 4477 |
else |
| 4478 |
make_radical(q, cur_style); |
| 4479 |
break; |
| 4480 |
case accent_noad: |
| 4481 |
make_math_accent(q, cur_style); |
| 4482 |
break; |
| 4483 |
case style_node: |
| 4484 |
cur_style = subtype(q); |
| 4485 |
setup_cur_size(cur_style); |
| 4486 |
cur_mu = x_over_n(get_math_quad_style(cur_style), 18); |
| 4487 |
goto DONE_WITH_NODE; |
| 4488 |
break; |
| 4489 |
case choice_node: |
| 4490 |
switch (cur_style / 2) { |
| 4491 |
case 0: |
| 4492 |
/*tex |display_style=0| */ |
| 4493 |
choose_mlist(display_mlist); |
| 4494 |
break; |
| 4495 |
case 1: |
| 4496 |
/*tex |text_style=2| */ |
| 4497 |
choose_mlist(text_mlist); |
| 4498 |
break; |
| 4499 |
case 2: |
| 4500 |
/*tex |script_style=4| */ |
| 4501 |
choose_mlist(script_mlist); |
| 4502 |
break; |
| 4503 |
case 3: |
| 4504 |
/*tex |script_script_style=6| */ |
| 4505 |
choose_mlist(script_script_mlist); |
| 4506 |
break; |
| 4507 |
} |
| 4508 |
flush_node_list(display_mlist(q)); |
| 4509 |
flush_node_list(text_mlist(q)); |
| 4510 |
flush_node_list(script_mlist(q)); |
| 4511 |
flush_node_list(script_script_mlist(q)); |
| 4512 |
type(q) = style_node; |
| 4513 |
subtype(q) = (quarterword) cur_style; |
| 4514 |
if (p != null) { |
| 4515 |
z = vlink(q); |
| 4516 |
couple_nodes(q,p); |
| 4517 |
while (vlink(p) != null) |
| 4518 |
p = vlink(p); |
| 4519 |
try_couple_nodes(p,z); |
| 4520 |
} |
| 4521 |
goto DONE_WITH_NODE; |
| 4522 |
break; |
| 4523 |
case ins_node: |
| 4524 |
case mark_node: |
| 4525 |
case adjust_node: |
| 4526 |
case boundary_node: |
| 4527 |
case whatsit_node: |
| 4528 |
case penalty_node: |
| 4529 |
case disc_node: |
| 4530 |
goto DONE_WITH_NODE; |
| 4531 |
break; |
| 4532 |
case rule_node: |
| 4533 |
if (height(q) > max_hl) |
| 4534 |
max_hl = height(q); |
| 4535 |
if (depth(q) > max_d) |
| 4536 |
max_d = depth(q); |
| 4537 |
goto DONE_WITH_NODE; |
| 4538 |
break; |
| 4539 |
case glue_node: |
| 4540 |
/*tex |
| 4541 |
|
| 4542 |
Conditional math glue (`\.{\\nonscript}') results in a |
| 4543 |
|glue_node| pointing to |zero_glue|, with |
| 4544 |
|subtype(q)=cond_math_glue|; in such a case the node |
| 4545 |
following will be eliminated if it is a glue or kern node and |
| 4546 |
if the current size is different from |text_size|. |
| 4547 |
|
| 4548 |
Unconditional math glue (`\.{\\muskip}') is converted to |
| 4549 |
normal glue by multiplying the dimensions by |cur_mu|. |
| 4550 |
|
| 4551 |
*/ |
| 4552 |
if (subtype(q) == mu_glue) { |
| 4553 |
math_glue_to_glue(q, cur_mu); |
| 4554 |
} else if ((cur_size != text_size) && (subtype(q) == cond_math_glue)) { |
| 4555 |
p = vlink(q); |
| 4556 |
if (p != null) |
| 4557 |
if ((type(p) == glue_node) || (type(p) == kern_node)) { |
| 4558 |
if (vlink(p) != null) { |
| 4559 |
couple_nodes(q,vlink(p)); |
| 4560 |
vlink(p) = null; |
| 4561 |
} else { |
| 4562 |
vlink(q) = null; |
| 4563 |
} |
| 4564 |
flush_node_list(p); |
| 4565 |
} |
| 4566 |
} |
| 4567 |
goto DONE_WITH_NODE; |
| 4568 |
break; |
| 4569 |
case kern_node: |
| 4570 |
math_kern(q, cur_mu); |
| 4571 |
goto DONE_WITH_NODE; |
| 4572 |
break; |
| 4573 |
default: |
| 4574 |
confusion("mlist1"); |
| 4575 |
} |
| 4576 |
/*tex |
| 4577 |
|
| 4578 |
When we get to the following part of the program, we have ``fallen |
| 4579 |
through'' from cases that did not lead to |check_dimensions| or |
| 4580 |
|done_with_noad| or |done_with_node|. Thus, |q|~points to a noad |
| 4581 |
whose nucleus may need to be converted to an hlist, and whose |
| 4582 |
subscripts and superscripts need to be appended if they are present. |
| 4583 |
|
| 4584 |
If |nucleus(q)| is not a |math_char|, the variable |delta| is the |
| 4585 |
amount by which a superscript should be moved right with respect to a |
| 4586 |
subscript when both are present. |
| 4587 |
|
| 4588 |
*/ |
| 4589 |
same = 0 ; |
| 4590 |
p = check_nucleus_complexity(q, &delta, cur_style, &same); |
| 4591 |
if (same) { |
| 4592 |
noadextra4(q) = same ; |
| 4593 |
} |
| 4594 |
if ((subscr(q) == null) && (supscr(q) == null)) { |
| 4595 |
/*tex |
| 4596 |
|
| 4597 |
Adding italic correction here is kind of fuzzy because some |
| 4598 |
characters already have that built in. However, we also add it in |
| 4599 |
the scripts so if it's optional here it also should be there. |
| 4600 |
|
| 4601 |
*/ |
| 4602 |
assign_new_hlist(q, p); |
| 4603 |
} else { |
| 4604 |
/*tex top, bottom */ |
| 4605 |
make_scripts(q, p, delta, cur_style, 0, 0); |
| 4606 |
} |
| 4607 |
CHECK_DIMENSIONS: |
| 4608 |
z = hpack(new_hlist(q), 0, additional, -1); |
| 4609 |
if (height(z) > max_hl) |
| 4610 |
max_hl = height(z); |
| 4611 |
if (depth(z) > max_d) |
| 4612 |
max_d = depth(z); |
| 4613 |
list_ptr(z) = null; |
| 4614 |
/*tex only drop the \.{\\hbox} */ |
| 4615 |
flush_node(z); |
| 4616 |
DONE_WITH_NOAD: |
| 4617 |
r = q; |
| 4618 |
r_type = type(r); |
| 4619 |
r_subtype = subtype(r); |
| 4620 |
if (r_type == fence_noad) { |
| 4621 |
r_subtype = left_noad_side; |
| 4622 |
cur_style = style; |
| 4623 |
setup_cur_size(cur_style); |
| 4624 |
/*tex style */ |
| 4625 |
cur_mu = x_over_n(get_math_quad_size(cur_size), 18); |
| 4626 |
} |
| 4627 |
DONE_WITH_NODE: |
| 4628 |
q = vlink(q); |
| 4629 |
} |
| 4630 |
if (r_type == simple_noad && r_subtype == bin_noad_type) { |
| 4631 |
type(r) = simple_noad; |
| 4632 |
subtype(r) = ord_noad_type; |
| 4633 |
} |
| 4634 |
/*tex |
| 4635 |
|
| 4636 |
Make a second pass over the mlist, removing all noads and inserting the |
| 4637 |
proper spacing and penalties. |
| 4638 |
|
| 4639 |
We have now tied up all the loose ends of the first pass of |
| 4640 |
|mlist_to_hlist|. The second pass simply goes through and hooks |
| 4641 |
everything together with the proper glue and penalties. It also handles |
| 4642 |
the |fence_noad|s that might be present, since |max_hl| and |max_d| are |
| 4643 |
now known. Variable |p| points to a node at the current end of the final |
| 4644 |
hlist. |
| 4645 |
|
| 4646 |
*/ |
| 4647 |
p = temp_head; |
| 4648 |
vlink(p) = null; |
| 4649 |
q = mlist; |
| 4650 |
r_type = 0; |
| 4651 |
r_subtype = 0; |
| 4652 |
cur_style = style; |
| 4653 |
setup_cur_size(cur_style); |
| 4654 |
cur_mu = x_over_n(get_math_quad_size(cur_size), 18); |
| 4655 |
NEXT_NODE: |
| 4656 |
while (q != null) { |
| 4657 |
/*tex |
| 4658 |
|
| 4659 |
If node |q| is a style node, change the style and |goto delete_q|; |
| 4660 |
otherwise if it is not a noad, put it into the hlist, advance |q|, |
| 4661 |
and |goto done|; otherwise set |s| to the size of noad |q|, set |t| |
| 4662 |
to the associated type (|ord_noad.. inner_noad|), and set |pen| to |
| 4663 |
the associated penalty. |
| 4664 |
|
| 4665 |
Just before doing the big |case| switch in the second pass, the |
| 4666 |
program sets up default values so that most of the branches are |
| 4667 |
short. |
| 4668 |
|
| 4669 |
*/ |
| 4670 |
t = simple_noad; |
| 4671 |
t_subtype = ord_noad_type; |
| 4672 |
pen = inf_penalty; |
| 4673 |
prepen = inf_penalty; |
| 4674 |
switch (type(q)) { |
| 4675 |
case simple_noad: |
| 4676 |
t_subtype = subtype(q); |
| 4677 |
switch (t_subtype) { |
| 4678 |
case bin_noad_type: |
| 4679 |
pen = bin_op_penalty_par; |
| 4680 |
prepen = pre_bin_op_penalty_par; |
| 4681 |
break; |
| 4682 |
case rel_noad_type: |
| 4683 |
pen = rel_penalty_par; |
| 4684 |
prepen = pre_rel_penalty_par; |
| 4685 |
break; |
| 4686 |
case vcenter_noad_type: |
| 4687 |
case over_noad_type: |
| 4688 |
case under_noad_type: |
| 4689 |
t_subtype = ord_noad_type; |
| 4690 |
break; |
| 4691 |
} |
| 4692 |
case radical_noad: |
| 4693 |
break; |
| 4694 |
case accent_noad: |
| 4695 |
break; |
| 4696 |
case fraction_noad: |
| 4697 |
t = simple_noad; |
| 4698 |
t_subtype = inner_noad_type; |
| 4699 |
break; |
| 4700 |
case fence_noad: |
| 4701 |
t_subtype = make_left_right(q, style, max_d, max_hl); |
| 4702 |
break; |
| 4703 |
case style_node: |
| 4704 |
/*tex Change the current style and |goto delete_q| */ |
| 4705 |
cur_style = subtype(q); |
| 4706 |
setup_cur_size(cur_style); |
| 4707 |
cur_mu = x_over_n(get_math_quad_style(cur_style), 18); |
| 4708 |
goto DELETE_Q; |
| 4709 |
break; |
| 4710 |
case whatsit_node: |
| 4711 |
case penalty_node: |
| 4712 |
case rule_node: |
| 4713 |
case disc_node: |
| 4714 |
case adjust_node: |
| 4715 |
case ins_node: |
| 4716 |
case mark_node: |
| 4717 |
case glue_node: |
| 4718 |
case kern_node: |
| 4719 |
couple_nodes(p,q); |
| 4720 |
p = q; |
| 4721 |
q = vlink(q); |
| 4722 |
vlink(p) = null; |
| 4723 |
goto NEXT_NODE; |
| 4724 |
break; |
| 4725 |
default: |
| 4726 |
confusion("mlist3"); |
| 4727 |
} |
| 4728 |
/*tex Append inter-element spacing based on |r_type| and |t| */ |
| 4729 |
if (r_type > 0) { |
| 4730 |
/*tex not the first noad */ |
| 4731 |
pp = p; |
| 4732 |
if (delimitermodeordinal && t_subtype == inner_noad_type && noadextra4(q) == 1) { |
| 4733 |
z = math_spacing_glue(r_subtype, ord_noad_type, cur_style, cur_mu); |
| 4734 |
} else { |
| 4735 |
z = math_spacing_glue(r_subtype, t_subtype, cur_style, cur_mu); |
| 4736 |
} |
| 4737 |
if (z != null) { |
| 4738 |
reset_attributes(z, node_attr(p)); |
| 4739 |
couple_nodes(p,z); |
| 4740 |
p = z; |
| 4741 |
} |
| 4742 |
if (penalties && prepen < inf_penalty && type(pp) != penalty_node) { |
| 4743 |
/*tex no checking of prev node type */ |
| 4744 |
z = new_penalty(prepen,noad_penalty); |
| 4745 |
reset_attributes(z, node_attr(p)); |
| 4746 |
couple_nodes(p,z); |
| 4747 |
p = z; |
| 4748 |
} |
| 4749 |
} |
| 4750 |
/*tex |
| 4751 |
|
| 4752 |
Append any |new_hlist| entries for |q|, and any appropriate |
| 4753 |
penalties. We insert a penalty node after the hlist entries of noad |
| 4754 |
|q| if |pen| is not an ``infinite'' penalty, and if the node |
| 4755 |
immediately following |q| is not a penalty node or a |rel_noad| or |
| 4756 |
absent entirely. |
| 4757 |
|
| 4758 |
*/ |
| 4759 |
if (new_hlist(q) != null) { |
| 4760 |
couple_nodes(p,new_hlist(q)); |
| 4761 |
do { |
| 4762 |
p = vlink(p); |
| 4763 |
} while (vlink(p) != null); |
| 4764 |
} |
| 4765 |
if (penalties && vlink(q) != null && pen < inf_penalty) { |
| 4766 |
r_type = type(vlink(q)); |
| 4767 |
r_subtype = subtype(vlink(q)); |
| 4768 |
if (r_type != penalty_node && (r_type != simple_noad || r_subtype != rel_noad_type)) { |
| 4769 |
z = new_penalty(pen,noad_penalty); |
| 4770 |
reset_attributes(z, node_attr(q)); |
| 4771 |
couple_nodes(p,z); |
| 4772 |
p = z; |
| 4773 |
} |
| 4774 |
} |
| 4775 |
if (type(q) == fence_noad && subtype(q) == right_noad_side) { |
| 4776 |
t = simple_noad; |
| 4777 |
t_subtype = open_noad_type; |
| 4778 |
} |
| 4779 |
r_type = t; |
| 4780 |
r_subtype = t_subtype; |
| 4781 |
DELETE_Q: |
| 4782 |
r = q; |
| 4783 |
q = vlink(q); |
| 4784 |
/*tex |
| 4785 |
|
| 4786 |
The m-to-hlist conversion takes place in-place, so the various |
| 4787 |
dependant fields may not be freed (as would happen if |flush_node| |
| 4788 |
was called). A low-level |free_node| is easier than attempting to |
| 4789 |
nullify such dependant fields for all possible node and noad types. |
| 4790 |
|
| 4791 |
*/ |
| 4792 |
if (nodetype_has_attributes(type(r))) { |
| 4793 |
delete_attribute_ref(node_attr(r)); |
| 4794 |
} |
| 4795 |
reset_node_properties(r); |
| 4796 |
free_node(r, get_node_size(type(r), subtype(r))); |
| 4797 |
} |
| 4798 |
} |