From fd1475aaec33e717a3721679008bc42bb96d0998 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 4 Oct 2026 15:41:41 +0200 Subject: pandoc allow markdown in LaTex environments TODO: pass arguments to the LaTeX environments --- common.mk | 1 + pandoc/filters/div-class-to-env.lua | 31 +++++++++++++++++++++++++++++++ templates/slides.md | 10 +++++----- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 pandoc/filters/div-class-to-env.lua diff --git a/common.mk b/common.mk index 8726a163..f4ad4ebe 100644 --- a/common.mk +++ b/common.mk @@ -17,6 +17,7 @@ PANDOC_CITE_OPTIONS := --citeproc PANDOC_FILTER_OPTIONS := --lua-filter "$(PANDOC_FILTER_DIR)/include-files.lua" PANDOC_FILTER_OPTIONS += --lua-filter "$(PANDOC_FILTER_DIR)/center-img.lua" PANDOC_FILTER_OPTIONS += --lua-filter "$(PANDOC_FILTER_DIR)/meta-vars.lua" +PANDOC_FILTER_OPTIONS += --lua-filter "$(PANDOC_FILTER_DIR)/div-class-to-env.lua" PANDOC_FILTER_OPTIONS += --filter pandoc-plot -M plot-configuration=$(PANDOC_DIR)/defaults/pandoc-plot.yml COMMON_PANDOC_OPTIONS := --data-dir="$(PANDOC_DIR)" --resource-path="$(COMMON_IMAGES):." $(PANDOC_FILTER_OPTIONS) PANDOC_XARGS ?= diff --git a/pandoc/filters/div-class-to-env.lua b/pandoc/filters/div-class-to-env.lua new file mode 100644 index 00000000..1a87777b --- /dev/null +++ b/pandoc/filters/div-class-to-env.lua @@ -0,0 +1,31 @@ +--- div-class-to-env.lua – filter to convert classes to LaTeX environments +--- +--- Copyright: © 2026 Florian Fischer +--- License: MIT – see LICENSE file for details + +if FORMAT:match('beamer') then + function Div(d) + -- ignore code blocks which are not of class "env". + if not d.classes:includes 'env' then + return + end + + local env + for _, v in ipairs(d.classes) do + if v ~= 'env' then + env = v + break + end + end + + if not env then + return + end + + return { + pandoc.RawInline('latex', '\\begin{'..env..'}'), + d, + pandoc.RawInline('latex', '\\end{'..env..'}') + } + end +end diff --git a/templates/slides.md b/templates/slides.md index 4c7e30c7..c03104c6 100644 --- a/templates/slides.md +++ b/templates/slides.md @@ -83,9 +83,9 @@ class AKTE { ## Some Text in custom tcolorboxes -`\begin{merke}`{=latex} -Der Grundsatz der \beamerpgap{2}{\boldred{Datenkapselung}} besagt, dass nur ein Objekt selbst Zugriff auf seine Attribute haben sollte. -`\end{merke}`{=latex} +:::{.env .merke} +Der Grundsatz der \beamerpgap{2}{\boldred{Datenkapselung}} besagt, dass nur ein **Objekt** selbst Zugriff auf seine *Attribute* haben sollte. +::: \pause\pause @@ -95,13 +95,13 @@ Der Zugriff von außen sollte nur über durch das Objekt bereitgestellte Methode \pause -`\begin{pseudocode}`{=latex} - +:::{.env .pseudocode} ``` Solange du willst... Mache was. Mache was anderes. ``` +::: `\end{pseudocode}`{=latex} -- cgit v1.2.3