commit 9e22a6fd8833a695e6384c86eadad72481e33ac2 Author: Phyks (Lucas Verney) Date: Mon Jan 25 14:54:02 2016 +0100 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1192926 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pandoc.pdf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1828ee9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "filters/pandoc-crossref"] + path = filters/pandoc-crossref + url = https://github.com/lierdakil/pandoc-crossref diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4308a74 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +SOURCES = $(wildcard *.md) +OUT = $(SOURCES:.md=.pdf) + +all: $(OUT) + +$(OUT): $(SOURCES) + pandoc --smart -t latex $< --filter=filters/pandoc-svg.py --filter=pandoc-crossref -o $@ + +clean: + rm -f $(OUT) + find . -name "*.pandoc.pdf" -delete diff --git a/README.md b/README.md new file mode 100644 index 0000000..dabd936 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +Pandoc boilerplate +================== + +Boilerplate to render scientific documents written in Markdown to LaTeX, using +Pandoc. + +Includes various Pandoc filters: + +* Automatically convert `SVG` files to `PDF` and rewrite the image link to + include them in the document easily. + +* Include [pandoc-crossref](https://github.com/lierdakil/pandoc-crossref) for + easy numbering and referencing. + + +## TODO + +* automatically convertfunction names (cos, sin, exp, log) to their +LaTeX equivalent (\cos and so on) when in a mathematical environment, +then taking out the useless leading `\`. + +* not having to use \frac{}{} to write fractions, but instead +automatically convert simple fractions in math environment to \frac{}{} +(for instance convert "(1 / 2)" to "\frac{1}{2}") + +* anything else like this that could help writing more readable LaTeX +code :) diff --git a/filters/pandoc-svg.py b/filters/pandoc-svg.py new file mode 100644 index 0000000..022820e --- /dev/null +++ b/filters/pandoc-svg.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python +""" +Pandoc filter to convert svg files to pdf as suggested at: +https://github.com/jgm/pandoc/issues/265#issuecomment-27317316 +""" + +__author__ = "Jerome Robert" + +import mimetypes +import subprocess +import os +import sys +from pandocfilters import toJSONFilter, Image + +# TODO add emf export if fmt=="docx" ? +fmt_to_option = { + "latex": ("--export-pdf", "pdf"), + "beamer": ("--export-pdf", "pdf"), + # because of IE + "html": ("--export-png", "png") +} + + +def svg_to_any(key, value, fmt, meta): + if key == 'Image': + alt, [src, title] = value[1], value[-1] + mimet, _ = mimetypes.guess_type(src) + option = fmt_to_option.get(fmt) + if mimet == 'image/svg+xml' and option: + base_name, _ = os.path.splitext(src) + eps_name = base_name + "." + "pandoc." + option[1] + try: + mtime = os.path.getmtime(eps_name) + except OSError: + mtime = -1 + if mtime < os.path.getmtime(src): + cmd_line = ['inkscape', option[0], eps_name, src] + sys.stderr.write("Running %s\n" % " ".join(cmd_line)) + subprocess.call(cmd_line, stdout=sys.stderr.fileno()) + return Image(['', [], []], alt, [eps_name, title]) + +if __name__ == "__main__": + toJSONFilter(svg_to_any) diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..77d05bf --- /dev/null +++ b/notes.md @@ -0,0 +1,18 @@ +--- +# Metadata +title: %title% +author: Lucas Verney +date: \today +# LaTeX headers +header-includes: + - \usepackage{dsfont} + - \usepackage{mathtools} + - \renewcommand{\arraystretch}{1.5} +# Pandoc-crossref options +cref: True +chapters: True +--- +\tableofcontents + +\pagebreak +