mystmd
mystmd copied to clipboard
Beamer and codeblock like \begin{verbatim} requires [fragile] option to display correctly
As explain here (https://pbelmans.ncag.info/blog/2011/02/20/why-latex-beamer-needs-fragile-when-using-verbatim/), using verbatim environment in beamer require the use of [fragile] option. Without it we get an error and the verbatim is not well displayed. That's why the current mystmd implementation does not work to generate slide with verbatim code in beamer/tex/pdf.
v1.2.9
Description
Myst md to beamer does not works when used with codeblock.
Proposed solution
A simple solution (the one I use right now), is to add [fragile] to each \begin{frame} in mystmd (index.ts)
Here is the my diff :
diff --git a/packages/myst-to-tex/src/index.ts b/packages/myst-to-tex/src/index.ts
index ac8b77ac..33813d38 100644
--- a/packages/myst-to-tex/src/index.ts
+++ b/packages/myst-to-tex/src/index.ts
@@ -144,7 +144,7 @@ const handlers: Record<string, Handler> = {
if (node.children?.[0]?.type === 'heading') {
state.data.nextHeadingIsFrameTitle = true;
}
- state.write('\n\n\\begin{frame}\n');
+ state.write('\n\n\\begin{frame}[fragile]\n');
state.renderChildren(node, false);
state.write('\\end{frame}\n\n');
return;
A better solution is maybe to detect frame that use a code block and add [fragile] option to the begin{frame}. An other option is to provide a way to allow to set the option use in a \begin{frame} (with a directive ?)
Additional notes
Except that it works very well, thank you a lot.