Skip to content

Commit

Permalink
🔗 Add LaTeX macro support for \cref{} (#876)
Browse files Browse the repository at this point in the history
Co-authored-by: Rowan Cockett <[email protected]>
  • Loading branch information
eurunuela and rowanc1 authored Jan 30, 2024
1 parent d4013a6 commit e2e6caa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-masks-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tex-to-myst': patch
---

Support cref
5 changes: 5 additions & 0 deletions packages/tex-to-myst/src/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ export const REF_HANDLERS: Record<string, Handler> = {
const label = texToText(getArguments(node, 'group'));
state.pushNode(u('crossReference', { label }));
},
macro_cref(node, state) {
state.openParagraph();
const label = texToText(getArguments(node, 'group'));
state.pushNode(u('crossReference', { label }, []));
},
};
43 changes: 43 additions & 0 deletions packages/tex-to-myst/tests/refs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,46 @@ cases:
children:
- type: text
value: '%s'
- title: cref
tex: >
\section{Greetings}
\label{sec:greetings}
Hello!
\section{Referencing}
I greeted in section~\cref{sec:greetings}.
tree:
type: root
children:
- type: block
children:
- type: heading
depth: 2
identifier: sec:greetings
label: sec:greetings
children:
- type: text
value: Greetings
- type: paragraph
children:
- type: text
value: Hello!
- type: block
children:
- type: heading
depth: 2
children:
- type: text
value: Referencing
- type: paragraph
children:
- type: text
value: 'I greeted in section '
- type: crossReference
identifier: sec:greetings
label: sec:greetings
children: []
- type: text
value: '.'

0 comments on commit e2e6caa

Please sign in to comment.