Layout

Jakob Voss authored
revision a697eb291c0eb801d770f9afbb8dac97251f0d65
Makefile
# Dies ist ein Makefile (GNU Make) mit Regeln zur Erstellung von Dateien

TITLE=Normdaten in Wikidata
AUTHOR=
DATE=

SOURCE_URL=https://www.penflip.com/nichtich/normdaten-in-wikidata
BUILD_DATE=$(shell date)
COMMIT_DATE=$(shell git log -1 --format=%cd)

TXT=$(wildcard *.txt)
MAIN=normdaten-in-wikidata

metadata:
@echo '% $(TITLE)' > $@
@echo '% $(AUTHOR)' >> $@
@echo '% $(DATE)' >> $@
@echo >> $@

$(MAIN).md: metadata $(TXT)
@cp metadata $@
@cp properties-table.txt properties.txt
@awk '/^[^ >]+\.txt/ {print}' Contents.txt | while read f; do \
cat $$f >> $@ ; echo >> $@ ;\
done

tex: $(MAIN).tex
$(MAIN).tex: metadata $(TXT)
@cp metadata $(MAIN).md
@cp properties-list.txt properties.txt
@awk '/^[^ >]+\.txt/ {print}' Contents.txt | while read f; do \
sed 's/
/XXXXXX/;s/<\/div>/YYYYYY/' $$f >> $(MAIN).md ;\
echo >> $(MAIN).md ;\
done
pandoc $(PANDOC_OPTIONS) -o $@ $(LATEX_OPTIONS) $(MAIN).md
cp properties-table.txt properties.txt
perl -pi -e 'BEGIN{undef $$/;} s/\\href{([^}]+)}{([^\\}]+)}/\\hreffn{\1}{\2}/sgm' $@
perl -pi -e 's/XXXXXX/\\begin{framedmerkbox}/;s/YYYYYY/\\end{framedmerkbox}/;' $@


pdf: $(MAIN).pdf
$(MAIN).pdf: $(MAIN).tex
xelatex $< && xelatex $< && xelatex $<

# PDF-Version
.PHONY: a4
a4:
pdfnup $(MAIN).pdf --nup '2x1' --a4paper --openright true --suffix a4

# Übersicht
synopsis: synopsis.md
synopsis.md: $(TXT)
@perl scripts/synopsis > $@

# ausgewählte Ausgabeformate
html: $(MAIN).html index.html
tex: $(MAIN).tex
docx: $(MAIN).docx

MAIN_FILES=$(MAIN).md $(MAIN).html $(MAIN).pdf synopsis.md

# alle Ausgabeformate
.PHONY: clean info deps

all: $(MAIN_FILES)

build: all
@mkdir -p build
@cp $(MAIN_FILES) build
@rsync -rupt --del images build/

clean:
rm -rf $(MAIN_FILES) build/ *.aux *.log *.lof *.out *.toc

# konkrete Regeln für die jeweiligen Ausgabeformate
.SUFFIXES: .md .pdf .html .tex .docx

PANDOC_OPTIONS=-s -S --toc -N -V build-date="$(BUILD_DATE)" -V commit-date="$(COMMIT_DATE)" -V source-url="$(SOURCE_URL)"
LATEX_OPTIONS=--template layout/template.tex \
--chapters\
--latex-engine xelatex
HTML_OPTIONS=--template layout/template.html --css layout/buttondown.css --css layout/layout.css --include-before layout/header.html
ODT_OPTIONS=

.md.html:
pandoc $(PANDOC_OPTIONS) -o $@ $(HTML_OPTIONS) $<

.md.docx:
pandoc $(PANDOC_OPTIONS) -t docx -o $@ $(ODT_OPTIONS) $<

# Snapshot zum Korrekturlesen mit Annotator
SNAPSHOT_OPTIONS = -V snapshot=1

snapshot.html: $(MAIN).md
pandoc $(PANDOC_OPTIONS) -o $@ $(HTML_OPTIONS) $(SNAPSHOT_OPTIONS) $<

TODAY=`date +%F`
snapshot: snapshot.html
cp snapshot.html build/$(TODAY).html


index.md: About.txt synopsis.md
cat About.txt > index.md
echo "* [HTML-Version]($(MAIN).html)" >> index.md
echo "* [PDF-Version]($(MAIN).pdf)" >> index.md
echo >> index.md
cat synopsis.md >> index.md
echo >> index.md

info:
./scripts/files

# upload build files if ftp.cfg exists
upload: upload-html upload-pdf upload-docx
upload-html: html ftp.cfg
ncftpput -R -f ftp.cfg / $(MAIN).html index.html
upload-pdf: ftp.cfg
make pdf; ncftpput -R -f ftp.cfg / $(MAIN).pdf
upload-docx: ftp.cg
make docx; ncftpput -R -f ftp.cfg / $(MAIN).docx

pull-and-upload: pull upload

# pull changes from upstream and exit with error if no changes were found
pull:
@git fetch
@if [ "$$(git log HEAD..origin/master --oneline)" ] ;\
then git merge origin master; \
else echo "no changes"; exit 1 ; fi


website: build
@if [ "$$(git status -s)" ]; then \
git status -s ; \
else \
git checkout gh-pages ; \
cp build/* . 2>/dev/null ; \
rsync -rupt --del build/images/ images ; \
git add --all ; \
if [ "$$(git status -s)" ]; then \
git commit -m "snapshot" ; \
else \
echo "nothing to commit." ; \
fi ; \
git checkout -f master; \
fi

# Benötigte Software
deps:
sudo apt-get install pandoc pandoc-citeproc\
texlive-latex-recommended\
texlive-fonts-extra texlive-fonts-recommended
layout/template
\documentclass[
a5paper,pagesize,
10pt,
DIV=12, % Seitenspiegel
BCOR=2mm,
open=any, % Kapitel sowohl links als auch rechts beginnen
ngerman
]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % wegen \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[utf8]{inputenc}
$if(euro)$
\usepackage{eurosym}
$endif$
\else % if luatex or xelatex
\usepackage{fontspec}
\ifxetex
\usepackage{xltxtra,xunicode}
\fi
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}

ewcommand{\euro}{€}
$if(mainfont)$
\setmainfont{$mainfont$}
$endif$
$if(sansfont)$
\setsansfont{$sansfont$}
$endif$
$if(monofont)$
\setmonofont{$monofont$}
$endif$
$if(mathfont)$
\setmathfont{$mathfont$}
$endif$
\fi



% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$

$if(natbib)$
\usepackage{natbib}
\bibliographystyle{plainnat}
$endif$
$if(biblatex)$
\usepackage{biblatex}
$if(biblio-files)$
\bibliography{$biblio-files$}
$endif$
$endif$
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
$if(tables)$
\usepackage{longtable}
$endif$

% Kopf- und Fußzeile
\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\setkomafont{pageheadfoot}{¶
ormalfont}
\renewcommand*{\chaptermarkformat}{}
\lefoot[\pagemark]{\pagemark\,\textsf{\enspace\,\textbar\enspace\,\headmark}}
\rofoot[\pagemark]{\textsf{\headmark\enspace\,\textbar\enspace\,}\pagemark}

% TODO: chaptermark auch bei unnumbered-Kapitel (Vorwort & Anhänge) setzen

% Kein Abstand vor Kapitelüberschriften
\renewcommand{\chapterheadstartvskip}{\vspace*{-\baselineskip}}
\renewcommand{\chapterheadendvskip}{\vspace*{0.5\baselineskip}}

% Abstände von section und subsection auf basis von scrbook ändern
\makeatletter
\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
{0.5\baselineskip}%
{0.1\baselineskip}%
{\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
\setlength{\parfillskip}{\z@ plus 1fil}\fi
\raggedsection¶
ormalfont\sectfont¶
obreak\size@subsection
}%
}
\renewcommand{\section}{\@startsection{section}{1}{\z@}%
{1\baselineskip}%
{0.5\baselineskip}%
{\ifnum \scr@compatibility >\@nameuse {scr@v@2.96}\relax
\setlength {\parfillskip}{\z@ plus 1fil}\fi
\raggedsection¶
ormalfont\sectfont¶
obreak\size@section
}%
}
\makeatother

% Listen
\usepackage{enumitem}
\renewcommand{\labelitemi}{--}
\setlist[itemize,1]{leftmargin=2em}
\setlist[enumerate,1]{leftmargin=2em}

% Interner Link mit Pfeil mittels \shortrightarrow
\usepackage{stmaryrd}

ewcommand{\internallinkarrow}{\rotatebox[origin=c]{45}{$$\shortrightarrow$$}}

% Bilder
\usepackage{graphicx}
% We will generate all images so they have a width \maxwidth. This means
% that they will get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}

% Merkbox (TODO: schöner)
% Siehe https://tex.stackexchange.com/questions/63752/colored-frame-for-the-framed-environment
\usepackage{framed}
\usepackage{xcolor}
\definecolor{merkboxrahmen}{RGB}{253,243,237}
\definecolor{merkboxhintergrund}{RGB}{244,176,131}

ewenvironment{merkbox}%
{\def\FrameCommand{\fboxsep=\FrameSep\fcolorbox{merkboxrahmen}{merkboxhintergrund}}%
\MakeFramed{\advance\hsize-\width \FrameRestore}}
{\endMakeFramed}

%\usepackage{tcolorbox}

ewenvironment{framed}[1][orange]
%{\begin{tcolorbox}[colframe=#1,colback=yellow]}
%{\end{tcolorbox}}

% Links
\usepackage[setpagesize=false, % page size defined by xetex
unicode=false, % unicode breaks when used with xetex
xetex]{hyperref}

% PDF-Einstellungen
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={$author-meta$},
pdftitle={$title-meta$},
colorlinks=true,
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
pdfborder={0 0 0}}
\urlstyle{same} % don't use monospace font for urls

% Externe Links als Fußnote

ewcommand{\hreffn}[2]{#2\footnote{\url{#1}}}

% Fußnoten fortlaufend
\usepackage{remreset}
\makeatletter
\@removefromreset{footnote}{chapter}
\makeatother

% Interne Links mit Pfeil davor
\let\orighyperref\hyperref
\renewcommand{\hyperref}[2][\mylabel]{%
\def\mylabel{#2}%
\orighyperref[#1]{\internallinkarrow\,#2}%
}

$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
$if(numbersections)$
\setcounter{secnumdepth}{5}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$

% Neue Deutsche Rechtschreibung
\ifxetex
\usepackage{polyglossia}
\setmainlanguage{ngerman}
\else
\usepackage[ngerman]{babel}
\fi

% Abbildungen durchgängig nummerieren
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\renewcommand\figurename{Abb.}

$for(header-includes)$
$header-includes$
$endfor$

\title{$title$}
\author{$for(author)$$author$$sep$ \and $endfor$}
\date{$date$}

\begin{document}
\maketitle

$if(commit-date)$Letzte Änderung: $commit-date$.$endif$

$if(build-date)$Erstellungszeit: $build-date$.$endif$

$for(include-before)$
$include-before$

$endfor$
$if(toc)$
{
\hypersetup{linkcolor=black}
\setcounter{tocdepth}{$toc-depth$}
\renewcommand{\contentsname}{Inhaltsverzeichnis}
\renewcommand{\listfigurename}{Abbildungsverzeichnis}
\tableofcontents
\listoffigures
%\listoftables
}
$endif$
$body$

$if(natbib)$
$if(biblio-files)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$biblio-files$}

$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$

$endif$

$for(include-after)$
$include-after$

$endfor$
\end{document}