Support \textup and \textmd (#1921)

* Support \textup and \textmd

This PR adds support for `\textup` and `\textmd`, which are the inverses of
`\textit` and `\textbf`.  Unlike bare `\text`, they result in `textup` and
`textmd` classes being applied, but those have no CSS rules, so they act the
same as bare `\text`.

Fixes #1909.

* Add documentation

* Add unsupported font commands
This commit is contained in:
Erik Demaine
2019-04-05 13:51:11 -04:00
committed by ylemkimon
parent ac4c6271d4
commit 070883532a
5 changed files with 56 additions and 17 deletions

View File

@@ -36,6 +36,10 @@ const sizeAtStyle = function(size: number, style: StyleInterface): number {
return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
};
// In these types, "" (empty string) means "no change".
export type FontWeight = "textbf" | "textmd" | "";
export type FontShape = "textit" | "textup" | "";
export type OptionsData = {
style: StyleInterface;
color?: string | void;
@@ -44,8 +48,8 @@ export type OptionsData = {
phantom?: boolean;
font?: string;
fontFamily?: string;
fontWeight?: string;
fontShape?: string;
fontWeight?: FontWeight;
fontShape?: FontShape;
sizeMultiplier?: number;
maxSize: number;
};
@@ -68,8 +72,8 @@ class Options {
// See: https://tex.stackexchange.com/questions/22350/difference-between-textrm-and-mathrm
font: string;
fontFamily: string;
fontWeight: string;
fontShape: string;
fontWeight: FontWeight;
fontShape: FontShape;
sizeMultiplier: number;
maxSize: number;
_fontMetrics: FontMetrics | void;
@@ -244,7 +248,7 @@ class Options {
/**
* Creates a new options object with the given font weight
*/
withTextFontWeight(fontWeight: string): Options {
withTextFontWeight(fontWeight: FontWeight): Options {
return this.extend({
fontWeight,
font: "",
@@ -254,7 +258,7 @@ class Options {
/**
* Creates a new options object with the given font weight
*/
withTextFontShape(fontShape: string): Options {
withTextFontShape(fontShape: FontShape): Options {
return this.extend({
fontShape,
font: "",

View File

@@ -13,10 +13,12 @@ const textFontFamilies = {
const textFontWeights = {
"\\textbf": "textbf",
"\\textmd": "textmd",
};
const textFontShapes = {
"\\textit": "textit",
"\\textup": "textup",
};
const optionsWithFont = (group, options) => {
@@ -39,9 +41,9 @@ defineFunction({
// Font families
"\\text", "\\textrm", "\\textsf", "\\texttt", "\\textnormal",
// Font weights
"\\textbf",
"\\textbf", "\\textmd",
// Font Shapes
"\\textit",
"\\textit", "\\textup",
],
props: {
numArgs: 1,