Pandoc Template
A flexible and future proof way to write documents.
Features
This project template and its build is quite flexible. The template strives to provide a more or less complete example of what is possible to keep not just the text under version control but also other sources like flowcharts and plots. Flexibility also means that you can add any feature you see fit or opt out of features you don't need.
The default features include:
- write document in pandoc-flavored Markdown, the example sources include
- a build script (
Makefile
) to automate the build process - convert Markdown sources to PDF with pandoc
- continuous integration, i.e. a build server that automatically
- spell checks Markdown sources
- deploys document to Nextcloud share
Disabling Features
You can disable most features by just removing the respective content in the
Markdown sources. Some feature are integrated in the Makefile
for which you
need to perform additional steps:
-
plots: remove the
*.R
file(s) inimg/plot
-
flowcharts: remove the
*.dot
file(s) inimg/graph
Alternatives
Most features and tools are optional and replaceable, the only real core tool is pandoc. Besides that, everything can be changed, e.g. you could use a different programming language for plotting, you could use Inkscape to create and edit your flowcharts, or you could even use a different build tool.
If you have an idea, suggestion, or even a concrete example, feel free to open an issue or create a merge request. The more (optional) features we can offer the more it shows how flexible and future proof this way of working is.
Continuous Integration
In GitLab, projects can automatically be built, tested and deployed. In general, this is called continuous integration (CI) and continuous deployment (CD). Both together are abbreviated to CI / CD and this is what you will see in the GitLab web interface.
You define what the CI server should do in the .gitlab-ci.yml
file. This
project template contains two stages:
- check to run the spell checker on all document sources
- deploy to upload the built document to an iDiv Nextcloud share
Spell Checking
Unfortunately, spell checking is still a bit awkward. The problem is that the currently existing spell checking tools are not really well integrated. See this issue for more information and progress.
If you think that the spell checker with its current
limitations is more of an annoyance than help and you can
rely on the spell checking from your editor, you can disable it by removing the
check stage from the .gitlab-ci.yml
file. Once the issues are fixed, you
can simply re-enable it by reverting the commit.
Deployment to Nextcloud
The deploy stage tries to upload the built document to an iDiv Nextcloud share. To make this work, you will need to set this up first by following these steps:
-
log in to Nextcloud
Go to the iDiv Nextcloud and log in.
-
create a new, empty folder
My recommendation is to create a top-level folder named documents. Then, create a sub-folder named after your project, e.g. the document title.
Avoid spaces and use dashes or underscores instead!
-
share the folder
Click on the share icon of the folder. Click on the plus
+
icon next to Share link. Check the Password protect box and set your password. Then click the Allow upload and editing radio button.Finally, click on the copy link to clipboard icon.
-
CI settings
Go to your GitLab project. Go to Settings, CI / CD and expand the Variables section. Add two variables:
-
NEXTCLOUD_SHARE
, paste the share link you copied from Nextcloud. Remove everything except the part after the last slash/
, e.g. if your link is:https://portal.idiv.de/nextcloud/index.php/s/aFgeXn5Ay9qffbd
... you only need the
aFgeXn5Ay9qffbd
part. -
NEXTCLOUD_PW
, with the password of the share.
Make sure both variables are masked so the values will not show up in your logs.
-
Building
To build the PDF, just type make
. Make already does incremental compilation,
i.e. it re-compiles only those targets whose sources changed. If you want to
watch for changes and automatically run make
when something changes, use
watchexec:
watchexec make
The watchexec
tool honors .gitignore
.
Requirements
These requirements are all more or less optional or replaceable. If you want to build the template PDF, you need these dependencies:
- git
- pandoc and pandoc-citeproc
- LaTeX, either through texlive or MiKTeX
- GNU make
- Graphviz
-
R including the packages data.table, tidyverse and svglite
install.packages(c("data.table", "tidyverse", "svglite"), Ncpus = 8)
- watchexec
- markdown-spellcheck
Note: On MS Windows, it might be helpful using chocolatey.