mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
\copyright, \textregistered, \textcircled support (#1073)
* \copyright support * Implement \textcircled, \copyright, \textregistered
This commit is contained in:
committed by
Kevin Barabash
parent
f01f504cfe
commit
b74b2374e2
@@ -63,7 +63,7 @@ const htmlBuilder = (group, options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate the amount of space between the body and the accent
|
// calculate the amount of space between the body and the accent
|
||||||
const clearance = Math.min(
|
let clearance = Math.min(
|
||||||
body.height,
|
body.height,
|
||||||
options.fontMetrics().xHeight);
|
options.fontMetrics().xHeight);
|
||||||
|
|
||||||
@@ -91,17 +91,34 @@ const htmlBuilder = (group, options) => {
|
|||||||
|
|
||||||
accentBody = buildCommon.makeSpan(["accent-body"], [accent]);
|
accentBody = buildCommon.makeSpan(["accent-body"], [accent]);
|
||||||
|
|
||||||
// CSS defines `.katex .accent .accent-body { width: 0 }`
|
// "Full" accents expand the width of the resulting symbol to be
|
||||||
|
// at least the width of the accent, and overlap directly onto the
|
||||||
|
// character without any vertical offset.
|
||||||
|
const accentFull = (group.value.label === "\\textcircled");
|
||||||
|
if (accentFull) {
|
||||||
|
accentBody.classes.push('accent-full');
|
||||||
|
clearance = body.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shift the accent over by the skew.
|
||||||
|
let left = skew;
|
||||||
|
|
||||||
|
// CSS defines `.katex .accent .accent-body:not(.accent-full) { width: 0 }`
|
||||||
// so that the accent doesn't contribute to the bounding box.
|
// so that the accent doesn't contribute to the bounding box.
|
||||||
// We need to shift the character by its width (effectively half
|
// We need to shift the character by its width (effectively half
|
||||||
// its width) to compensate.
|
// its width) to compensate.
|
||||||
let left = -width / 2;
|
if (!accentFull) {
|
||||||
|
left -= width / 2;
|
||||||
// Shift the accent over by the skew.
|
}
|
||||||
left += skew;
|
|
||||||
|
|
||||||
accentBody.style.left = left + "em";
|
accentBody.style.left = left + "em";
|
||||||
|
|
||||||
|
// \textcircled uses the \bigcirc glyph, so it needs some
|
||||||
|
// vertical adjustment to match LaTeX.
|
||||||
|
if (group.value.label === "\\textcircled") {
|
||||||
|
accentBody.style.top = ".2em";
|
||||||
|
}
|
||||||
|
|
||||||
accentBody = buildCommon.makeVList({
|
accentBody = buildCommon.makeVList({
|
||||||
positionType: "firstBaseline",
|
positionType: "firstBaseline",
|
||||||
children: [
|
children: [
|
||||||
@@ -215,7 +232,7 @@ defineFunction({
|
|||||||
type: "accent",
|
type: "accent",
|
||||||
names: [
|
names: [
|
||||||
"\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"',
|
"\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"',
|
||||||
"\\r", "\\H", "\\v",
|
"\\r", "\\H", "\\v", "\\textcircled",
|
||||||
],
|
],
|
||||||
props: {
|
props: {
|
||||||
numArgs: 1,
|
numArgs: 1,
|
||||||
|
@@ -401,8 +401,13 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.accent-body {
|
// Accents that are not of the accent-full class have zero width
|
||||||
|
// (do not contribute to the width of the final symbol).
|
||||||
|
.accent-body:not(.accent-full) {
|
||||||
width: 0;
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accent-body {
|
||||||
position: relative; // so that 'left' can shift the accent
|
position: relative; // so that 'left' can shift the accent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -117,6 +117,16 @@ defineMacro("\\rbrack", "]");
|
|||||||
defineMacro("\\aa", "\\r a");
|
defineMacro("\\aa", "\\r a");
|
||||||
defineMacro("\\AA", "\\r A");
|
defineMacro("\\AA", "\\r A");
|
||||||
|
|
||||||
|
// \DeclareTextCommandDefault{\textcopyright}{\textcircled{c}}
|
||||||
|
// \DeclareTextCommandDefault{\textregistered}{\textcircled{%
|
||||||
|
// \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont R}}
|
||||||
|
// \DeclareRobustCommand{\copyright}{%
|
||||||
|
// \ifmmode{\nfss@text{\textcopyright}}\else\textcopyright\fi}
|
||||||
|
defineMacro("\\textcopyright", "\\textcircled{c}");
|
||||||
|
defineMacro("\\copyright",
|
||||||
|
"\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}");
|
||||||
|
defineMacro("\\textregistered", "\\textcircled{\\scriptsize R}");
|
||||||
|
|
||||||
// Unicode double-struck letters
|
// Unicode double-struck letters
|
||||||
defineMacro("\u2102", "\\mathbb{C}");
|
defineMacro("\u2102", "\\mathbb{C}");
|
||||||
defineMacro("\u210D", "\\mathbb{H}");
|
defineMacro("\u210D", "\\mathbb{H}");
|
||||||
|
@@ -697,6 +697,7 @@ defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
|
|||||||
defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
|
defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
|
||||||
defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
|
defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
|
||||||
defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
|
defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
|
||||||
|
defineSymbol(text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
|
||||||
|
|
||||||
defineSymbol(text, main, textord, "\u2013", "--");
|
defineSymbol(text, main, textord, "\u2013", "--");
|
||||||
defineSymbol(text, main, textord, "\u2013", "\\textendash");
|
defineSymbol(text, main, textord, "\u2013", "\\textendash");
|
||||||
|
Reference in New Issue
Block a user