Skip to content
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

πŸ‘©β€πŸŽ“ Add wrapfigure latex environment #1342

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-beans-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tex-to-myst': patch
---

Support wrapfigure environment
25 changes: 11 additions & 14 deletions packages/tex-to-myst/src/figures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ function centering(node: GenericNode, state: ITexParser) {
}
}

function renderFigure(node: GenericNode, state: ITexParser) {
state.closeParagraph();
state.openNode('container', { kind: 'figure' });
state.renderChildren(node);
state.closeParagraph();
state.closeNode();
}

const FIGURE_HANDLERS: Record<string, Handler> = {
env_figure(node, state) {
state.closeParagraph();
state.openNode('container', { kind: 'figure' });
state.renderChildren(node);
state.closeParagraph();
state.closeNode();
},
env_subfigure(node, state) {
state.closeParagraph();
state.openNode('container', { kind: 'figure' });
state.renderChildren(node);
state.closeParagraph();
state.closeNode();
},
env_figure: renderFigure,
env_subfigure: renderFigure,
env_wrapfigure: renderFigure,
env_centering(node, state) {
centering(node, state);
state.renderChildren(node);
Expand Down
1 change: 1 addition & 0 deletions packages/tex-to-myst/src/tex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const macros: Record<string, number> = {
multirow: 5,
multicolumn: 3,
subfigure: 2,
wrapfigure: 3,
tabularx: 2,
longtable: 2,
['longtable*']: 2,
Expand Down
32 changes: 32 additions & 0 deletions packages/tex-to-myst/tests/figures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,35 @@ cases:
children:
- type: text
value: Simulation Two
- title: Wrapfigure environment
tex: |-
\begin{wrapfigure}[23]{r}{0.5\textwidth}
\centering
\includegraphics[width=1.0\textwidth]{figures/my_pic.png}
\caption{ This is the caption, \href{computations.ipynb}{link to notebook}.}
\label{fig:picture}
\end{wrapfigure}
tree:
type: root
children:
- type: container
kind: figure
identifier: fig:picture
label: fig:picture
align: center
children:
- type: image
url: figures/my_pic.png
- type: caption
children:
- type: paragraph
children:
- type: text
value: 'This is the caption, '
- type: link
url: computations.ipynb
children:
- type: text
value: link to notebook
- type: text
value: '.'
Loading