Merge branch 'feature/better_templates' into develop

This commit is contained in:
AlexKucera committed 2025-09-21 16:02:47 +02:00
commit bd2a54bb50
8 files changed
+1111 -40

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# Obsidian Typst PDF Export
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/akucera/obsidian-typst-pdf-export-blue)](https://github.com/akucera/obsidian-typst-pdf-export/releases)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/AlexKucera/obsidian-typst-pdf-export?labelColor=blue)](https://github.com/AlexKucera/obsidian-typst-pdf-export/releases)
[![License: MIT](https://img.shields.io/github/license/AlexKucera/obsidian-typst-pdf-export?color=yellow)](https://opensource.org/licenses/MIT)
[![Obsidian Downloads](https://img.shields.io/github/downloads/AlexKucera/obsidian-typst-pdf-export/total?color=green)](https://obsidian.md/plugins?id=obsidian-typst-pdf-export)
![](https://img.shields.io/badge/desktop_only-red?label=obsidian&labelColor=purple)
-1
View File
@@ -86,7 +86,6 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
"sharp",
...builtins],
format: "cjs",
target: "es2018",
+6 -27
View File
@@ -60,8 +60,8 @@ export class PandocCommandBuilder {
// Add Typst engine options
this.addTypstEngineOptions(args, pandocOptions);
// Generate intermediate Typst file if requested
await this.addIntermediateTypstOutput(args, pandocOptions);
// Add enhanced Typst diagnostics for better error reporting
this.addTypstDiagnostics(args, pandocOptions);
// Set working directory for relative paths
if (pandocOptions.vaultBasePath) {
@@ -147,32 +147,11 @@ export class PandocCommandBuilder {
}
/**
* Generate intermediate Typst file if requested
* Add enhanced Typst diagnostics for better error reporting
*/
private async addIntermediateTypstOutput(args: string[], pandocOptions: PandocOptions): Promise<void> {
if (!pandocOptions.generateIntermediateTypst || !pandocOptions.tempDir) {
return;
}
const typstPath = path.join(pandocOptions.tempDir, 'intermediate.typ');
args.push('--output', typstPath);
// Also create a copy to keep for debugging
const debugTypstPath = path.join(pandocOptions.tempDir, 'debug.typ');
// Store cleanup handler in pandocOptions to be handled by the caller
if (!pandocOptions.cleanupHandlers) {
pandocOptions.cleanupHandlers = [];
}
pandocOptions.cleanupHandlers.push(() => {
try {
const fs = require('fs');
if (fs.existsSync(typstPath)) {
fs.copyFileSync(typstPath, debugTypstPath);
}
} catch (e) {
console.warn('Could not create debug Typst file:', e);
}
});
private addTypstDiagnostics(args: string[], pandocOptions: PandocOptions): void {
// Add Typst diagnostic options for better error reporting
args.push('--pdf-engine-opt', '--diagnostic-format=short');
}
}
-4
View File
@@ -30,10 +30,6 @@ export class PandocExecutor {
const pandocPath = this.pathResolver.resolveExecutablePath(pandocOptions.pandocPath, 'pandoc');
const timeout = pandocOptions.timeout || 60000;
// Log the exact command being executed for debugging
progressCallback?.('Starting Pandoc process...', 40);
// Determine working directory - use vault base path if available, fallback to plugin directory
let workingDir: string;
+414
View File
@@ -0,0 +1,414 @@
// Horizontal rule definition for Pandoc compatibility
#let horizontalrule = pad(y: 11pt, (line(stroke: 2pt + gray, length: 75%)))
// Email block styling function - elegant book style
#let email-block(from: none, to: none, subject: none, date: none, body) = {
block(
width: 100%,
inset: 18pt,
fill: rgb("#fafaf9"),
stroke: 1pt + rgb("#d6d3d1"),
radius: 0pt, // Square corners for book style
breakable: true
)[
#text(size: 1em, weight: "medium", style: "italic", fill: rgb("#57534e"))[Correspondence]
#v(0.4em)
#grid(
columns: (auto, 1fr),
row-gutter: 8pt,
column-gutter: 16pt,
if from != none [
#text(size: 0.9em, fill: rgb("#78716c"))[From:]
] else [],
if from != none [
#text(size: 0.9em)[#from]
] else [],
if to != none [
#text(size: 0.9em, fill: rgb("#78716c"))[To:]
] else [],
if to != none [
#text(size: 0.9em)[#to]
] else [],
if subject != none [
#text(size: 0.9em, fill: rgb("#78716c"))[Subject:]
] else [],
if subject != none [
#text(size: 0.9em, style: "italic")[#subject]
] else [],
if date != none [
#text(size: 0.9em, fill: rgb("#78716c"))[Date:]
] else [],
if date != none [
#text(size: 0.9em)[#date]
] else [],
)
#if body != none [
#v(0.6em)
#line(length: 100%, stroke: 0.5pt + rgb("#d6d3d1"))
#v(0.6em)
#block(
width: 100%,
inset: 0pt,
)[
#text(size: 0.9em)[#body]
]
]
]
}
// Drop cap function for chapter openings
#let drop-cap(text-content) = {
if type(text-content) != str {
text-content
} else {
let first-letter = text-content.slice(0, 1)
let rest = text-content.slice(1)
block(
width: 100%,
inset: 0pt,
)[
#grid(
columns: (auto, 1fr),
column-gutter: 8pt,
align: (left + top, left + top),
// Large decorative first letter
text(
size: 48pt,
weight: "bold",
font: ("Baskerville", "Times New Roman"),
fill: rgb("#7c2d12")
)[#first-letter],
// Rest of the paragraph
text(size: 11pt)[#rest]
)
]
}
}
// Decorative section divider
#let section-divider = {
v(1em)
align(center)[
#text(20pt, fill: rgb("#a8a29e"))[❦ ❦ ❦]
]
v(1em)
}
#let conf(
title: none,
authors: (),
date: none,
lang: "en",
region: "US",
paper: "a4",
margin: (inside: 3cm, outside: 2.5cm, top: 2.5cm, bottom: 2.5cm),
cols: 1,
font: ("Baskerville", "Times New Roman", "Times"),
fontsize: 11pt,
sectionnumbering: none, // Chapters typically don't use numbered sections
pagenumbering: "1",
// Support for UI-configurable options
heading_font: none,
monospace_font: none,
margin_top: none,
margin_right: none,
margin_bottom: none,
margin_left: none,
orientation: "portrait",
export_format: none,
doc,
) = {
// Set document properties
set document(
title: title
// Skip author in document metadata to avoid type issues
)
// Book-style alternating margins for binding
let page-margin = if margin_top != none {
(
top: if margin_top != none { margin_top } else { 2.5cm },
right: if margin_right != none { margin_right } else { 2.5cm },
bottom: if margin_bottom != none { margin_bottom } else { 2.5cm },
left: if margin_left != none { margin_left } else { 3cm },
)
} else {
margin
}
// Book page layout with alternating margins
set page(
paper: paper,
flipped: orientation == "landscape",
margin: page-margin,
..if export_format == "single-page" and orientation == "landscape" {
(width: auto,)
} else if export_format == "single-page" {
(height: auto,)
} else {
(:)
},
numbering: pagenumbering,
// Running headers for book style
header: context {
let page-num = counter(page).get().first()
if page-num > 1 [
#set text(size: 9pt, style: "italic", fill: rgb("#6b7280"))
#if calc.even(page-num) [
// Even pages: book title on left
#if title != none [#title] else [Document]
#h(1fr)
#page-num
] else [
// Odd pages: chapter title on right
#page-num
#h(1fr)
#context {
let headings = query(heading.where(level: 1))
if headings.len() > 0 [
#headings.last().body
] else [
Chapter
]
}
]
#v(-0.5em)
#line(length: 100%, stroke: 0.5pt + rgb("#d1d5db"))
]
}
)
// Classic book typography - serif fonts
let body-font = if font != none and type(font) == str {
(font, "Baskerville", "Times New Roman", "Times")
} else if font != none {
font
} else {
("Baskerville", "Times New Roman", "Times")
}
let body-fontsize = fontsize
set text(
font: body-font,
size: body-fontsize,
lang: lang,
region: region,
fill: rgb("#1f2937")
)
// Book-style paragraph settings with first-line indent
set par(
justify: true,
leading: 0.65em,
spacing: 0.65em,
first-line-indent: 1.2em
)
// Chapter and section numbering
if sectionnumbering != none {
set heading(numbering: sectionnumbering)
}
// Book-style heading fonts (same as body for classic look)
let heading-font = if heading_font != none and type(heading_font) == str {
(heading_font, "Baskerville", "Times New Roman", "Times")
} else if heading_font != none {
heading_font
} else {
("Baskerville", "Times New Roman", "Times")
}
// Chapter styling (Level 1 headings)
show heading.where(level: 1): it => {
pagebreak(weak: true)
v(3cm)
block(
width: 100%,
above: 0em,
below: 2em,
)[
#set align(center)
#set par(first-line-indent: 0em)
// Chapter number (if numbered)
#if it.numbering != none [
#text(
size: 14pt,
weight: "regular",
font: heading-font,
fill: rgb("#6b7280"),
tracking: 2pt
)[CHAPTER #counter(heading).display("I")]
#v(1em)
]
// Chapter title
#text(
size: 24pt,
weight: "bold",
font: heading-font,
fill: rgb("#111827")
)[#it.body]
#v(1.5em)
// Decorative flourish
#text(16pt, fill: rgb("#9ca3af"))[❦]
#v(2em)
]
// Reset paragraph indentation for first paragraph after chapter
par(first-line-indent: 0em)[]
}
// Section styling (Level 2 headings)
show heading.where(level: 2): it => {
v(1.5em)
block(
width: 100%,
below: 1em,
)[
#set align(center)
#set par(first-line-indent: 0em)
#text(
size: 16pt,
weight: "semibold",
font: heading-font,
fill: rgb("#374151")
)[#it.body]
#v(0.5em)
#line(length: 30%, stroke: 1pt + rgb("#9ca3af"))
]
}
// Subsection styling (Level 3 headings)
show heading.where(level: 3): it => block(
width: 100%,
below: 0.8em,
above: 1.2em,
)[
#set par(first-line-indent: 0em)
#text(
size: 13pt,
weight: "medium",
font: heading-font,
fill: rgb("#4b5563"),
style: "italic"
)[#it.body]
]
// Code styling (rare in books but sometimes needed)
let code-font = if monospace_font != none and type(monospace_font) == str {
(monospace_font, "Courier New", "Monaco")
} else {
("Courier New", "Monaco")
}
show raw: set text(font: code-font, size: body-fontsize * 0.9)
show raw.where(block: true): block.with(
width: 100%,
fill: rgb("#f9fafb"),
inset: 12pt,
radius: 0pt,
stroke: (left: 3pt + rgb("#d1d5db")),
breakable: true,
)
// Enhanced quote styling for books
show quote: it => {
set par(first-line-indent: 0em)
block(
width: 100%,
inset: (left: 2em, right: 2em, top: 1em, bottom: 1em),
)[
#set text(style: "italic", size: body-fontsize * 0.95)
#set par(leading: 0.7em)
#it.body
#if it.attribution != none [
#v(0.5em)
#align(right)[
#text(size: body-fontsize * 0.9, style: "normal")[— #it.attribution]
]
]
]
}
// Book title page (if title provided)
if title != none and title != "" [
#set align(center)
#set par(first-line-indent: 0em)
#v(4cm)
// Main title
#text(
size: 28pt,
weight: "bold",
font: heading-font,
fill: rgb("#111827")
)[#title]
#v(2em)
// Decorative line
#line(length: 40%, stroke: 1pt + rgb("#6b7280"))
#v(2em)
// Authors
#if authors != () and authors != none [
#for (i, author) in authors.enumerate() [
#if author.name != none and author.name != "" [
#text(
size: 16pt,
font: heading-font,
fill: rgb("#374151")
)[#author.name]
#if i < authors.len() - 1 [
#v(0.5em)
]
]
]
#v(2em)
]
// Date
#if date != none [
#text(
size: 12pt,
style: "italic",
fill: rgb("#6b7280")
)[#date]
]
#v(1fr)
#pagebreak()
// Copyright page (if authors provided)
#if authors != () and authors != none [
#v(1fr)
#set align(left)
#set text(size: 9pt, fill: rgb("#6b7280"))
#set par(first-line-indent: 0em, leading: 0.6em)
Copyright © #if date != none [#date] else [2024] by #if authors != () and authors != none [
#for (i, author) in authors.enumerate() [
#if author.name != none and author.name != "" [#author.name]#if i < authors.len() - 1 [, ]
]
] else [Author]
#v(0.5em)
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law.
#pagebreak()
]
]
// Document content
doc
}
+7 -7
View File
@@ -149,7 +149,7 @@
width: 100%,
below: 1em,
above: 1.2em,
fill: rgb("#2563eb"),
fill: rgb("#0d9488"),
inset: (x: 12pt, y: 8pt),
radius: 6pt,
)[
@@ -162,9 +162,9 @@
below: 0.6em,
above: 1em,
inset: (bottom: 3pt),
stroke: (bottom: 2pt + rgb("#2563eb")),
stroke: (bottom: 2pt + rgb("#0d9488")),
)[
#set text(font: heading-font, size: heading-fontsize * 0.85, weight: "semibold", fill: rgb("#1e40af"))
#set text(font: heading-font, size: heading-fontsize * 0.85, weight: "semibold", fill: rgb("#0f766e"))
#it.body
]
@@ -190,7 +190,7 @@
if title != none and title != "" [
#block(
width: 100%,
fill: gradient.linear(rgb("#1e40af"), rgb("#3b82f6"), angle: 45deg),
fill: gradient.linear(rgb("#0f766e"), rgb("#14b8a6"), angle: 45deg),
inset: 16pt,
radius: (top: 8pt),
)[
@@ -204,7 +204,7 @@
#v(0.3em)
#for author in authors [
#if author.name != none and author.name != "" [
#text(14pt, fill: rgb("#dbeafe"))[#author.name]
#text(14pt, fill: rgb("#ccfbf1"))[#author.name]
]
]
]
@@ -212,7 +212,7 @@
// Contact info sidebar
align(right + top)[
#if date != none [
#text(11pt, fill: rgb("#dbeafe"), style: "italic")[#date]
#text(11pt, fill: rgb("#ccfbf1"), style: "italic")[#date]
]
]
)
@@ -233,7 +233,7 @@
if authors != () and authors != none [
#for author in authors [
#if author.name != none and author.name != "" [
#text(14pt, weight: "semibold", fill: rgb("#1e40af"))[#author.name]
#text(14pt, weight: "semibold", fill: rgb("#0f766e"))[#author.name]
]
]
] else [],
+376
View File
@@ -0,0 +1,376 @@
// Horizontal rule definition for Pandoc compatibility
#let horizontalrule = pad(y: 11pt, (line(stroke: 2pt + gray, length: 75%)))
// Email block styling function with modern sidebar-appropriate styling
#let email-block(from: none, to: none, subject: none, date: none, body) = {
block(
width: 100%,
inset: 14pt,
fill: rgb("#f8fafc"),
stroke: 1pt + rgb("#e2e8f0"),
radius: 8pt,
breakable: true
)[
#text(size: 0.9em, weight: "semibold", fill: rgb("#475569"))[Email]
#v(0.3em)
#grid(
columns: (auto, 1fr),
row-gutter: 6pt,
column-gutter: 12pt,
if from != none [
#text(style: "italic", size: 0.85em, fill: rgb("#64748b"))[From:]
] else [],
if from != none [
#text(size: 0.9em, fill: rgb("#1e293b"))[#from]
] else [],
if to != none [
#text(style: "italic", size: 0.85em, fill: rgb("#64748b"))[To:]
] else [],
if to != none [
#text(size: 0.9em, fill: rgb("#1e293b"))[#to]
] else [],
if subject != none [
#text(style: "italic", size: 0.85em, fill: rgb("#64748b"))[Subject:]
] else [],
if subject != none [
#text(size: 0.9em, weight: "medium", fill: rgb("#0f172a"))[#subject]
] else [],
)
#if body != none [
#v(0.5em)
#block(
width: 100%,
inset: 8pt,
fill: rgb("#ffffff"),
radius: 4pt,
stroke: 0.5pt + rgb("#e2e8f0"),
)[
#text(size: 0.85em, fill: rgb("#374151"))[#body]
]
]
]
}
// Sidebar navigation component
#let sidebar-nav(title: none, authors: (), date: none, body-fontsize: 11pt, pagenumbering: "1") = {
let sidebar-bg = gradient.linear(
rgb("#dc2626"),
rgb("#ea580c"),
rgb("#f97316"),
angle: 160deg
)
place(
top + left,
dx: 0pt,
dy: 0pt,
block(
width: 4.5cm,
height: 27cm,
fill: sidebar-bg,
inset: 18pt,
radius: (right: 12pt),
)[
#set text(fill: white, size: body-fontsize * 0.9)
// Document title in sidebar
#if title != none and title != "" [
#text(15pt, weight: "bold", tracking: 0.5pt)[#upper(title)]
#v(1.2em)
#line(length: 100%, stroke: 1.5pt + rgb("#dbeafe"))
#v(1.2em)
]
// Author information in sidebar
#if authors != () and authors != none [
#text(9pt, weight: "medium", fill: rgb("#dbeafe"), tracking: 1pt)[AUTHORS]
#v(0.5em)
#for (i, author) in authors.enumerate() [
#if author.name != none and author.name != "" [
#text(10pt, weight: "regular")[#author.name]
#if i < authors.len() - 1 [#v(0.3em)]
]
]
#v(1.5em)
]
// Date in sidebar
#if date != none [
#text(9pt, weight: "medium", fill: rgb("#dbeafe"), tracking: 1pt)[DATE]
#v(0.5em)
#text(10pt)[#date]
#v(1.5em)
]
// Enhanced Table of contents in sidebar
#text(9pt, weight: "medium", fill: rgb("#dbeafe"), tracking: 1pt)[CONTENTS]
#v(0.7em)
#context {
let headings-1 = query(heading.where(level: 1))
let headings-2 = query(heading.where(level: 2))
for h1 in headings-1 {
block(
width: 100%,
inset: (y: 0.2em),
fill: rgb(255, 255, 255, 10%),
radius: 3pt
)[
#text(9pt, weight: "semibold")[#h1.body]
]
// Show level 2 headings under this level 1
for h2 in headings-2 {
if h2.location().page() >= h1.location().page() {
text(8pt, fill: rgb("#dbeafe"))[ • #h2.body]
v(0.15em)
}
}
v(0.4em)
}
}
#v(1fr)
// Progress indicator
#context {
let current-page = counter(page).get().first()
let total-pages = counter(page).final().first()
let progress = current-page / total-pages * 100
text(8pt, fill: rgb("#dbeafe"))[Progress]
v(0.3em)
block(
width: 100%,
height: 4pt,
fill: rgb(255, 255, 255, 20%),
radius: 2pt
)[
#place(
left,
block(
width: progress * 1%,
height: 100%,
fill: rgb("#fbbf24"),
radius: 2pt
)
)
]
v(0.5em)
}
// Page number at bottom of sidebar
#if pagenumbering != none [
#line(length: 100%, stroke: 1pt + rgb("#dbeafe"))
#v(0.7em)
#set align(center)
#context {
let current = counter(page).get().first()
let total = counter(page).final().first()
text(13pt, weight: "bold")[#current]
v(0.2em)
text(8pt, fill: rgb("#dbeafe"))[of #total]
}
]
]
)
}
#let conf(
title: none,
authors: (),
date: none,
lang: "en",
region: "US",
paper: "a4",
margin: (left: 8cm, right: 1.5cm, top: 1.5cm, bottom: 1.5cm),
cols: 1,
font: ("Inter", "SF Pro", "Helvetica Neue", "Arial"),
fontsize: 11pt,
sectionnumbering: "1.",
pagenumbering: "1",
// Support for UI-configurable options
heading_font: none,
monospace_font: none,
margin_top: none,
margin_right: none,
margin_bottom: none,
margin_left: none,
orientation: "portrait",
export_format: none,
doc,
) = {
// Set document properties
set document(
title: title
)
// Sidebar layout with fixed left margin for floating sidebar
let page-margin = (
top: if margin_top != none { margin_top } else { 1.5cm },
right: if margin_right != none { margin_right } else { 1.5cm },
bottom: if margin_bottom != none { margin_bottom } else { 1.5cm },
left: 5cm, // Fixed for sidebar - not configurable
)
// Page layout optimized for sidebar
set page(
paper: paper,
flipped: orientation == "landscape",
margin: page-margin,
..if export_format == "single-page" and orientation == "landscape" {
(width: auto,)
} else if export_format == "single-page" {
(height: auto,)
} else {
(:)
},
numbering: pagenumbering,
background: {
// Add the floating sidebar
sidebar-nav(
title: title,
authors: authors,
date: date,
body-fontsize: fontsize,
pagenumbering: pagenumbering
)
}
)
// Modern sans-serif typography
let body-font = if font != none and type(font) == str {
(font, "Inter", "SF Pro", "Helvetica Neue", "Arial")
} else {
font
}
let body-fontsize = fontsize
set text(
font: body-font,
size: body-fontsize,
lang: lang,
region: region,
fill: rgb("#111827")
)
// Clean paragraph settings
set par(justify: true, leading: 0.65em, spacing: 0.8em)
// Set heading numbering
if sectionnumbering != none {
set heading(numbering: sectionnumbering)
}
// Modern heading fonts
let heading-font = if heading_font != none and type(heading_font) == str {
(heading_font, "Inter", "SF Pro", "Helvetica Neue", "Arial")
} else if heading_font != none {
heading_font
} else {
("Inter", "SF Pro", "Helvetica Neue", "Arial")
}
let heading-fontsize = body-fontsize * 1.3
// Color palette coordinated with orange-red sidebar
let primary-color = rgb("#dc2626")
let secondary-color = rgb("#ea580c")
let accent-color = rgb("#f97316")
let text-color = rgb("#374151")
show heading.where(level: 1): it => block(
width: 100%,
below: 1.4em,
above: 2em,
breakable: false,
)[
#set text(font: heading-font, size: heading-fontsize * 1.2, weight: "bold", fill: primary-color)
#it
#v(0.5em)
#line(length: 100%, stroke: 2pt + gradient.linear(primary-color, secondary-color))
]
show heading.where(level: 2): it => block(
width: 100%,
below: 1em,
above: 1.6em,
inset: (left: 0pt, bottom: 8pt),
)[
#set text(font: heading-font, size: heading-fontsize, weight: "semibold", fill: text-color)
#it
#v(0.3em)
#line(length: 40%, stroke: 1pt + primary-color)
]
show heading.where(level: 3): it => block(
width: 100%,
below: 0.8em,
above: 1.2em,
)[
#set text(font: heading-font, size: heading-fontsize * 0.85, weight: "medium", fill: accent-color)
#it
]
// Enhanced code styling
let code-font = if monospace_font != none and type(monospace_font) == str {
(monospace_font, "SF Mono", "JetBrains Mono", "Courier New")
} else {
("SF Mono", "JetBrains Mono", "Courier New")
}
show raw: set text(font: code-font, size: body-fontsize * 0.9, fill: rgb("#374151"))
show raw.where(block: true): block.with(
width: 100%,
fill: rgb("#f8fafc"),
stroke: 1pt + rgb("#e2e8f0"),
inset: 14pt,
radius: 6pt,
breakable: true,
)
// Enhanced list styling
set list(indent: 1em, body-indent: 0.5em)
show list: it => {
set text(fill: rgb("#374151"))
it
}
// Enhanced quote styling
show quote: it => block(
width: 100%,
fill: rgb("#f1f5f9"),
inset: (left: 16pt, right: 16pt, top: 12pt, bottom: 12pt),
stroke: (left: 4pt + accent-color),
radius: (right: 6pt),
)[
#set text(style: "italic", fill: rgb("#4b5563"))
#it
]
// Figure styling
show figure: it => block(
width: 100%,
breakable: false,
)[
#set align(center)
#it.body
#if it.caption != none [
#v(0.7em)
#text(
size: body-fontsize * 0.9,
style: "italic",
fill: rgb("#6b7280")
)[
Figure #counter(figure).display("1"): #it.caption
]
]
]
// Don't show title/authors in main content since they're in sidebar
// Just start with the document content
doc
}
+307
View File
@@ -0,0 +1,307 @@
// Horizontal rule definition for Pandoc compatibility
#let horizontalrule = pad(y: 11pt, (line(stroke: 2pt + gray, length: 75%)))
// Email block styling function
#let email-block(from: none, to: none, subject: none, date: none, body) = {
block(
width: 100%,
inset: 16pt,
stroke: 0.5pt + blue,
radius: 5pt,
breakable: true
)[
#grid(
columns: (auto, 1fr),
row-gutter: 13pt,
column-gutter: 8pt,
if from != none [
#text(style: "italic", size: 1em)[From:]
] else [],
if from != none [
#text(size: 1em)[#from]
] else [],
if to != none [
#text(style: "italic", size: 1em)[To:]
] else [],
if to != none [
#text(size: 1em)[#to]
] else [],
if subject != none [
#text(style: "italic", size: 1em)[Subject:]
] else [],
if subject != none [
#text(size: 1em)[#subject]
] else [],
if date != none [
#text(style: "italic", size: 1em)[Date:]
] else [],
if date != none [
#text(size: 1em)[#date]
] else [],
)
#if body != none [
#block(
width: 100%,
inset: (left: 5pt, top: 6pt),
stroke: (left: 2pt + gray),
)[
#body
]
]
]
}
#let conf(
title: none,
authors: (),
date: none,
lang: "en",
region: "US",
paper: "a4",
margin: (x: 2.5cm, y: 2cm),
cols: 2,
font: ("Libertinus Serif", "Times New Roman", "Times"),
fontsize: 10pt,
sectionnumbering: "1.",
pagenumbering: "1",
// Support for UI-configurable options
heading_font: none,
monospace_font: none,
margin_top: none,
margin_right: none,
margin_bottom: none,
margin_left: none,
orientation: "portrait",
export_format: none,
doc,
) = {
// Set document properties
set document(
title: title
// Skip author in document metadata to avoid type issues
)
// Use UI-configured margins if available, otherwise fall back to template defaults
let page-margin = if margin_top != none {
(
top: if margin_top != none { margin_top } else { 2cm },
right: if margin_right != none { margin_right } else { 2.5cm },
bottom: if margin_bottom != none { margin_bottom } else { 2cm },
left: if margin_left != none { margin_left } else { 2.5cm },
)
} else {
margin
}
// globally set the gutter between page columns
set columns(gutter: 4% + 11pt)
// Single-column page layout
// Two-column page layout with configurable orientation
set page(
paper: paper,
flipped: orientation == "landscape",
margin: page-margin,
columns: 2,
..if export_format == "single-page" and orientation == "landscape" {
(width: auto,)
} else if export_format == "single-page" {
(height: auto,)
} else {
(:)
},
numbering: pagenumbering,
header: context {
if counter(page).get().first() > 1 [
#h(1fr) #counter(page).display("1")
]
}
)
// Academic typography - serif font with good readability
let body-font = if font != none and type(font) == str {
(font, "Libertinus Serif", "Times New Roman", "Times")
} else {
font
}
let body-fontsize = fontsize
set text(
font: body-font,
size: body-fontsize,
lang: lang,
region: region
)
// Justified paragraphs with proper spacing for columns
set par(justify: true, leading: 0.65em, spacing: 0.65em)
// Set heading numbering
if sectionnumbering != none {
set heading(numbering: sectionnumbering)
}
// Academic heading styles
let heading-font = if heading_font != none and type(heading_font) == str {
(heading_font, "Libertinus Serif", "Times New Roman", "Times")
} else if heading_font != none {
heading_font
} else {
("Libertinus Serif", "Times New Roman", "Times")
}
let heading-fontsize = body-fontsize * 1.3
show heading.where(level: 1): it => {
// Level 1 headings span both columns and create section breaks
place(
top + left,
scope: "parent",
float: true,
clearance: 1em,
block(
width: 100%,
below: 1.2em,
above: 1.5em,
breakable: false,
)[
#set text(font: heading-font, size: heading-fontsize * 1.2, weight: "bold")
#set align(left)
#it
#v(0.3em)
#line(length: 100%, stroke: 1pt + gray)
]
)
}
show heading.where(level: 2): it => block(
width: 100%,
below: 0.8em,
above: 1em,
)[
#set text(font: heading-font, size: heading-fontsize, weight: "bold")
#it
]
show heading.where(level: 3): it => block(
width: 100%,
below: 0.6em,
above: 0.8em,
)[
#set text(font: heading-font, size: heading-fontsize * 0.9, weight: "semibold", style: "italic")
#it
]
// Code styling with monospace font
let code-font = if monospace_font != none and type(monospace_font) == str {
(monospace_font, "Courier New", "Monaco", "Menlo")
} else {
("Courier New", "Monaco", "Menlo")
}
show raw: set text(font: code-font, size: body-fontsize * 0.9)
// Code blocks with background
show raw.where(block: true): block.with(
width: 100%,
fill: luma(250),
inset: 8pt,
radius: 3pt,
breakable: true,
)
// Full-width title and author section spanning both columns
if title != none and title != "" [
#place(
top + center,
scope: "parent",
float: true,
clearance: 2em,
block(
width: 100%,
breakable: false,
)[
#set align(center)
#text(18pt, weight: "bold", font: heading-font)[#title]
#if authors != () and authors != none [
#v(0.8em)
#for (i, author) in authors.enumerate() [
#if author.name != none and author.name != "" [
#text(12pt, style: "italic")[#author.name]
#if i < authors.len() - 1 [, ]
]
]
]
#if date != none [
#v(0.5em)
#text(10pt, style: "italic")[#date]
]
#v(1.5em)
#line(length: 60%, stroke: 0.5pt + gray)
]
)
] else [
// If no title, still show authors and date in header if present
#if authors != () and authors != none or date != none [
#place(
top + center,
scope: "parent",
float: true,
clearance: 1em,
block(width: 100%)[
#set align(center)
#if authors != () and authors != none [
#for (i, author) in authors.enumerate() [
#if author.name != none and author.name != "" [
#text(12pt, weight: "semibold")[#author.name]
#if i < authors.len() - 1 [, ]
]
]
]
#if date != none [
#v(0.3em)
#text(10pt, style: "italic")[#date]
]
#v(1em)
#line(length: 40%, stroke: 0.5pt + gray)
]
)
]
]
// Enhanced figure styling for two-column layout
show figure: it => {
block(
width: 100%,
breakable: false,
)[
#set align(center)
#it.body
#if it.caption != none [
#v(0.5em)
#text(size: body-fontsize * 0.9, style: "italic")[
Figure #counter(figure).display("1"): #it.caption
]
]
]
}
// Footnote styling for columns
show footnote.entry: it => {
block(
width: 100%,
inset: (top: 0.3em),
)[
#text(size: body-fontsize * 0.8)[
#super[#it.note.counter.display("1")] #it.note.body
]
]
}
// Document content
doc
}