From d7f2f7f019e4159aee5f252ec62e807fdf62abb2 Mon Sep 17 00:00:00 2001
From: Christof Kaufmann <christof.kaufmann@hs-bochum.de>
Date: Thu, 23 Jan 2025 23:35:43 +0100
Subject: [PATCH] keras3-cpu: Fix broken PDF export of notebooks

To export a Jupyter Notebook as PDF from Jupyter Lab or VS Code
nbconvert is used. nbconvert calls pandoc to generate LaTeX source and
compile it as PDF. nbconvert uses a custom LaTeX template, which is not
compatible with pandoc >= 3.2.1, currently. This commit is a workaround
to make it compatible. Revert this commit as soon as
https://github.com/jupyter/nbconvert/pull/2196 is available in the base
docker image. However, the workaround should not do any harm, since it
checks whether the patch is required before modifying the template.
---
 keras3-cpu/Dockerfile | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/keras3-cpu/Dockerfile b/keras3-cpu/Dockerfile
index 868e865..1afbc92 100644
--- a/keras3-cpu/Dockerfile
+++ b/keras3-cpu/Dockerfile
@@ -184,6 +184,11 @@ RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
     fix-permissions "/etc/skel"
 # remember to copy back in post start hook
 
+# workaround for PDF export until https://github.com/jupyter/nbconvert/pull/2196 arrives
+RUN if ! grep -q "pandocbounded" /opt/conda/share/jupyter/nbconvert/templates/latex/base.tex.j2; then \
+        echo "Patching nbconvert latex template." && \
+        sed -i '168i\    \\newcommand{\\pandocbounded}[1]{#1}' /opt/conda/share/jupyter/nbconvert/templates/latex/base.tex.j2 ; \
+    fi
 
 # override maintainer label from Jupyter docker stacks
 LABEL maintainer="Christof Kaufmann <christof.kaufmann@hs-bochum.de>"
-- 
GitLab