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 @@ -13,6 +13,7 @@ export const schema = z.array(
fileName: z.string(),
typeOfFile: TypeOfFileSchema,
markdown: z.string(),
isMilkdown: z.boolean().optional(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to generalise this to e.g. implicitFigures: z.boolean().optional(),?

Milkdown isn't fundamental here.

})
);

Expand Down Expand Up @@ -55,11 +56,17 @@ 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+implicit_figures";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest don't put the type in the name, because it is already typed. Make a more general name for this variable.

// const fromString = "markdown+implicit_figures";

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" },
Expand All @@ -76,7 +83,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
Expand Down Expand Up @@ -130,6 +137,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":
Expand All @@ -138,7 +146,8 @@ export const handler = async function (
const generatePDFResult = await generateFile(
["--pdf-engine=xelatex", `--template=./template.latex`],
localPathPDF,
markdown
markdown,
isMilkdown
);

if (generatePDFResult?.statusCode) {
Expand All @@ -154,7 +163,8 @@ export const handler = async function (
await generateFile(
[`--template=./template.latex`],
localPathTEX,
markdown
markdown,
isMilkdown
);

const s3PathTEX = `${eachRequestData.userId}/${filenameTEX}`;
Expand Down
4 changes: 4 additions & 0 deletions src/template.latex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down