Skip to content

Commit

Permalink
📜 Improvements to LaTeX parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Oct 13, 2023
1 parent 0b090ca commit 923b1e6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-jars-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tex-to-myst': patch
---

Updates to various latex parsing functions
4 changes: 4 additions & 0 deletions packages/tex-to-myst/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const MISC_HANDLERS: Record<string, Handler> = {
// Some size options, not respecting at the moment
macro_vspace: pass,
macro_hfill: pass,
macro_tiny: pass,
macro_small: pass,
macro_footnotesize: pass,
macro_normalsize: pass,
Expand All @@ -75,4 +76,7 @@ export const MISC_HANDLERS: Record<string, Handler> = {
macro_textwidth: pass,
macro_onecolumn: pass,
macro_linewidth: pass,
// line numbers
macro_linenumbers: pass,
macro_nolinenumbers: pass,
};
15 changes: 14 additions & 1 deletion packages/tex-to-myst/src/siunitx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const UNITS: Record<string, string> = {
mole: 'mol',
second: 's',
becquerel: 'Bq',
degreeCelsius: '°C',
degreeCelsius: '',
coulomb: 'C',
farad: 'F',
gray: 'Gy',
Expand Down Expand Up @@ -54,6 +54,7 @@ const UNITS: Record<string, string> = {
arcsecond: '″', // second (plane angle) U+2033
neper: 'Np',
tonne: 't',
celsius: '℃',
};

// SI prefixes
Expand Down Expand Up @@ -327,6 +328,18 @@ const SIUNITX_HANDLERS: Record<string, Handler> = {
});
return;
},
macro_si(node, state) {
state.openParagraph();
const { units, alt, organized } = createSiUnitNode(state.file, node, 0);
const translated = organized.map(unitToString).join(NARROW_NO_BREAK_SPACE);
state.addLeaf<SiUnit>('si', {
unit: translated,
alt,
units: units.map((n: GenericNode) => n.content),
value: translated,
});
return;
},
macro_qty(node, state) {
state.openParagraph();
const { units, alt, organized } = createSiUnitNode(state.file, node, 1);
Expand Down
7 changes: 7 additions & 0 deletions packages/tex-to-myst/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export const TABLE_HANDLERS: Record<string, Handler> = {
state.closeParagraph();
state.closeNode();
},
['env_table*'](node, state) {
state.closeParagraph();
state.openNode('container', { kind: 'table' });
state.renderChildren(node);
state.closeParagraph();
state.closeNode();
},
env_tabular: createTable,
env_tabularx: createTable,
env_supertabular: createTable,
Expand Down
2 changes: 2 additions & 0 deletions packages/tex-to-myst/src/tex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const macros: Record<string, number> = {
affiliation: 1,
framebox: 1,
tnote: 1,
['table*']: 1,
arraystretch: 1,
multirow: 5,
multicolumn: 3,
Expand All @@ -83,6 +84,7 @@ const macros: Record<string, number> = {
captionof: 2,
// SI Units: https://texdoc.org/serve/siunitx/0
SI: 2,
si: 1,
qty: 2,
tothe: 1,
raiseto: 1,
Expand Down
3 changes: 3 additions & 0 deletions packages/tex-to-myst/tests/siunitx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ cases:
- title: kg⁻¹
tex: \qty[per-mode = symbol]{1.99}{ \per \kilogram }
text: 1.99 kg⁻¹
- title: 90 ms
tex: 90~\si{\milli \second}
text: 90 ms

0 comments on commit 923b1e6

Please sign in to comment.