arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
feat: publish latex-html root and markdown at /md
Pau Escrich p4u@dabax.net
Fri, 27 Feb 2026 12:29:37 +0100
commit

5e2e15f9ffb5f13dd08dcf052c4dcf1c9bd34c82

parent

7cf2223d9e91cbe6cef0c5480b12e96d04715995

M .github/workflows/build-and-deploy.yml → .github/workflows/build-and-deploy.yml

@@ -23,16 +23,21 @@

- name: Install tools run: | sudo apt-get update - sudo apt-get install -y pandoc texlive-latex-recommended texlive-bibtex-extra texlive-extra-utils + sudo apt-get install -y pandoc texlive-latex-recommended texlive-bibtex-extra texlive-extra-utils poppler-utils + + - name: Build LaTeX HTML site + run: | + ./scripts/build-latex-html.sh docs ./md/ - name: Convert LaTeX to Markdown run: | - ./scripts/convert-paper.sh + ./scripts/convert-paper.sh docs/md - - name: Build Markdown preview page + - name: Build Markdown preview page (/md) run: | touch docs/.nojekyll - cat << 'EOF' > docs/index.html + mkdir -p docs/md + cat << 'EOF' > docs/md/index.html <!DOCTYPE html> <html lang="en" data-color-mode="light" data-light-theme="light" data-dark-theme="light"> <head>

@@ -119,6 +124,27 @@ background: #f6f8fa;

border: 1px solid #d0d7de; border-radius: 8px; } + .markdown-body img, + .markdown-body object, + .markdown-body embed { + max-width: 100% !important; + width: 100% !important; + height: auto !important; + display: block; + margin: 0 auto; + border-radius: 6px; + } + .markdown-body figure { + margin: 1.2rem 0; + max-width: 100%; + } + .markdown-body figure > img { + width: 100% !important; + } + .markdown-body figcaption { + color: #57606a !important; + font-size: 0.95rem; + } #status { margin-left: auto; font: 500 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

@@ -138,6 +164,7 @@ </style>

</head> <body> <div class="topbar"> + <a href="../">LaTeX HTML view</a> <a href="paper.md" download>Download paper.md</a> <a href="paper.md" target="_blank" rel="noopener noreferrer">Open raw markdown</a> <span id="status">Loading markdown...</span>

@@ -165,7 +192,9 @@ window.renderMathInElement(content, {

throwOnError: false, delimiters: [ { left: '$$', right: '$$', display: true }, - { left: '$', right: '$', display: false } + { left: '$', right: '$', display: false }, + { left: '\\\\[', right: '\\\\]', display: true }, + { left: '\\\\(', right: '\\\\)', display: false } ] }); }

@@ -184,7 +213,7 @@ - name: Upload paper.md artifact

uses: actions/upload-artifact@v4 with: name: paper-markdown - path: docs/paper.md + path: docs/md/paper.md if-no-files-found: error - name: Upload GitHub Pages artifact
M docker/pandoc-test/Dockerfile → docker/pandoc-test/Dockerfile

@@ -3,6 +3,7 @@

RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ pandoc \ + poppler-utils \ texlive-latex-recommended \ texlive-bibtex-extra \ texlive-extra-utils \
A scripts/build-latex-html.sh

@@ -0,0 +1,56 @@

+#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT_DIR" + +OUTPUT_DIR="${1:-docs}" +MD_PATH="${2:-./md/}" +mkdir -p "$OUTPUT_DIR" + +./scripts/prepare-flattened-tex.sh + +FLAT_TEX="$ROOT_DIR/build/flat/flattened.tex" +RESOURCE_PATH="$ROOT_DIR/build/flat:$ROOT_DIR/build/flat/texsrc/build:$ROOT_DIR/build/flat/texsrc/sections:$ROOT_DIR/build/flat/texsrc/figures:$ROOT_DIR/v2/build:$ROOT_DIR/v2/sections:$ROOT_DIR/v2/figures:$ROOT_DIR/v2/bibliography" + +( + cd "$OUTPUT_DIR" + pandoc "$FLAT_TEX" \ + --from=latex+raw_tex \ + --to=html5 \ + --standalone \ + --mathjax=https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js \ + --resource-path="$RESOURCE_PATH" \ + --citeproc \ + --bibliography="$ROOT_DIR/v2/bibliography/bibtex.bib" \ + --extract-media=media \ + --metadata title="DaVinci Paper" \ + -o index.html +) + +perl -0777 -i -pe " + s~</head>~<style> + :root { color-scheme: light; } + body { margin: 0 auto; max-width: 980px; padding: 26px 18px 48px; color: #1f2328; line-height: 1.72; background: #f6f8fa; } + .paper-nav { position: sticky; top: 0; z-index: 10; margin: -26px -18px 20px; padding: 10px 14px; border-bottom: 1px solid #d0d7de; background: rgba(255,255,255,0.95); backdrop-filter: blur(4px); } + .paper-nav a { display: inline-block; margin-right: 8px; text-decoration: none; border: 1px solid #d0d7de; border-radius: 6px; padding: 6px 10px; color: #1f2328; background: #f6f8fa; font: 600 14px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif; } + p, li, td, th, blockquote { color: #1f2328; } + h1, h2, h3, h4, h5, h6 { color: #0f172a; } + img, embed, object { max-width: 100%; width: 100% !important; height: auto !important; display: block; margin: 0 auto; border-radius: 6px; } + figure { margin: 1.2rem 0; max-width: 100%; } + figure > img { width: 100% !important; } + figcaption { color: #57606a; font-size: 0.95rem; } + pre { overflow-x: auto; background: #f6f8fa; border: 1px solid #d0d7de; border-radius: 8px; padding: 10px; } + @media (max-width: 767px) { body { padding: 14px 12px 28px; } .paper-nav { margin: -14px -12px 16px; } } + </style></head>~s; + s~<body([^>]*)>~<body\\1><div class='paper-nav'><a href='$MD_PATH'>Markdown View</a><a href='${MD_PATH}paper.md' download>Download paper.md</a></div>~s; +" "$OUTPUT_DIR/index.html" + +# Ensure extracted media links are relative in deployed root page. +perl -0777 -i -pe ' + s#(?:\.\./)*docs/(?:md/)?media/#media/#g; +' "$OUTPUT_DIR/index.html" + +./scripts/postprocess-web-output.sh "$OUTPUT_DIR" "$OUTPUT_DIR/index.html" + +test -s "$OUTPUT_DIR/index.html"
M scripts/convert-paper.sh → scripts/convert-paper.sh

@@ -4,83 +4,29 @@

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT_DIR" -mkdir -p build/flat docs - -TMP_TEX_ROOT="build/flat/texsrc" -rm -rf "$TMP_TEX_ROOT" -cp -R v2 "$TMP_TEX_ROOT" +OUTPUT_DIR="${1:-docs/md}" +mkdir -p "$OUTPUT_DIR" -# latexpand does not resolve macro-based include prefixes like \secs/, so -# normalize them to explicit relative paths in a temporary conversion tree. -while IFS= read -r -d '' tex_file; do - sed -E \ - -e 's#\\input\{\\secs/#\\input{../sections/#g' \ - -e 's#\\input\{\\figs/#\\input{../figures/#g' \ - -e 's#\\includegraphics(\[[^]]*\])?\{\\figs/#\\includegraphics\1{../figures/#g' \ - -e 's#\\bibliography\{\\bib/#\\bibliography{../bibliography/#g' \ - "$tex_file" > "${tex_file}.tmp" - mv "${tex_file}.tmp" "$tex_file" -done < <(find "$TMP_TEX_ROOT" -type f -name '*.tex' -print0) - -# Use markdown-friendly macro styles for conversion output. -cat >> "$TMP_TEX_ROOT/build/preamble-macros.tex" <<'EOF' -\renewcommand{\hlset}[1]{#1} -\renewcommand{\hlget}[1]{#1} -\renewcommand{\circuitstyle}[1]{\texttt{#1}\xspace} -\renewcommand{\smartcontractstyle}[1]{\texttt{#1}\xspace} -\renewcommand{\blobstyle}[1]{\texttt{#1}\xspace} -\renewcommand{\methodstyle}[1]{\texttt{#1}\xspace} -\renewcommand{\vocstyle}[1]{\texttt{#1}\xspace} -\renewcommand{\blinder}[1][]{\texttt{blinder}\xspace} -\renewcommand{\msg}[1][]{\texttt{message}\xspace} -\renewcommand{\enc}[1][]{\texttt{ciphertext}\xspace} -\renewcommand{\pk}[1][]{\texttt{pk}\xspace} -\renewcommand{\sk}[1][]{\texttt{sk}\xspace} -\renewcommand{\conc}{||} -\renewcommand{\F}{\mathbb{F}\xspace} -EOF +./scripts/prepare-flattened-tex.sh -# Support extensionless \includegraphics{...} paths by adding symlink aliases. -if [[ -d "$TMP_TEX_ROOT/figures" ]]; then - while IFS= read -r -d '' figure_file; do - figure_base="${figure_file%.*}" - if [[ "$figure_file" != "$figure_base" && ! -e "$figure_base" ]]; then - ln -s "$(basename "$figure_file")" "$figure_base" - fi - done < <(find "$TMP_TEX_ROOT/figures" -maxdepth 1 -type f -print0) -fi +FLAT_TEX="$ROOT_DIR/build/flat/flattened.tex" +RESOURCE_PATH="$ROOT_DIR/build/flat:$ROOT_DIR/build/flat/texsrc/build:$ROOT_DIR/build/flat/texsrc/sections:$ROOT_DIR/build/flat/texsrc/figures:$ROOT_DIR/v2/build:$ROOT_DIR/v2/sections:$ROOT_DIR/v2/figures:$ROOT_DIR/v2/bibliography" ( - cd "$TMP_TEX_ROOT/build" - latexpand main.tex > "$ROOT_DIR/build/flat/flattened.tex" + cd "$OUTPUT_DIR" + pandoc "$FLAT_TEX" \ + --from=latex+raw_tex \ + --to=gfm+tex_math_dollars \ + --wrap=none \ + --markdown-headings=atx \ + --resource-path="$RESOURCE_PATH" \ + --citeproc \ + --bibliography="$ROOT_DIR/v2/bibliography/bibtex.bib" \ + --extract-media=media \ + --strip-comments \ + -o paper.md ) -# Preserve references as labels (instead of dropping to empty text) so markdown -# remains readable even without TeX cross-reference resolution. -perl -0777 -i -pe ' - s/\\labelcref\{([^}]+)\}/$1/g; - s/\\eqref\{([^}]+)\}/$1/g; - s/\\ref\{([^}]+)\}/$1/g; - s/\\Cref\{([^}]+)\}/$1/g; - s/\\cref\{([^}]+)\}/$1/g; - s/\{\\sf\{([^{}]+)\}\}/\\texttt{$1}/g; - s/\\sf\{([^{}]+)\}/\\texttt{$1}/g; - s/\{\\tt\{([^{}]+)\}\}/\\texttt{$1}/g; - s/\\tt\{([^{}]+)\}/\\texttt{$1}/g; -' build/flat/flattened.tex - -pandoc build/flat/flattened.tex \ - --from=latex+raw_tex \ - --to=gfm+tex_math_dollars \ - --wrap=none \ - --markdown-headings=atx \ - --resource-path=build/flat:build/flat/texsrc/build:build/flat/texsrc/sections:build/flat/texsrc/figures:v2/build:v2/sections:v2/figures:v2/bibliography \ - --citeproc \ - --bibliography=v2/bibliography/bibtex.bib \ - --extract-media=docs/media \ - --strip-comments \ - -o docs/paper.md - # Clean residual LaTeX wrappers that are not useful in markdown output. perl -0777 -i -pe ' s/\\hyperlink\{[^{}]*\}\{([^{}]*)\}/$1/g;

@@ -98,6 +44,13 @@ s/\\allowbreak//g;

s/\$\$\\label\{[^}]+\}\s*/\$\$/g; s/\\:\|\|\\:/ || /g; s/\[\]\(#\\detokenize\{([^}]*)\}\)/$1/g; -' docs/paper.md +' "$OUTPUT_DIR/paper.md" + +# Ensure media links remain relative for /md hosting. +perl -0777 -i -pe ' + s#(?:\.\./)*docs/(?:md/)?media/#media/#g; +' "$OUTPUT_DIR/paper.md" + +./scripts/postprocess-web-output.sh "$OUTPUT_DIR" "$OUTPUT_DIR/paper.md" -test -s docs/paper.md +test -s "$OUTPUT_DIR/paper.md"
A scripts/prepare-flattened-tex.sh

@@ -0,0 +1,101 @@

+#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT_DIR" + +mkdir -p build/flat + +TMP_TEX_ROOT="build/flat/texsrc" +rm -rf "$TMP_TEX_ROOT" +cp -R v2 "$TMP_TEX_ROOT" + +# latexpand does not resolve macro-based include prefixes like \secs/, so +# normalize them to explicit relative paths in a temporary conversion tree. +while IFS= read -r -d '' tex_file; do + sed -E \ + -e 's#\\input\{\\secs/#\\input{../sections/#g' \ + -e 's#\\input\{\\figs/#\\input{../figures/#g' \ + -e 's#\\includegraphics(\[[^]]*\])?\{\\figs/#\\includegraphics\1{../figures/#g' \ + -e 's#\\bibliography\{\\bib/#\\bibliography{../bibliography/#g' \ + "$tex_file" > "${tex_file}.tmp" + mv "${tex_file}.tmp" "$tex_file" +done < <(find "$TMP_TEX_ROOT" -type f -name '*.tex' -print0) + +# Use conversion-friendly macro styles to avoid leaking complex LaTeX wrappers. +cat >> "$TMP_TEX_ROOT/build/preamble-macros.tex" <<'EOF' +\renewcommand{\hlset}[1]{#1} +\renewcommand{\hlget}[1]{#1} +\renewcommand{\circuitstyle}[1]{\texttt{#1}\xspace} +\renewcommand{\smartcontractstyle}[1]{\texttt{#1}\xspace} +\renewcommand{\blobstyle}[1]{\texttt{#1}\xspace} +\renewcommand{\methodstyle}[1]{\texttt{#1}\xspace} +\renewcommand{\vocstyle}[1]{\texttt{#1}\xspace} +\renewcommand{\blinder}[1][]{\texttt{blinder}\xspace} +\renewcommand{\msg}[1][]{\texttt{message}\xspace} +\renewcommand{\enc}[1][]{\texttt{ciphertext}\xspace} +\renewcommand{\pk}[1][]{\texttt{pk}\xspace} +\renewcommand{\sk}[1][]{\texttt{sk}\xspace} +\renewcommand{\conc}{||} +\renewcommand{\F}{\mathbb{F}\xspace} +EOF + +# Support extensionless \includegraphics{...} paths by adding safe aliases. +# Prefer true image formats and avoid source formats like .mmd/.drawio. +if [[ -d "$TMP_TEX_ROOT/figures" ]]; then + declare -A FIGURE_BASES=() + while IFS= read -r -d '' figure_file; do + FIGURE_BASES["${figure_file%.*}"]=1 + done < <(find "$TMP_TEX_ROOT/figures" -maxdepth 1 -type f -print0) + + for figure_base in "${!FIGURE_BASES[@]}"; do + [[ -e "$figure_base" ]] && continue + for ext in png jpg jpeg webp svg pdf; do + if [[ -f "${figure_base}.${ext}" ]]; then + ln -s "$(basename "${figure_base}.${ext}")" "$figure_base" + break + fi + done + done +fi + +( + cd "$TMP_TEX_ROOT/build" + latexpand main.tex > "$ROOT_DIR/build/flat/flattened.tex" +) + +# Preserve references as readable labels when TeX crossrefs are unresolved. +perl -0777 -i -pe ' + s#\{../figures/#\{texsrc/figures/#g; + s/\\labelcref\{([^}]+)\}/$1/g; + s/\\eqref\{([^}]+)\}/$1/g; + s/\\ref\{([^}]+)\}/$1/g; + s/\\Cref\{([^}]+)\}/$1/g; + s/\\cref\{([^}]+)\}/$1/g; + s/\{\\sf\{([^{}]+)\}\}/\\texttt{$1}/g; + s/\\sf\{([^{}]+)\}/\\texttt{$1}/g; + s/\{\\tt\{([^{}]+)\}\}/\\texttt{$1}/g; + s/\\tt\{([^{}]+)\}/\\texttt{$1}/g; +' build/flat/flattened.tex + +# Ensure extensionless figure paths point to explicit, browser-friendly files. +if [[ -d "$TMP_TEX_ROOT/figures" ]]; then + declare -A FIGURE_BASES=() + while IFS= read -r -d '' figure_file; do + FIGURE_BASES["$(basename "${figure_file%.*}")"]=1 + done < <(find "$TMP_TEX_ROOT/figures" -maxdepth 1 -type f -print0) + + for figure_base in "${!FIGURE_BASES[@]}"; do + selected_ext="" + for ext in png jpg jpeg webp svg pdf; do + if [[ -f "$TMP_TEX_ROOT/figures/${figure_base}.${ext}" ]]; then + selected_ext="$ext" + break + fi + done + [[ -n "$selected_ext" ]] || continue + + escaped_base="$(printf '%s' "texsrc/figures/${figure_base}" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')" + perl -0777 -i -pe "s#\\{${escaped_base}\\}#\\{texsrc/figures/${figure_base}.${selected_ext}\\}#g" build/flat/flattened.tex + done +fi