Skip to content
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
20 changes: 15 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/template.latex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down