diff --git a/index.ts b/index.ts index af2af91..e120bf5 100644 --- a/index.ts +++ b/index.ts @@ -59,13 +59,23 @@ export const handler = async function ( markdown: string, implicitFigures: boolean = false ) => { - // pandoc source format - // If implicitFigures, enable the implicit_figures extension and add image captions - const fromString = implicitFigures ? "markdown+implicit_figures" : "markdown-implicit_figures"; + // Use standard Pandoc style via format name `markdown` + // (see https://pandoc.org/chunkedhtml-demo/3.1-general-options.html) + // + // The "+implicit_figures" extension wraps images in figures and uses the image's alt text as the caption. + // NOTE: The "Figure X." prefix is removed in the LaTeX template via: + // ```tex + // % Remove "Figure X." prefix from captions + // \usepackage{caption} + // \captionsetup[figure]{labelformat=empty} + // ``` + // + // If `implicitFigures`, enable the `implicit_figures`, disable otherwise... + const formatName = implicitFigures ? "markdown+implicit_figures" : "markdown-implicit_figures"; try { await pdcTs.Execute({ - from: fromString, + from: formatName, to: "latex", // pandoc output format pandocArgs, spawnOpts: { argv0: "+RTS -M512M -RTS" }, @@ -82,7 +92,7 @@ export const handler = async function ( } const TeXoutput = await pdcTs.Execute({ - from: fromString, + from: formatName, to: "latex", // pandoc output format pandocArgs, outputToFile: false, // Controls whether the output will be returned as a string or written to a file diff --git a/src/template.latex b/src/template.latex index bb8d070..b1ceb8a 100644 --- a/src/template.latex +++ b/src/template.latex @@ -220,6 +220,28 @@ $endif$ \usepackage{float} \floatplacement{figure}{H} +% Centre images +\usepackage{etoolbox} % For toggle functionality + +\newtoggle{infigure} % Create toggle to track if we're inside a figure environment +\togglefalse{infigure} % Initialize as false + +\pretocmd{\figure}{\toggletrue{infigure}}{}{} % Set toggle when entering/exiting figure environments +\apptocmd{\endfigure}{\togglefalse{infigure}}{}{} + +\let\oldincludegraphics\includegraphics % Save the original includegraphics command + +\renewcommand{\includegraphics}[2][]{ % Redefine includegraphics to check if it's already in a figure + \iftoggle{infigure}{% + \oldincludegraphics[#1]{#2}% + }{% + \begin{figure} + \centering + \oldincludegraphics[#1]{#2} + \end{figure}% + }% +} + % Remove "Figure X." prefix from captions \usepackage{caption} \captionsetup[figure]{labelformat=empty}