\copyright, \textregistered, \textcircled support (#1073)

* \copyright support

* Implement \textcircled, \copyright, \textregistered
This commit is contained in:
Erik Demaine
2018-05-07 20:44:40 -04:00
committed by Kevin Barabash
parent f01f504cfe
commit b74b2374e2
4 changed files with 41 additions and 8 deletions

View File

@@ -63,7 +63,7 @@ const htmlBuilder = (group, options) => {
}
// calculate the amount of space between the body and the accent
const clearance = Math.min(
let clearance = Math.min(
body.height,
options.fontMetrics().xHeight);
@@ -91,17 +91,34 @@ const htmlBuilder = (group, options) => {
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.
// We need to shift the character by its width (effectively half
// its width) to compensate.
let left = -width / 2;
// Shift the accent over by the skew.
left += skew;
if (!accentFull) {
left -= width / 2;
}
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({
positionType: "firstBaseline",
children: [
@@ -215,7 +232,7 @@ defineFunction({
type: "accent",
names: [
"\\'", "\\`", "\\^", "\\~", "\\=", "\\u", "\\.", '\\"',
"\\r", "\\H", "\\v",
"\\r", "\\H", "\\v", "\\textcircled",
],
props: {
numArgs: 1,

View File

@@ -401,8 +401,13 @@
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;
}
.accent-body {
position: relative; // so that 'left' can shift the accent
}
}

View File

@@ -117,6 +117,16 @@ defineMacro("\\rbrack", "]");
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
defineMacro("\u2102", "\\mathbb{C}");
defineMacro("\u210D", "\\mathbb{H}");

View File

@@ -697,6 +697,7 @@ defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
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", "\\textendash");