From 81ef11f6946e6558bc41a84bbb6d36ad1879638a Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Tue, 25 Feb 2025 21:28:00 +0000 Subject: [PATCH 1/6] feat: add a isMilkdown prop and activate implicit figures if not Milkdown --- index.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index eeace8a..9d7baac 100644 --- a/index.ts +++ b/index.ts @@ -13,6 +13,7 @@ export const schema = z.array( fileName: z.string(), typeOfFile: TypeOfFileSchema, markdown: z.string(), + isMilkdown: z.boolean().optional(), }) ); @@ -55,11 +56,16 @@ export const handler = async function ( const generateFile = async ( pandocArgs: string[], destFilePath: string, - markdown: string + markdown: string, + isMilkdown: boolean = true ) => { + // pandoc source format + // If Milkdown, disable the implicit_figures extension to remove all image captions + const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; + try { await pdcTs.Execute({ - from: "markdown-implicit_figures", // pandoc source format (disabling the implicit_figures extension to remove all image captions) + from: fromString, to: "latex", // pandoc output format pandocArgs, spawnOpts: { argv0: "+RTS -M512M -RTS" }, @@ -76,7 +82,7 @@ export const handler = async function ( } const TeXoutput = await pdcTs.Execute({ - from: "markdown-implicit_figures", // pandoc source format (disabling the implicit_figures extension to remove all image captions) + from: fromString, to: "latex", // pandoc output format pandocArgs, outputToFile: false, // Controls whether the output will be returned as a string or written to a file @@ -130,6 +136,7 @@ export const handler = async function ( let url = ""; for (let eachRequestData of requestData) { const markdown = eachRequestData.markdown; + const isMilkdown = eachRequestData.isMilkdown; switch (eachRequestData.typeOfFile) { case "PDF": @@ -138,7 +145,8 @@ export const handler = async function ( const generatePDFResult = await generateFile( ["--pdf-engine=xelatex", `--template=./template.latex`], localPathPDF, - markdown + markdown, + isMilkdown ); if (generatePDFResult?.statusCode) { @@ -154,7 +162,8 @@ export const handler = async function ( await generateFile( [`--template=./template.latex`], localPathTEX, - markdown + markdown, + isMilkdown ); const s3PathTEX = `${eachRequestData.userId}/${filenameTEX}`; From 7d3e7bdbe85418fb3c414b13b4d744673613b947 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Mon, 3 Mar 2025 21:09:57 +0000 Subject: [PATCH 2/6] feat: test out whether figures are produced --- index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 9d7baac..4d0b279 100644 --- a/index.ts +++ b/index.ts @@ -61,7 +61,8 @@ export const handler = async function ( ) => { // pandoc source format // If Milkdown, disable the implicit_figures extension to remove all image captions - const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; + // const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; + const fromString = isMilkdown ? "markdown"; try { await pdcTs.Execute({ From 9e03a62a206202896d2873096fcf3f7fd18eac37 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Mon, 3 Mar 2025 21:11:00 +0000 Subject: [PATCH 3/6] fix: correct ternary --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 4d0b279..58d5e90 100644 --- a/index.ts +++ b/index.ts @@ -62,7 +62,7 @@ export const handler = async function ( // pandoc source format // If Milkdown, disable the implicit_figures extension to remove all image captions // const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; - const fromString = isMilkdown ? "markdown"; + const fromString = "markdown"; try { await pdcTs.Execute({ From edf7ff12520a54d20c48f6a04d76503535cb316b Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Mon, 3 Mar 2025 21:14:02 +0000 Subject: [PATCH 4/6] feat: test out whether figures are produced again --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 58d5e90..203182c 100644 --- a/index.ts +++ b/index.ts @@ -62,7 +62,7 @@ export const handler = async function ( // pandoc source format // If Milkdown, disable the implicit_figures extension to remove all image captions // const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; - const fromString = "markdown"; + const fromString = "markdown+implicit_figures"; try { await pdcTs.Execute({ From 0f010def1289c1aed02c3f44cd4531333fb3e0ae Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Mon, 3 Mar 2025 21:25:38 +0000 Subject: [PATCH 5/6] fix: set figure to stay in place in text --- src/template.latex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/template.latex b/src/template.latex index a604e02..3e7d1ca 100644 --- a/src/template.latex +++ b/src/template.latex @@ -216,6 +216,10 @@ $if(institute)$ $endif$ \date{$date$} +% Set images to stay in place +\usepackage{float} +\floatplacement{figure}{H} + % Lambda customisation \let\OldRule\rule From 58bc9f4e8d224c0bb15d28c80ae4053ca0323b10 Mon Sep 17 00:00:00 2001 From: Liam Doan Date: Mon, 3 Mar 2025 21:30:07 +0000 Subject: [PATCH 6/6] fix: revert fromString change --- index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 203182c..a2829a8 100644 --- a/index.ts +++ b/index.ts @@ -61,8 +61,8 @@ export const handler = async function ( ) => { // pandoc source format // If Milkdown, disable the implicit_figures extension to remove all image captions - // const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown"; - const fromString = "markdown+implicit_figures"; + const fromString = isMilkdown ? "markdown-implicit_figures" : "markdown+implicit_figures"; + // const fromString = "markdown+implicit_figures"; try { await pdcTs.Execute({