Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Implement \pmb via CSS text-shadow #3505

Merged
merged 3 commits into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions contrib/render-a11y-string/render-a11y-string.js
Expand Up @@ -392,6 +392,11 @@ const handleObject = (
break;
}

case "pmb": {
a11yStrings.push("bold");
break;
}

case "phantom": {
a11yStrings.push("empty space");
break;
Expand Down
1 change: 1 addition & 0 deletions src/domTree.js
Expand Up @@ -153,6 +153,7 @@ export type CssStyle = $Shape<{
minWidth: string,
paddingLeft: string,
position: string,
textShadow: string,
top: string,
width: string,
verticalAlign: string,
Expand Down
1 change: 1 addition & 0 deletions src/functions.js
Expand Up @@ -10,6 +10,7 @@ export default functions;
import "./functions/accent";
import "./functions/accentunder";
import "./functions/arrow";
import "./functions/pmb";
import "./environments/cd";
import "./functions/char";
import "./functions/color";
Expand Down
44 changes: 44 additions & 0 deletions src/functions/pmb.js
@@ -0,0 +1,44 @@
// @flow
import defineFunction, {ordargument} from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
import {binrelClass} from "./mclass";

import type {ParseNode} from "../parseNode";

// \pmb is a simulation of bold font.
// The version of \pmb in ambsy.sty works by typesetting three copies
// with small offsets. We use CSS text-shadow.
// It's a hack. Not as good as a real bold font. Better than nothing.

defineFunction({
type: "pmb",
names: ["\\pmb"],
props: {
numArgs: 1,
allowedInText: true,
},
handler({parser}, args) {
return {
type: "pmb",
mode: parser.mode,
mclass: binrelClass(args[0]),
body: ordargument(args[0]),
};
},
htmlBuilder(group: ParseNode<"pmb">, options) {
const elements = html.buildExpression(group.body, options, true);
const node = buildCommon.makeSpan([group.mclass], elements, options);
node.style.textShadow = "0.02em 0.01em 0.04px";
return node;
},
mathmlBuilder(group: ParseNode<"pmb">, style) {
const inner = mml.buildExpression(group.body, style);
// Wrap with an <mstyle> element.
const node = new mathMLTree.MathNode("mstyle", inner);
node.setAttribute("style", "text-shadow: 0.02em 0.01em 0.04px");
return node;
},
});
8 changes: 0 additions & 8 deletions src/macros.js
Expand Up @@ -597,14 +597,6 @@ defineMacro("\\mod", "\\allowbreak" +
"\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}" +
"{\\rm mod}\\,\\,#1");

// \pmb -- A simulation of bold.
// The version in ambsy.sty works by typesetting three copies of the argument
// with small offsets. We use two copies. We omit the vertical offset because
// of rendering problems that makeVList encounters in Safari.
defineMacro("\\pmb", "\\html@mathml{" +
"\\@binrel{#1}{\\mathrlap{#1}\\kern0.5px#1}}" +
"{\\mathbf{#1}}");

//////////////////////////////////////////////////////////////////////
// LaTeX source2e

Expand Down
7 changes: 7 additions & 0 deletions src/parseNode.js
Expand Up @@ -414,6 +414,13 @@ type ParseNodeTypes = {
loc?: ?SourceLocation,
body: AnyParseNode,
|},
"pmb": {|
type: "pmb",
mode: Mode,
loc?: ?SourceLocation,
mclass: string,
body: AnyParseNode[],
|},
"raisebox": {|
type: "raisebox",
mode: Mode,
Expand Down
Binary file modified test/screenshotter/images/Pmb-chrome.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshotter/images/Pmb-firefox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshotter/images/Pmb-safari.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.