Skip to content

Commit 8eda1e3

Browse files
authored
Merge pull request #546 from mathjax/issue2514
Fix issue with \textit, etc., not working with textmacros extension. (mathjax/MathJax#2514)
2 parents ee74a83 + 744bef9 commit 8eda1e3

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

ts/input/tex/ParseUtil.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ namespace ParseUtil {
236236
* @param {TexParser} parser The calling parser.
237237
* @param {string} text The text in the math expression to parse.
238238
* @param {number|string=} level The scriptlevel.
239+
* @param {string} font The mathvariant to use
239240
* @return {MmlNode[]} The nodes corresponding to the internal math expression.
240241
*/
241242
export function internalMath(parser: TexParser, text: string,
242-
level?: number | string): MmlNode[] {
243+
level?: number | string, font?: string): MmlNode[] {
243244
if (parser.configuration.options.internalMath) {
244-
return parser.configuration.options.internalMath(parser, text, level);
245+
return parser.configuration.options.internalMath(parser, text, level, font);
245246
}
246-
let def = (parser.stack.env['font'] ? {mathvariant: parser.stack.env['font']} : {});
247+
let mathvariant = font || parser.stack.env.font;
248+
let def = (mathvariant ? {mathvariant} : {});
247249
let mml: MmlNode[] = [], i = 0, k = 0, c, node, match = '', braces = 0;
248250
if (text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {
249251
while (i < text.length) {

ts/input/tex/base/BaseMappings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ new sm.CommandMap('macros', {
620620
mathfrak: ['Macro', '{\\frak #1}', 1],
621621
mathsf: ['Macro', '{\\sf #1}', 1],
622622
mathtt: ['Macro', '{\\tt #1}', 1],
623-
textrm: ['Macro', '\\mathord{\\rm\\text{#1}}', 1],
624-
textit: ['Macro', '\\mathord{\\it\\text{#1}}', 1],
625-
textbf: ['Macro', '\\mathord{\\bf\\text{#1}}', 1],
626-
textsf: ['Macro', '\\mathord{\\sf\\text{#1}}', 1],
627-
texttt: ['Macro', '\\mathord{\\tt\\text{#1}}', 1],
623+
textrm: ['HBox', null, TexConstant.Variant.NORMAL],
624+
textit: ['HBox', null, TexConstant.Variant.ITALIC],
625+
textbf: ['HBox', null, TexConstant.Variant.BOLD],
626+
textsf: ['HBox', null, TexConstant.Variant.SANSSERIF],
627+
texttt: ['HBox', null, TexConstant.Variant.MONOSPACE],
628628
pmb: ['Macro', '\\rlap{#1}\\kern1px{#1}', 1],
629629
TeX: ['Macro', 'T\\kern-.14em\\lower.5ex{E}\\kern-.115em X'],
630630
LaTeX: ['Macro', 'L\\kern-.325em\\raise.21em' +

ts/input/tex/base/BaseMethods.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,11 @@ BaseMethods.BuildRel = function(parser: TexParser, name: string) {
10031003
* @param {TexParser} parser The calling parser.
10041004
* @param {string} name The macro name.
10051005
* @param {string} style Box style.
1006+
* @param {string} font The mathvariant to use
10061007
*/
1007-
BaseMethods.HBox = function(parser: TexParser, name: string, style: string) {
1008+
BaseMethods.HBox = function(parser: TexParser, name: string, style: string, font?: string) {
10081009
// @test Hbox
1009-
parser.PushAll(ParseUtil.internalMath(parser, parser.GetArgument(name), style));
1010+
parser.PushAll(ParseUtil.internalMath(parser, parser.GetArgument(name), style, font));
10101011
};
10111012

10121013
/**

ts/input/tex/textmacros/TextMacrosConfiguration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ export const textBase = Configuration.local({
7979
* @param {TexParser} parser The TexParser calling this function
8080
* @param {string} text The text-mode string to be processed
8181
* @param {number|string} level The scriptlevel of the text
82+
* @param {string} mathvariant The mathvariant for the text
8283
* @return {MmlNode[]} The final MmlNode generated for the text
8384
*/
84-
function internalMath(parser: TexParser, text: string, level?: number | string): MmlNode[] {
85+
function internalMath(parser: TexParser, text: string, level?: number | string, mathvariant?: string): MmlNode[] {
8586
const config = parser.configuration.packageData.get('textmacros');
8687
if (!(parser instanceof TextParser)) {
8788
config.texParser = parser;
8889
}
89-
return [(new TextParser(text, {}, config.parseOptions, level)).mml()];
90+
return [(new TextParser(text, mathvariant ? {mathvariant} : {}, config.parseOptions, level)).mml()];
9091
}
9192

9293
//

ts/input/tex/textmacros/TextParser.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ export class TextParser extends TexParser {
106106
*/
107107
public saveText() {
108108
if (this.text) {
109-
const text = ParseUtil.internalText(this, this.text, {});
110-
if (this.stack.env.mathvariant) {
111-
NodeUtil.setAttribute(text, 'mathvariant', this.stack.env.mathvariant);
112-
}
109+
const mathvariant = this.stack.env.mathvariant;
110+
const text = ParseUtil.internalText(this, this.text, mathvariant ? {mathvariant} : {});
113111
this.text = '';
114112
this.Push(text);
115113
}

0 commit comments

Comments
 (0)