Skip to content

Commit fe6080c

Browse files
nthieryrowanc1
andauthored
☑️ MyST-to-TeX: add support for checkboxes (#2560)
Co-authored-by: Rowan Cockett <[email protected]>
1 parent 8c82b34 commit fe6080c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.changeset/stupid-otters-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"myst-to-tex": patch
3+
---
4+
5+
MyST-to-TeX: add support for checkboxes

packages/myst-to-tex/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ const handlers: Record<string, Handler> = {
240240
}
241241
},
242242
listItem(node, state) {
243-
state.write('\\item ');
243+
if (node.checked === true) {
244+
state.write('\\item[$\\blacksquare$] ');
245+
} else if (node.checked === false) {
246+
state.write('\\item[$\\square$] ');
247+
} else {
248+
state.write('\\item ');
249+
}
250+
244251
if (node.children?.[0]?.type === 'paragraph' && node.children.length === 1) {
245252
state.renderChildren(node.children[0], true);
246253
} else {

packages/myst-to-tex/tests/basic.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,20 @@ cases:
624624
children:
625625
- type: text
626626
value: 'A list item in a paragraph'
627+
- type: listItem
628+
children:
629+
- type: text
630+
value: 'A checkbox'
631+
checked: false
632+
- type: listItem
633+
children:
634+
- type: text
635+
value: 'A checked checkbox'
636+
checked: true
627637
latex: |-
628638
\begin{itemize}
629639
\item A list item
630640
\item A list item in a paragraph
641+
\item[$\square$] A checkbox
642+
\item[$\blacksquare$] A checked checkbox
631643
\end{itemize}

0 commit comments

Comments
 (0)