From 09f30d65e43c3099fb13960232576f06f0c29343 Mon Sep 17 00:00:00 2001
From: Tristan Stenner <ttstenner@gmail.com>
Date: Tue, 16 Jul 2019 18:31:59 +0200
Subject: [PATCH] Add option to include source files in ConTeXt PDFs (#5578)

Add a metadata option (`includesource`) to attach the source documents to the resulting PDF.
---
 MANUAL.txt                     | 3 +++
 data/templates/default.context | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/MANUAL.txt b/MANUAL.txt
index a623fddfd..9e582b69d 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1828,6 +1828,9 @@ Pandoc uses these variables when [creating a PDF] with ConTeXt.
 `whitespace`
 :   spacing between paragraphs, e.g. `none`, `small` (using [`setupwhitespace`])
 
+`includesource`
+:   include all source documents as file attachments in the PDF file
+
 [ConTeXt Paper Setup]: https://wiki.contextgarden.net/PaperSetup
 [ConTeXt Layout]: https://wiki.contextgarden.net/Layout
 [ConTeXt Font Switching]: https://wiki.contextgarden.net/Font_Switching
diff --git a/data/templates/default.context b/data/templates/default.context
index f54b55e74..dcd2dde5d 100644
--- a/data/templates/default.context
+++ b/data/templates/default.context
@@ -105,6 +105,11 @@ $endif$
 \setupxtable[body][]
 \setupxtable[foot][bottomframe=on]
 
+$if(includesource)$
+$for(sourcefile)$
+\attachment[file=$curdir$/$sourcefile$,method=hidden]
+$endfor$
+$endif$
 $for(header-includes)$
 $header-includes$
 $endfor$