Skip to content

Commit

Permalink
Merge pull request #268 from mgreminger/scientific-notation
Browse files Browse the repository at this point in the history
feat: allow units for scientific notation number
  • Loading branch information
mgreminger authored Aug 25, 2024
2 parents c0985b9 + f52a4c1 commit d297860
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 333 deletions.
Binary file added public/images/updates/scientific_notation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
const apiUrl = window.location.origin;
const currentVersion = 20240818;
const currentVersion = 20240824;
const tutorialHash = "hUts8q3sKUqJGFUwSdL5ZS";
const termsVersion = 20240110;
Expand Down
4 changes: 4 additions & 0 deletions src/KeyboardShortcuts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<td class="first-column"><span class="key">/</span></td>
<td>Divide</td>
</tr>
<tr>
<td class="first-column"><span class="key">{modifier}</span> + <span class="key">E</span></td>
<td>Insert *10^ for scientific notation</td>
</tr>
<tr>
<td class="first-column"><span class="key">&lt;</span> then <span class="key">=</span></td>
<td>Insert less than or equal to symbol (&le;)</td>
Expand Down
94 changes: 57 additions & 37 deletions src/MathField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,45 +70,65 @@
}
function handleKeyDown(e: KeyboardEvent) {
if (e.key === 'Tab' && !e.shiftKey) {
e.preventDefault();
let hasPlaceholder = false;
let startingPosition: number | undefined;
if ( !mathLiveField.value.includes('placeholder') ) {
startingPosition = mathLiveField.position;
mathLiveField.executeCommand('moveAfterParent');
} else {
hasPlaceholder = true
}
if (hasPlaceholder || startingPosition === mathLiveField.position) {
mathLiveField.executeCommand('moveToNextPlaceholder');
}
} else if (e.key === '|') {
e.preventDefault();
mathLiveField.executeCommand(['insert', '|']);
} else if (e.key === 'Enter') {
if (!mathLiveField.shadowRoot.querySelector(".ui-menu-container")) {
switch (e.key) {
case 'Tab':
if(!e.shiftKey) {
e.preventDefault();
let hasPlaceholder = false;
let startingPosition: number | undefined;
if ( !mathLiveField.value.includes('placeholder') ) {
startingPosition = mathLiveField.position;
mathLiveField.executeCommand('moveAfterParent');
} else {
hasPlaceholder = true
}
if (hasPlaceholder || startingPosition === mathLiveField.position) {
mathLiveField.executeCommand('moveToNextPlaceholder');
}
}
break;
case '|':
e.preventDefault();
if ($activeMathField?.pendingNewLatex && !e.shiftKey && !e[$modifierKey]) {
$activeMathField.setPendingLatex();
} else if(e.shiftKey) {
dispatch('shiftEnter');
} else if(e[$modifierKey]) {
dispatch('modifierEnter');
} else {
dispatch('enter');
mathLiveField.executeCommand(['insert', '|']);
break;
case 'Enter':
if (!mathLiveField.shadowRoot.querySelector(".ui-menu-container")) {
e.preventDefault();
if ($activeMathField?.pendingNewLatex && !e.shiftKey && !e[$modifierKey]) {
$activeMathField.setPendingLatex();
} else if(e.shiftKey) {
dispatch('shiftEnter');
} else if(e[$modifierKey]) {
dispatch('modifierEnter');
} else {
dispatch('enter');
}
}
}
} else if (e.key === '*' && e[$modifierKey]) {
e.preventDefault();
mathLiveField.executeCommand(['insert', '\\times']);
} else if (e.key === "'") {
e.preventDefault();
mathLiveField.executeCommand(['insert', '^{\\mathrm{T}}']);
} else if (e.key === "F10" && e.shiftKey) {
e.preventDefault();
//@ts-ignore
mathLiveField.showMenu();
break;
case '*':
if (e[$modifierKey]) {
e.preventDefault();
mathLiveField.executeCommand(['insert', '\\times']);
}
break;
case "'":
e.preventDefault();
mathLiveField.executeCommand(['insert', '^{\\mathrm{T}}']);
break;
case "F10":
if(e.shiftKey) {
e.preventDefault();
//@ts-ignore
mathLiveField.showMenu();
}
break;
case "e":
case "E":
if (e[$modifierKey]) {
e.preventDefault();
mathLiveField.executeCommand(['insert', '#@\\cdot10^{#?}']);
}
break;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Updates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
}
</style>

<em>August 24, 2024</em>
<h4>Scientific Notation Improvements</h4>
<p>
A frequent point of confusion was the lack of support for units immediately following
a number expressed in scientific notation. Units now work as expected when used with
scientific notation (see image below). Additionally, the {modifier}-E keyboard shortcut
can be used to insert scientific notation and a new scientific notation button has been
added to the virtual keyboard.
</p>
<br>
<p>
New scientific notation with units support:
<img src="images/updates/scientific_notation.png" width="{253*0.5}px" height="{64*0.5}px" alt="Math cell shown with scientific notation number with units">
</p>

<br>

<em>August 18, 2024</em>
<h4>New Show Intermediate Results Feature</h4>
<p>
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export const keyboards: Keyboards = {
new Button({ buttonText: '=', content: '=', command: "typedText" }),
new Button({ buttonText: '+', content: '+', command: "typedText" }),
new Blank('0.25fr'),
new Button({ buttonText: ',', content: ',', command: "typedText" }),
new Button({ buttonText: '\\cdot 10^{\\mathrm{x}}', content: '#@\\cdot10^{#?}' }),
new Button({ buttonText: 'x_a', content: '#@_{#?}' }),
new Button({ buttonText: '\\approx', content: '\\approx' })
]]
Expand Down
3 changes: 2 additions & 1 deletion src/parser/LatexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ fragment
IDENTIFIER : [a-zA-Z] [a-zA-Z0-9]*;

fragment
EXP : ('E' | 'e') ('+' | '-')? DIGIT+ ;
EXP : ('E' | 'e' ) ('+' | '-')? DIGIT+
| ' '* ( CMD_CDOT | CMD_TIMES) ' '* '10' CARET ( DIGIT | ( L_BRACE ('+' | '-')? DIGIT+ R_BRACE) );

fragment
GREEK_CHAR: '\\' ('alpha' | 'beta' | 'gamma' | 'delta' | 'epsilon' | 'zeta' |
Expand Down
Loading

0 comments on commit d297860

Please sign in to comment.