Initial commit

This commit is contained in:
Valentin Brandl 2021-02-03 10:44:28 +01:00
commit f411cf6dea
14 changed files with 452 additions and 0 deletions

15
.drone.yml Normal file
View File

@ -0,0 +1,15 @@
---
kind: pipeline
type: docker
name: default
steps:
- name: build
image: nixos/nix
commands:
- nix-build
---
kind: signature
hmac: 830da6e38a18c0405b56b500d229248e30cbaac49df92116a077564489ecbfab
...

1
.envrc Normal file
View File

@ -0,0 +1 @@
eval "$(lorri direnv)"

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
_minted-paper/
*.aux
*.bbl
*.bcf
*.blg
*.fdb_latexmk
*.fls
*.log
*.out
*.pdf
*.run.xml
result
#!cv.pdf

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
# use bash so process substutution is available
SHELL = bash
SRC = main.tex
TARGET = $(SRC:%.tex=%.pdf)
.PHONY: build
build: $(TARGET)
# used for `nix-build`
.PHONY: install
install: build
mkdir -pv ${out}/
cp $(TARGET) ${out}/
%.pdf: %.tex
latexmk $<
.PHONY: watch
watch:
latexmk -pvc $(SRC)
.PHONY: lint
lint:
chktex $(SRC)
.PHONY: languagetool
languagetool:
languagetool <(cat $(SRC) | ./scripts/detex.py)
.PHONY: clean
clean:
latexmk -C

4
acronyms.tex Normal file
View File

@ -0,0 +1,4 @@
\DeclareAcronym{html}{
short = HTML,
long = hyper text markup language
}

51
default.nix Normal file
View File

@ -0,0 +1,51 @@
# { pkgs ? import (import nix/fetch-nixpkgs.nix) {}
# }:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
latexPackage = pkgs.texlive.combine {
inherit (texlive)
# base packages
scheme-small
csquotes
latexmk
moderncv
needspace
fontawesome
silence
wrapfig
enumitem
mathpazo
;
};
in
stdenv.mkDerivation {
name = "story";
buildInputs = [
latexPackage
# language correction
pkgs.languagetool
# detex script
pkgs.python
# make
pkgs.gnumake
# PDF viewer
pkgs.zathura
];
src = ./.;
buildPhase = "make";
meta = with lib; {
description = "Deterministic LaTeX template using Nix";
license = licenses.bsd3;
platforms = platforms.linux;
};
}

114
diazessay.cls Normal file
View File

@ -0,0 +1,114 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Diaz Essay
% LaTeX Class
% Version 1.0 (13/1/19)
%
% This class originates from:
% http://www.LaTeXTemplates.com
%
% Authors:
% Vel (vel@LaTeXTemplates.com)
% Nicolas Diaz (nsdiaz@uc.cl)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------------------
% CLASS CONFIGURATION
%----------------------------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{diazessay}[2019/01/13 Diaz Essay class v1.0]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} % Pass through any options to the base class
\ProcessOptions\relax % Process given options
\LoadClass{article} % Load the base class
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage[english]{babel} % English language hyphenation
\usepackage{graphicx} % Required for including images
\graphicspath{{Figures/}{./}} % Specifies where to look for included images (trailing slash required)
\usepackage{wrapfig} % Allows in-line images
\usepackage{booktabs} % Required for better horizontal rules in tables
\usepackage{enumitem} % Required for list customisation
\setlist{noitemsep} % No spacing between list items
\makeatletter
\renewcommand\@biblabel[1]{\textbf{#1.}} % Remove the square brackets from each bibliography item ('[1]' to '1.')
\makeatother
%----------------------------------------------------------------------------------------
% DOCUMENT MARGINS
%----------------------------------------------------------------------------------------
\usepackage{geometry} % Required for adjusting page dimensions and margins
\geometry{
paper=a4paper, % Paper size, change to letterpaper for US letter size
top=2.5cm, % Top margin
bottom=3cm, % Bottom margin
left=4cm, % Left margin
right=4cm, % Right margin
headheight=0.75cm, % Header height
footskip=1.5cm, % Space from the bottom margin to the baseline of the footer
headsep=0.75cm, % Space from the top margin to the baseline of the header
%showframe, % Uncomment to show how the type block is set on the page
}
%----------------------------------------------------------------------------------------
% FONTS
%----------------------------------------------------------------------------------------
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Use 8-bit encoding
\usepackage{mathpazo} % Use the Palatino font
\usepackage[protrusion=true, expansion=true]{microtype} % Better typography
\linespread{1.05} % Increase line spacing slightly; Palatino benefits from a slight increase by default
%----------------------------------------------------------------------------------------
% TITLE
%----------------------------------------------------------------------------------------
\makeatletter
\renewcommand{\maketitle}{ % Customise the title (do not edit title and author name here)
\vspace*{30pt} % Vertical whitespace before the title
\begin{flushright} % Right align
{\LARGE\@title} % Increase the font size of the title
\vspace{50pt} % Vertical whitespace between the title and author name
{\large\@author}\\ % Author name
\@date % Date
\vspace{40pt} % Vertical whitespace between the author block and abstract
\end{flushright}
}
\makeatother
%----------------------------------------------------------------------------------------
% HEADERS AND FOOTERS
%----------------------------------------------------------------------------------------
\usepackage{fancyhdr} % Required for customising headers and footers
\pagestyle{fancy} % Enable custom headers and footers
\renewcommand{\headrulewidth}{0pt} % Remove default top horizontal rule
\lhead{} % Left header
\chead{} % Centre header
\rhead{} % Right header
\lfoot{} % Left footer
\cfoot{\thepage} % Centre footer
\rfoot{} % Right footer

15
latexmkrc Normal file
View File

@ -0,0 +1,15 @@
# create PDF
$pdf_mode = 1;
# clean transitive assets
$cleanup_includes_cusdep_generated = 1;
# clean files generated by LaTeX
$cleanup_includes_generated = 1;
$biber = 'biber --validate-datamodel %O %S';
# use zathura as viewer
$pdf_previewer = 'zathura';
$pdflatex = 'pdflatex --shell-escape -interaction=nonstopmode';
$latex = 'latex --shell-escape -interaction=nonstopmode';

58
main.tex Normal file
View File

@ -0,0 +1,58 @@
% silence external warnings
\RequirePackage{silence}
\WarningFilter{scrreprt}{Usage of package `titlesec'}
\WarningFilter{scrreprt}{Activating an ugly workaround}
\WarningFilter{titlesec}{Non standard sectioning command detected}
\WarningFilter{microtype}{protrusion codes list}
\WarningFilter{latexfont}{Font}
\WarningFilter{latexfont}{Some font shapes}
\documentclass[11pt]{diazessay}
% document language
% \usepackage[ngerman]{babel}
% UTF-8 encoding
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% language specific quotes
\usepackage{csquotes}
\usepackage{needspace}
% make overfull hbox warnings prominently visible in document
\overfullrule=2cm
% \usepackage[scale=0.75]{geometry}
\title{\textbf{Main Title} \\ {\Large\itshape Subtitle}}
\author{Valentin Brandl}
% \date{\today}
\date{}
\begin{document}
\maketitle
\begin{abstract}
Foo Bar baz lel
\end{abstract}
\hspace*{3.6mm}\textit{Keywords:} foo, bar, baz, trololol
\vspace{30pt}
\section*{Once upon a time}
\section*{Once upon a time}
\end{document}
% vim: set filetype=tex ts=2 sw=2 tw=0 et :

6
nix/fetch-nixpkgs.nix Normal file
View File

@ -0,0 +1,6 @@
let
spec = builtins.fromJSON (builtins.readFile ./nixpkgs-src.json);
in builtins.fetchTarball {
url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
inherit (spec) sha256;
}

9
nix/nixpkgs-src.json Normal file
View File

@ -0,0 +1,9 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"url": "https://github.com/nixos/nixpkgs",
"rev": "6a3f5bcb061e1822f50e299f5616a0731636e4e7",
"date": "2018-10-05T18:33:19-04:00",
"sha256": "1ib96has10v5nr6bzf7v8kw7yzww8zanxgw2qi1ll1sbv6kj6zpd",
"fetchSubmodules": false
}

12
scripts/detex-languagetool.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
dir_path = os.path.dirname(os.path.realpath(__file__))
subprocess.call('cat ' + sys.argv[-1] + ' | '
+ os.path.join(dir_path, 'detex.py') + ' | '
+ 'languagetool ' + ' '.join(sys.argv[1:-1]),
shell=True)

81
scripts/detex.py Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env python3
import re
import sys
def swallow(match):
return ' ' * len(match.group(0))
def swallow_command(match):
return ' ' * (len(match.group(1)) + 1) + ' ' + match.group(2) + ' '
def main():
text = sys.stdin.read()
text_len = len(text)
# \hyp
text = re.subn(r'(\w+)\\hyp\{\}(\w+)', r' \1-\2 ', text)[0]
text = re.subn(r'(\w+)\\fshyp\{\}(\w+)', r' \1-\2 ', text)[0]
# glossary entries
def replace_glossary(match):
text = match.group(2).replace('-', ' ')
if match.group(1).endswith('pl'):
text += 's'
if match.group(1)[0].isupper():
text = text[0].upper() + text[1:]
text = ' ' * len(match.group(1)) + ' ' + text + ' '
if match.group(1).endswith('pl'):
text = text[1:]
return text
text = re.subn(r'\\((?:newdef)?[gG]ls(?:pl)?){((?:\w+-?)+?)}',
replace_glossary, text)[0]
# acronyms
def replace_acronym(match):
return ' ' * len(match.group(1)) + ' ' + match.group(2) + ' '
text = re.subn(r'\\([aA]cr.*?){(.+?)}',
replace_acronym, text)[0]
# remove keypoints
text = re.subn(r'\\keypoint\{.*?\}', swallow, text)[0]
# remove autocites
text = re.subn(r'~?\\[aA]utocite(?:\[.+?\])?\{.*?\}', swallow, text)[0]
# Remove textcites
def replace_textcite(match):
template = 'Foo and Bar'
return template + ' ' * (len(match.group(0)) - len(template))
text = re.subn(r'\\[tT]extcite\{(.*?)\}', replace_textcite, text)[0]
# citesoftware
text = re.subn(r'\\(citesoftware)\{(.*?)\}', swallow_command, text)[0]
# Remove common surrounding markup
text = re.subn(r'\\(emph|texttt|textit|texttt|texthtt)\{(.*?)\}',
swallow_command, text)[0]
# Remove abbreviations
text = re.subn(r'\\eg\b', 'eg.', text)[0]
text = re.subn(r'\\cf\b', 'cf.', text)[0]
text = re.subn(r'\\ie\b', 'ie.', text)[0]
# references
text = re.subn(r'\\([vV]?ref)\{(.*?)\}', swallow_command, text)[0]
# remove comments at line end
text = re.subn(r'([^\\])%.*', '\\1', text)[0]
# do not move things around too much
print(text)
assert len(text) == text_len
if __name__ == '__main__':
main()

39
shell.nix Normal file
View File

@ -0,0 +1,39 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
latexPackage = pkgs.texlive.combine {
inherit (texlive)
# base packages
scheme-small
csquotes
latexmk
moderncv
needspace
fontawesome
silence
wrapfig
enumitem
mathpazo
;
};
in
pkgs.mkShell {
buildInputs = [
latexPackage
# language correction
pkgs.languagetool
# detex script
pkgs.python
# make
pkgs.gnumake
# PDF viewer
pkgs.zathura
];
}