mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
Support for \raisebox (#685)
* Rough support for \raisebox * Fix bounding box thanks to @kevinbarash and @ronkok * Use calculateSize to support all currently supported units (ex, em, mu). * Shift height and depth in all cases. * Add screenshot test * Rename transform -> raisebox * Switch to normalsize in raisebox * Attempt at using makeVList * Significant rewrite, now working well * rename textFunctionStyles to textFunctionFonts
This commit is contained in:
committed by
Kevin Barabash
parent
6857689946
commit
ca224eda81
@@ -304,7 +304,7 @@ groupTypes.ordgroup = function(group, options) {
|
||||
};
|
||||
|
||||
groupTypes.text = function(group, options) {
|
||||
const newOptions = options.withFont(group.value.style);
|
||||
const newOptions = options.withFont(group.value.font);
|
||||
const inner = buildExpression(group.value.body, newOptions, true);
|
||||
for (let i = 0; i < inner.length - 1; i++) {
|
||||
if (inner[i].tryCombine(inner[i + 1])) {
|
||||
@@ -1631,6 +1631,24 @@ groupTypes.mclass = function(group, options) {
|
||||
return makeSpan([group.value.mclass], elements, options);
|
||||
};
|
||||
|
||||
groupTypes.raisebox = function(group, options) {
|
||||
const body = groupTypes.sizing({value: {
|
||||
value: [{
|
||||
type: "text",
|
||||
value: {
|
||||
body: group.value.body,
|
||||
font: "mathrm", // simulate \textrm
|
||||
},
|
||||
}],
|
||||
size: 6, // simulate \normalsize
|
||||
}}, options);
|
||||
const dy = units.calculateSize(group.value.dy.value, options);
|
||||
return buildCommon.makeVList([{
|
||||
type: "elem",
|
||||
elem: body,
|
||||
}], "shift", -dy, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* buildGroup is the function that takes a group and calls the correct groupType
|
||||
* function for it. It also handles the interaction of size and style changes
|
||||
|
@@ -601,6 +601,10 @@ groupTypes.mclass = function(group, options) {
|
||||
return new mathMLTree.MathNode("mstyle", inner);
|
||||
};
|
||||
|
||||
// Transforms (translation/rotation) don't seem to have a representation
|
||||
// in MathML, so just treat them like \text{...}
|
||||
groupTypes.raisebox = groupTypes.text;
|
||||
|
||||
/**
|
||||
* Takes a list of nodes, builds them, and returns a list of the generated
|
||||
* MathML nodes. A little simpler than the HTML version because we don't do any
|
||||
|
@@ -32,7 +32,7 @@ defineFunction("\\sqrt", {
|
||||
});
|
||||
|
||||
// Non-mathy text, possibly in a font
|
||||
const textFunctionStyles = {
|
||||
const textFunctionFonts = {
|
||||
"\\text": undefined, "\\textrm": "mathrm", "\\textsf": "mathsf",
|
||||
"\\texttt": "mathtt", "\\textnormal": "mathrm", "\\textbf": "mathbf",
|
||||
"\\textit": "textit",
|
||||
@@ -51,7 +51,7 @@ defineFunction([
|
||||
return {
|
||||
type: "text",
|
||||
body: ordargument(body),
|
||||
style: textFunctionStyles[context.funcName],
|
||||
font: textFunctionFonts[context.funcName],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -650,3 +650,18 @@ defineFunction(["\\begin", "\\end"], {
|
||||
nameGroup: nameGroup,
|
||||
};
|
||||
});
|
||||
|
||||
// Box manipulation
|
||||
defineFunction(["\\raisebox"], {
|
||||
numArgs: 2,
|
||||
argTypes: ["size", "text"],
|
||||
allowedInText: true,
|
||||
}, function(context, args) {
|
||||
const amount = args[0];
|
||||
const body = args[1];
|
||||
return {
|
||||
type: "raisebox",
|
||||
dy: amount,
|
||||
body: ordargument(body),
|
||||
};
|
||||
});
|
||||
|
BIN
test/screenshotter/images/Raisebox-chrome.png
Normal file
BIN
test/screenshotter/images/Raisebox-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
test/screenshotter/images/Raisebox-firefox.png
Normal file
BIN
test/screenshotter/images/Raisebox-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@@ -186,6 +186,7 @@ OverUnderset: |
|
||||
Phantom: \dfrac{1+\phantom{x^{\blue{2}}} = x}{1+x^{\blue{2}} = x} \left(\vphantom{\int_t} zzz \right) \left( X \hphantom{\frac{\frac X X}{X}} \right)
|
||||
PrimeSpacing: f'+f_2'+f^{f'}
|
||||
PrimeSuper: x'^2+x'''^2+x'^2_3+x_3'^2
|
||||
Raisebox: \frac{a}{a\raisebox{0.5em}{b}} \cdot \frac{a\raisebox{-0.5em}{b}}{a} \cdot \sqrt{a\raisebox{0.5em}{b}} \cdot \sqrt{a\raisebox{-0.5em}{b}} \cdot \sqrt{a\raisebox{0.5em}{b}\raisebox{-0.5em}{b}}
|
||||
RelativeUnits: |
|
||||
\begin{array}{ll}
|
||||
a\kern1emb^{a\kern1emb^{a\kern1emb}} &
|
||||
|
Reference in New Issue
Block a user