Skip to content

Commit

Permalink
Restructured build process and added HTML output format. Also created…
Browse files Browse the repository at this point in the history
… TODO in README.md
  • Loading branch information
TilBlechschmidt committed Mar 1, 2019
1 parent cfba5b6 commit b04589d
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 68 deletions.
6 changes: 6 additions & 0 deletions .build/FlagsGeneral.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-F pandoc-crossref
-F pandoc-citeproc
--bibliography=src/bibliography.yaml
--csl .template/ieee.csl
--metadata-file=.template/metadata.yml
--lua-filter=.template/date.lua
7 changes: 7 additions & 0 deletions .build/FlagsHTML.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--standalone
--self-contained
--number-sections
--toc
--css=.template/html/layout.css
--template=.template/html/template.phtml
-t html5
6 changes: 6 additions & 0 deletions .build/FlagsPDF.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--template=.template/tex/template.tex
--include-in-header=.template/tex/packages.tex
--include-before-body=.template/tex/theme.tex
--include-before-body=.template/tex/layout.tex
--number-sections
-t latex
1 change: 1 addition & 0 deletions .build/FlagsPlaintext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-t plain
2 changes: 1 addition & 1 deletion .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ services:
build: .
command: ${BUILD_PARAMETERS:-build}
volumes:
- ../:/project
- ../:/project
6 changes: 6 additions & 0 deletions .template/date.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function Meta(m)
language, _ = m["lang"][1]["text"]:gsub("-", "_")
os.setlocale(language)
m.date = os.date("%B %e, %Y")
return m
end
51 changes: 51 additions & 0 deletions .template/html/layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@import url('https://cdn.rawgit.com/dreampulse/computer-modern-web-font/master/font/Sans/cmun-sans.css');

html {
background-color: #455a64;
font-family: "Computer Modern Sans", sans-serif;
}

body {
background-color: #fafafa;

margin: 16px auto;
max-width: 1000px;
min-width: 600px;
width: 50%;

padding: 32px;

box-shadow: 0px 6px 6px -3px rgba(0,0,0,0.2),0px 10px 14px 1px rgba(0,0,0,0.14),0px 4px 18px 3px rgba(0,0,0,0.12);
}

#title-block-header {
text-align: center;
}

#title-block-header::before {
content: '';
background: url('../logo.png');
background-size: cover;
width: 300px;
height: 91.3px;
display: block;
margin: 64px auto;
}

#title-block-header, #TOC {
padding-bottom: 32px;
margin-bottom: 32px;
border-bottom: 1px solid #eee;
}

a {
color: rgb(5, 56, 121);
margin-bottom: 2px;
border-bottom: 0px solid black;
transition: all .2s ease-in-out;
text-decoration: none;
}

a:hover {
border-bottom-width: 2px;
}
72 changes: 72 additions & 0 deletions .template/html/template.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$" />
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
$if(quotes)$
q { quotes: "“" "”" "‘" "’"; }
$endif$
</style>
$if(highlighting-css)$
<style>
$highlighting-css$
</style>
$endif$
$for(css)$
<link rel="stylesheet" href="$css$" />
$endfor$
$if(math)$
$math$
$endif$
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
$for(header-includes)$
$header-includes$
$endfor$
</head>
<body>
$for(include-before)$
$include-before$
$endfor$
$if(title)$
<header id="title-block-header">
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC">
$table-of-contents$
</nav>
$endif$
$body$
$for(include-after)$
$include-after$
$endfor$
</body>
</html>
Binary file removed .template/logo.jpg
Binary file not shown.
Binary file added .template/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .template/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ link-citations: true
Deckblatt: true
toc: true
lot: false
lof: false
lof: false
File renamed without changes.
File renamed without changes.
22 changes: 8 additions & 14 deletions .template/template.tex → .template/tex/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,6 @@
$endif$

\begin{document}
$if(title)$
$if(beamer)$
\frame{\titlepage}
$else$
\maketitle
\pagebreak
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
$endif$

$if(Deckblatt)$
\begin{center}
Expand All @@ -408,10 +395,17 @@
\begin{center}
\begin{tabularx}{\textwidth}{r|X}
Matrikelnummer & $Matrikelnummer$ \\\midrule
Thema & $Thema$ \\\midrule
Thema & $title$ \\\midrule
Studiengang, Zenturie & $Studiengang$, $Zenturie$\
\end{tabularx}
\end{center}

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

\pagebreak
$endif$

Expand Down
File renamed without changes.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
# Boilerplate for scientific research papers
# How to write scientific papers - the simple way

- How to
- Setup
- Clone/Fork
- IDE Setups
- VSCode
- Template change pull
- Push template changes
- Build (macOS, Linux, Windoof)
- Write feedback
- Write document
- Common metadata attributes
- LOF/LOT
- Removing title page
- Citation
- References (sections, images, ...)
- File overview
- Project
- Template
- Referenzen
- Pandoc
- Markdown (Pandoc style)

## Pandoc-Markdown reference

Expand Down
139 changes: 92 additions & 47 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,64 @@
#!/bin/sh
watch() {
fswatch src | xargs -L 1 ./build.sh build
}
#!/usr/bin/env bash
OUTPUT_FOLDER="out"
OUTPUT_FILE="${OUTPUT_FOLDER}/main"

# Flags for pandoc
PANDOC_INPUT="src/*.md"
FLAGS_PANDOC=$(cat .build/FlagsGeneral.txt)
FLAGS_PDF="${FLAGS_PANDOC} $(cat .build/FlagsPDF.txt)"
FLAGS_HTML="${FLAGS_PANDOC} $(cat .build/FlagsHTML.txt)"
FLAGS_PLAINTEXT="${FLAGS_PANDOC} $(cat .build/FlagsPlaintext.txt)"

build() {
pandoc src/*.md \
--number-sections \
-F pandoc-crossref \
-F pandoc-citeproc \
--bibliography=src/bibliography.yaml \
--csl .template/ieee.csl \
--template=.template/template.tex \
--include-in-header=.template/packages.tex \
--include-before-body=.template/theme.tex \
--include-before-body=.template/layout.tex \
--metadata-file=.template/metadata.yml \
-o out/main.pdf
}
PREFIX=""
if [ "$2" = true ]; then
PREFIX="$(date "+[%H:%M:%S]") "
fi

MESSAGE="${PREFIX}Building for target '${TARGET}' ..."

echo ${MESSAGE}

mkdir -p ${OUTPUT_FOLDER}

case $1 in
pdf)
pandoc ${PANDOC_INPUT} ${FLAGS_PDF} -o "${OUTPUT_FILE}.pdf"
;;
plaintext)
pandoc ${PANDOC_INPUT} ${FLAGS_PLAINTEXT} -o "${OUTPUT_FILE}.txt"
;;
html)
pandoc ${PANDOC_INPUT} ${FLAGS_HTML} -o "${OUTPUT_FILE}.html"
;;
*)
echo -e "\r\033[1A\033[0KInvalid target: '${TARGET}'"
return -1
;;
esac

spellcheck() {
pandoc src/*.md \
-F pandoc-crossref \
-F pandoc-citeproc \
--bibliography=src/bibliography.yaml \
--csl .template/ieee.csl \
--template=.template/template.tex \
--include-in-header=.template/packages.tex \
--include-before-body=.template/theme.tex \
--include-before-body=.template/layout.tex \
--metadata-file=.template/metadata.yml \
-t plain \
-o out/main.txt
local status=$?

if [ $status -ne 0 ]; then
echo -e "\n${MESSAGE} \033[31merror\033[0m" >&2
else
echo -e "\r\033[1A\033[0K${MESSAGE} \033[32mdone\033[0m"
fi

return $status
}

help() {
cat << EOF
Markdown typesetting tool.
usage:
build.sh [--docker][--help] command
build.sh [--target type][--docker][--help]
parameters:
--docker run inside docker container.
--help print this.
commands:
build typeset src/main.md -> out/main.pdf
spellcheck typeset src/main.md -> out/main.txt
watch watch src and execute build on file change.
--target Determines the output file type. One of: pdf, html, plaintext
--docker Run inside docker container. Ignored if already inside a container.
--help Print this help.
examples:
build.sh watch
Expand All @@ -57,12 +68,46 @@ Markdown typesetting tool.
EOF
}

mkdir -p out
case $1 in
--help) help;;
--docker) BUILD_PARAMETERS="${@:2}" docker-compose -p latex_build -f .docker/docker-compose.yml up;;
build) build;;
watch) watch;;
spellcheck) spellcheck;;
*) build;;
esac
PARAMETERS="$@"

DOCKER=false
TARGET=pdf
WATCH=false

while [[ $# -gt 0 ]]; do
case $1 in
-t|--target)
TARGET="$2"
shift
shift
;;
-d|--docker)
DOCKER=true
shift
;;
-w|--watch)
WATCH=true
shift
;;
-h|--help)
help
exit
;;
*)
# unknown option
shift
;;
esac
done

# When asked to run in docker and we are not already then move into the matrix.
if [ ! -f /.dockerenv ] && [ "$DOCKER" = true ]; then
BUILD_PARAMETERS="${PARAMETERS}" docker-compose -p latex_build -f .docker/docker-compose.yml up
exit
fi

if [ "$WATCH" = true ]; then
fswatch src | while read -r changed_path; do build $TARGET true; done
else
build $TARGET
fi
Loading

0 comments on commit b04589d

Please sign in to comment.