-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 all AMS mathord symbols #618
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
17f861a
Fix all AMS mathord symbols
edemaine 9b29f46
Fix \imath, \jmath, \pounds support
edemaine b91f8ff
Fix \mathit support
edemaine 7dc0ad2
Fix Greek capitals
edemaine 7a28993
Default font to main (fix Unicode support)
edemaine 2386a75
Now using correct \maltese
edemaine 5b318e9
Correct mathit documentation
edemaine bf40271
Merge remote-tracking branch 'upstream/master' into box
edemaine 85f5e9f
var -> const
edemaine b14093c
Add trailing commas
edemaine 2ae3091
Remove greekCapitals (no longer needed)
edemaine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ var fontMetrics = require("./fontMetrics"); | |
var symbols = require("./symbols"); | ||
var utils = require("./utils"); | ||
|
||
/* No longer needed; see mathit below. | ||
var greekCapitals = [ | ||
"\\Gamma", | ||
"\\Delta", | ||
|
@@ -22,14 +23,30 @@ var greekCapitals = [ | |
"\\Psi", | ||
"\\Omega" | ||
]; | ||
*/ | ||
|
||
// The following have to be loaded from Main-Italic font, using class mainit | ||
var mainitLetters = [ | ||
"\u0131", // dotless i, \imath | ||
"\u0237", // dotless j, \jmath | ||
"\u00a3" // \pounds | ||
"\\imath", // dotless i | ||
"\\jmath", // dotless j | ||
"\\pounds" // pounds symbol | ||
]; | ||
|
||
/** | ||
* Looks up the given symbol in fontMetrics, after applying any symbol | ||
* replacements defined in symbol.js | ||
*/ | ||
var lookupSymbol = function(value, fontFamily, mode) { | ||
// Replace the value with its replaced value from symbol.js | ||
if (symbols[mode][value] && symbols[mode][value].replace) { | ||
value = symbols[mode][value].replace; | ||
} | ||
return { | ||
value: value, | ||
metrics: fontMetrics.getCharacterMetrics(value, fontFamily) | ||
}; | ||
}; | ||
|
||
/** | ||
* Makes a symbolNode after translation via the list of symbols in symbols.js. | ||
* Correctly pulls out metrics for the character, and optionally takes a list of | ||
|
@@ -40,12 +57,9 @@ var mainitLetters = [ | |
* should if present come first in `classes`. | ||
*/ | ||
var makeSymbol = function(value, fontFamily, mode, options, classes) { | ||
// Replace the value with its replaced value from symbol.js | ||
if (symbols[mode][value] && symbols[mode][value].replace) { | ||
value = symbols[mode][value].replace; | ||
} | ||
|
||
var metrics = fontMetrics.getCharacterMetrics(value, fontFamily); | ||
var lookup = lookupSymbol(value, fontFamily, mode); | ||
var metrics = lookup.metrics; | ||
value = lookup.value; | ||
|
||
var symbolNode; | ||
if (metrics) { | ||
|
@@ -100,10 +114,19 @@ var mathsym = function(value, mode, options, classes) { | |
*/ | ||
var mathDefault = function(value, mode, options, classes, type) { | ||
if (type === "mathord") { | ||
return mathit(value, mode, options, classes); | ||
var fontLookup = mathit(value, mode, options, classes); | ||
return makeSymbol(value, fontLookup.fontName, mode, options, | ||
classes.concat([fontLookup.fontClass])); | ||
} else if (type === "textord") { | ||
return makeSymbol( | ||
value, "Main-Regular", mode, options, classes.concat(["mathrm"])); | ||
var font = symbols[mode][value] && symbols[mode][value].font; | ||
if (font === "ams") { | ||
return makeSymbol( | ||
value, "AMS-Regular", mode, options, classes.concat(["amsrm"])); | ||
} else { // if (font === "main") { | ||
return makeSymbol( | ||
value, "Main-Regular", mode, options, | ||
classes.concat(["mathrm"])); | ||
} | ||
} else { | ||
throw new Error("unexpected type: " + type + " in mathDefault"); | ||
} | ||
|
@@ -116,13 +139,19 @@ var mathit = function(value, mode, options, classes) { | |
if (/[0-9]/.test(value.charAt(0)) || | ||
// glyphs for \imath and \jmath do not exist in Math-Italic so we | ||
// need to use Main-Italic instead | ||
utils.contains(mainitLetters, value) || | ||
utils.contains(greekCapitals, value)) { | ||
return makeSymbol( | ||
value, "Main-Italic", mode, options, classes.concat(["mainit"])); | ||
utils.contains(mainitLetters, value)) { | ||
// For greek capitals, we have a choice, but Math-Italic | ||
// seems closer to LaTeX. | ||
//|| utils.contains(greekCapitals, value)) { | ||
return { | ||
fontName: "Main-Italic", | ||
fontClass: "mainit" | ||
}; | ||
} else { | ||
return makeSymbol( | ||
value, "Math-Italic", mode, options, classes.concat(["mathit"])); | ||
return { | ||
fontName: "Math-Italic", | ||
fontClass: "mathit" | ||
}; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update the doc string for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks! |
||
|
||
|
@@ -132,24 +161,22 @@ var mathit = function(value, mode, options, classes) { | |
var makeOrd = function(group, options, type) { | ||
var mode = group.mode; | ||
var value = group.value; | ||
if (symbols[mode][value] && symbols[mode][value].replace) { | ||
value = symbols[mode][value].replace; | ||
} | ||
|
||
var classes = ["mord"]; | ||
|
||
var font = options.font; | ||
if (font) { | ||
var fontLookup; | ||
if (font === "mathit" || utils.contains(mainitLetters, value)) { | ||
return mathit(value, mode, options, classes); | ||
fontLookup = mathit(value, mode, options, classes); | ||
} else { | ||
var fontName = fontMap[font].fontName; | ||
if (fontMetrics.getCharacterMetrics(value, fontName)) { | ||
return makeSymbol( | ||
value, fontName, mode, options, classes.concat([font])); | ||
} else { | ||
return mathDefault(value, mode, options, classes, type); | ||
} | ||
fontLookup = fontMap[font]; | ||
} | ||
if (lookupSymbol(value, fontLookup.fontName, mode).metrics) { | ||
return makeSymbol(value, fontLookup.fontName, mode, options, | ||
classes.concat([fontLookup.fontClass || font])); | ||
} else { | ||
return mathDefault(value, mode, options, classes, type); | ||
} | ||
} else { | ||
return mathDefault(value, mode, options, classes, type); | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code supposed to be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to ask you about this. Yes, it seems so:
Greek capital letters are in both fonts,
Main-Italic
andMath-Italic
. So which should we use? The master code claims to useMain-Italic
for Greek capital letters. But if you try the demo with\mathit{\Omega\imath}
, and inspect, you'll see that the\Omega
gets classmathit
while\imath
getsmainit
:In fact, the master code ends up calling
mathit()
with a single-unicode-character string (Ω
), whilegreekCapitals
is defined in terms of the macro name ("\Omega"
). When my code fixed this, I ended up changing Greek capital letters to useMain-Italic
font, which caused some tests to fail. I confirmed withtexcmp
thatMath-Italic
seems slightly closer, so kept it there.Let me know if you'd like this code changed at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, can you remove the commented out code? TBH, I'm not sure why we have the same glyphs duplicated in different fonts. It would be nice if we could avoid this and save a few bytes. I'm curious to find out why the rendering looks different even though the glyphs are the same. Maybe the advance or skew metrics for the Greek capitals are differ between fonts. I think it's safe to investigate this separate from this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I remove the list of greekCapitals as well? It's currently commented out (to prevent lint from complaining).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.