From 72554c663c31d3ef4f5188d51fda0ae2bb92ade3 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Tue, 4 Mar 2025 22:41:08 +0000 Subject: [PATCH 1/5] refactor: change fromString variable to formatName, improve comments --- index.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 From ed074ba1bb74b5202e23a15d0f4ed59e49b693e6 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Wed, 5 Mar 2025 09:49:54 +0000 Subject: [PATCH 2/5] fix: automatically centre images --- src/template.latex | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/template.latex b/src/template.latex index bb8d070..f01ceb8 100644 --- a/src/template.latex +++ b/src/template.latex @@ -220,6 +220,31 @@ $endif$ \usepackage{float} \floatplacement{figure}{H} +% Wrap includegaphics in figures with centering... +\usepackage{etoolbox} % For toggle functionality + +\newtoggle{infigure} % Create toggle to track if we're inside a figure environment +\togglefalse{infigure} % Initialize as false + +% Set toggle when entering/exiting figure environments +\pretocmd{\figure}{\toggletrue{infigure}}{}{} +\apptocmd{\endfigure}{\togglefalse{infigure}}{}{} + +% Save the original includegraphics command +\let\oldincludegraphics\includegraphics + +% Redefine includegraphics to check if it's already in a figure +\renewcommand{\includegraphics}[2][]{% + \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} From 2e99b3e8cc0dea19f20bbd3ae7a4175ddd8628ba Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Wed, 5 Mar 2025 09:51:07 +0000 Subject: [PATCH 3/5] refactor: edit comments in latex template for consistency --- src/template.latex | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/template.latex b/src/template.latex index f01ceb8..b1ceb8a 100644 --- a/src/template.latex +++ b/src/template.latex @@ -220,21 +220,18 @@ $endif$ \usepackage{float} \floatplacement{figure}{H} -% Wrap includegaphics in figures with centering... +% 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 -% Set toggle when entering/exiting figure environments -\pretocmd{\figure}{\toggletrue{infigure}}{}{} +\pretocmd{\figure}{\toggletrue{infigure}}{}{} % Set toggle when entering/exiting figure environments \apptocmd{\endfigure}{\togglefalse{infigure}}{}{} -% Save the original includegraphics command -\let\oldincludegraphics\includegraphics +\let\oldincludegraphics\includegraphics % Save the original includegraphics command -% Redefine includegraphics to check if it's already in a figure -\renewcommand{\includegraphics}[2][]{% +\renewcommand{\includegraphics}[2][]{ % Redefine includegraphics to check if it's already in a figure \iftoggle{infigure}{% \oldincludegraphics[#1]{#2}% }{% From b01bb3bd4be3fa05c9b1d6e2bb750a09903d7e30 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Wed, 5 Mar 2025 09:56:09 +0000 Subject: [PATCH 4/5] chore(testing): change implicit figures to true temporarily in DEV env --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index e120bf5..9084b05 100644 --- a/index.ts +++ b/index.ts @@ -146,7 +146,7 @@ export const handler = async function ( let url = ""; for (let eachRequestData of requestData) { const markdown = eachRequestData.markdown; - const implicitFigures = eachRequestData.implicitFigures; + const implicitFigures = true; switch (eachRequestData.typeOfFile) { case "PDF": From 5d28dfd468f9454a03487ee77f290000242175e5 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Wed, 5 Mar 2025 10:00:22 +0000 Subject: [PATCH 5/5] chore(testing): works! revert back --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 9084b05..e120bf5 100644 --- a/index.ts +++ b/index.ts @@ -146,7 +146,7 @@ export const handler = async function ( let url = ""; for (let eachRequestData of requestData) { const markdown = eachRequestData.markdown; - const implicitFigures = true; + const implicitFigures = eachRequestData.implicitFigures; switch (eachRequestData.typeOfFile) { case "PDF":