summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2014-12-31 17:35:06 +0100
committerJonas Smedegaard <dr@jones.dk>2014-12-31 17:49:14 +0100
commitf89b78b463c108eed766a9ea7d930043e0a457d8 (patch)
treef505a518fe868ff81d367b8f1e3e70b0492d0e6a
parent83ff019b64e25bfb4895c525ba0fcc3ae514e32a (diff)
Mark systematic issues (and compile LaTeX explicitly: Pandoc don't detect need for 3rd round).
-rw-r--r--Makefile12
-rw-r--r--header.tex8
-rwxr-xr-xpandoc-todo59
3 files changed, 76 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 25079fe..d7f1cf8 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ citeproc_file = $(stem).bib
templates = template.tex header.tex before.tex after.tex
-filters = ./pandoc-memoir ./pandoc-cs1
+filters = ./pandoc-memoir ./pandoc-cs1 ./pandoc-todo
filters += $(if $(citeproc_file),pandoc-citeproc)
filters += ./pandoc-iri
@@ -52,5 +52,11 @@ $(stem).mediawiki: $(stem).raw
$(stem).native: $(stem).mediawiki $(localfilters)
$(env_filter) pandoc -f mediawiki $(args_meta) $(args_filter) -o $@ $<
-$(flavors:%=$(stem)-%.pdf) $(stem).tex: $(stem).native $(templates)
- pandoc $(args_meta) $(args_latex) $(args_$(@:$(stem)-%.pdf=%)) -o $@ $<
+$(flavors:%=$(stem)-%.tex): $(stem).native $(templates)
+ pandoc $(args_meta) $(args_latex) $(args_$(@:$(stem)-%.tex=%)) -o $@ $<
+
+XELATEX = xelatex -no-shell-escape -halt-on-error -interaction=batchmode
+%.pdf: %.tex
+ $(XELATEX) $<
+ $(XELATEX) $<
+ $(XELATEX) $<
diff --git a/header.tex b/header.tex
index 36ea321..f18638f 100644
--- a/header.tex
+++ b/header.tex
@@ -1,7 +1,15 @@
\microtypesetup{final}
\urlstyle{tt}
\usepackage{draftwatermark}
+\usepackage{xcolor,textcomp}
+\usepackage[normalem]{ulem}
+\newcommand{\hl}{%
+ \bgroup\markoverwith{%
+ \textcolor{yellow}{\rule[-.5ex]{2pt}{2.5ex}}}\ULon}
%\usepackage{fixme}
+\usepackage[obeyDraft]{todonotes}
+ \usepackage{marginnote}
+ \renewcommand{\marginpar}{\marginnote}
\hypersetup{breaklinks,hidelinks,draft=false}
\usepackage[defaultlines=4,all]{nowidow}
\def\UrlBreaks{%
diff --git a/pandoc-todo b/pandoc-todo
new file mode 100755
index 0000000..784b8fa
--- /dev/null
+++ b/pandoc-todo
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+# TODO: support multi-match within word
+# TODO: support multi-word match
+# TODO: always count and allow expressing which (default: all)
+# TODO: parse regex+commeent as definition in external markdown TODO file.
+# TODO: normal hyphenation within note (keep quote with word in "word")
+
+use warnings;
+use strict;
+
+use feature qw(switch);
+no if $] >= 5.018, warnings => "experimental::smartmatch";
+
+use Pandoc::Filter 0.05;
+use Pandoc::Elements;
+
+my $breakable_chars = qr/[\&\;\/\.\?\!\=]/;
+my $hyphen_chars = qr/[\x{2010}-\x{2015}\x{2053}\x{2212}]/;
+my $doublequote_chars = qr/[\x{00AB}\x{00BB}\x{201C}-\x{201F}\x{300C}-\x{300F}\x{301D}-\x{301F}\x{FE41}-\x{FE44}\x{FF02}\x{FF62}\x{FF63}]/;
+my $singlequote_chars = qr/[\x{0060}\x{2018}\x{2019}\x{201A}\x{201B}\x{2039}\x{203A}\x{FF07}]/;
+my $odd_singlequote_chars = qr/[\x{2019}]/;
+
+pandoc_filter(
+ \&todo,
+);
+
+sub latex_encode {
+ my $s = shift;
+ $s =~ s/(?<!\s|$breakable_chars)($breakable_chars])(?!\s)/$1\\-/g;
+ $s =~ s/$odd_singlequote_chars/'/g; #'
+ return $s;
+}
+
+sub mark_inside {
+ my ( $before, $it, $after, $note ) = @_;
+ return [ RawInline( 'latex', sprintf( '%s\\todo{%s}\\hl{%s}%s',
+ latex_encode($before),
+ latex_encode($note),
+ latex_encode($it),
+ latex_encode($after),
+ ))];
+};
+
+sub todo {
+ my $self = shift;
+ return unless ( $self->name eq 'Str' );
+ given ($self->content) {
+ when (/^(-)$/) {
+ return mark_inside( '', $1, '', 'double dash?' ) };
+ when ( /^(.*?)($hyphen_chars(?:.*$hyphen_chars)?)(.*?)$/ ) {
+ return mark_inside( $1, $2, $3, 'bad dash/hyphen' ) };
+ when ( /^(.*?)($doublequote_chars(?:.*$doublequote_chars)?)(.*?)$/ ) {
+ return mark_inside( $1, $2, $3, 'bad quote' ) };
+ when ( /^(.*?)($singlequote_chars(?:.*$singlequote_chars)?)(.*?)$/ ) {
+ return mark_inside( $1, $2, $3, 'Bad quote/apostrophe' ) };
+ default { return };
+ }
+};