Add pandoc for PDF creation and GitHub Actions for auto-generation

pull/632/head
Rick Calixte 2021-12-26 02:00:40 -05:00
parent 3df19b2e4f
commit f733e5970e
No known key found for this signature in database
32 changed files with 1092 additions and 169 deletions

46
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,46 @@
---
name: Generate PDF using Pandoc
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "create_pdf"
create_pdf:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Pandoc Docker image v3.2.1.0
container:
image: pandoc/latex:3.2.1.0
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Run the PDF creation script in the container
- uses: docker://pandoc/latex:3.2.1.0
with:
entrypoint: './pandoc-docker.sh'
# Create an output with the shortened version of the commit SHA
- id: short_sha
env:
GITHUB_SHA: ${{ github.sha }}
run: echo "::set-output name=short_sha::$(echo ${GITHUB_SHA::7})"
# Create a release with the PDFs as assets and the shortened SHA as the tag name
- uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.short_sha.outputs.short_sha }}
draft: false
files: |
*.pdf

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Byte-compiled / optimized / DLL files
*.epub
*.pdf
__pycache__/
*.py[cod]

View File

@ -1,4 +1,4 @@
*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) ∙ [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) ∙ [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) ∙ [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [עברית](https://github.com/donnemartin/system-design-primer/issues/272) ∙ [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [한국어](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polski](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Español](https://github.com/donnemartin/system-design-primer/issues/136) ∙ [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) ∙ [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) ∙ [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
*[English](README.md) • [日本語](README-ja.md) • [简体中文](README-zh-Hans.md) • [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) • [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) • [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) • [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) • [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) • [עברית](https://github.com/donnemartin/system-design-primer/issues/272) • [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) • [한국어](https://github.com/donnemartin/system-design-primer/issues/102) • [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) • [Polski](https://github.com/donnemartin/system-design-primer/issues/68) • [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) • [Español](https://github.com/donnemartin/system-design-primer/issues/136) • [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) • [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) • [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) • [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
# システム設計入門

View File

@ -3,7 +3,7 @@
> * 译者:[XatMassacrE](https://github.com/XatMassacrE)、[L9m](https://github.com/L9m)、[Airmacho](https://github.com/Airmacho)、[xiaoyusilen](https://github.com/xiaoyusilen)、[jifaxu](https://github.com/jifaxu)、[根号三](https://github.com/sqrthree)
> * 这个 [链接](https://github.com/xitu/system-design-primer/compare/master...donnemartin:master) 用来查看本翻译与英文版是否有差别(如果你没有看到 README.md 发生变化,那就意味着这份翻译文档是最新的)。
*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) ∙ [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) ∙ [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) ∙ [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [עברית](https://github.com/donnemartin/system-design-primer/issues/272) ∙ [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [한국어](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polski](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Español](https://github.com/donnemartin/system-design-primer/issues/136) ∙ [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) ∙ [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) ∙ [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
*[English](README.md) • [日本語](README-ja.md) • [简体中文](README-zh-Hans.md) • [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) • [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) • [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) • [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) • [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) • [עברית](https://github.com/donnemartin/system-design-primer/issues/272) • [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) • [한국어](https://github.com/donnemartin/system-design-primer/issues/102) • [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) • [Polski](https://github.com/donnemartin/system-design-primer/issues/68) • [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) • [Español](https://github.com/donnemartin/system-design-primer/issues/136) • [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) • [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) • [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) • [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
# 系统设计入门
@ -1193,7 +1193,7 @@ def get_user(self, user_id):
##### 缓存的缺点:
- 请求的数据如果不在缓存中就需要经过三个步骤来获取数据,这会导致明显的延迟。
- 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。
- 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。
- 当一个节点出现故障的时候,它将会被一个新的节点替代,这增加了延迟的时间。
#### 直写模式

View File

@ -1,4 +1,4 @@
*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) ∙ [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) ∙ [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) ∙ [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [עברית](https://github.com/donnemartin/system-design-primer/issues/272) ∙ [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [한국어](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polski](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Español](https://github.com/donnemartin/system-design-primer/issues/136) ∙ [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) ∙ [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) ∙ [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
*[English](README.md) • [日本語](README-ja.md) • [简体中文](README-zh-Hans.md) • [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) • [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) • [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) • [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) • [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) • [עברית](https://github.com/donnemartin/system-design-primer/issues/272) • [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) • [한국어](https://github.com/donnemartin/system-design-primer/issues/102) • [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) • [Polski](https://github.com/donnemartin/system-design-primer/issues/68) • [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) • [Español](https://github.com/donnemartin/system-design-primer/issues/136) • [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) • [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) • [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) • [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
# 系統設計入門

206
README.md
View File

@ -1,4 +1,4 @@
*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) ∙ [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) ∙ [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) ∙ [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [עברית](https://github.com/donnemartin/system-design-primer/issues/272) ∙ [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [한국어](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polski](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Español](https://github.com/donnemartin/system-design-primer/issues/136) ∙ [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) ∙ [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) ∙ [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
*[English](README.md) • [日本語](README-ja.md) • [简体中文](README-zh-Hans.md) • [繁體中文](README-zh-TW.md) | [العَرَبِيَّة‎](https://github.com/donnemartin/system-design-primer/issues/170) • [বাংলা](https://github.com/donnemartin/system-design-primer/issues/220) • [Português do Brasil](https://github.com/donnemartin/system-design-primer/issues/40) • [Deutsch](https://github.com/donnemartin/system-design-primer/issues/186) • [ελληνικά](https://github.com/donnemartin/system-design-primer/issues/130) • [עברית](https://github.com/donnemartin/system-design-primer/issues/272) • [Italiano](https://github.com/donnemartin/system-design-primer/issues/104) • [한국어](https://github.com/donnemartin/system-design-primer/issues/102) • [فارسی](https://github.com/donnemartin/system-design-primer/issues/110) • [Polski](https://github.com/donnemartin/system-design-primer/issues/68) • [русский язык](https://github.com/donnemartin/system-design-primer/issues/87) • [Español](https://github.com/donnemartin/system-design-primer/issues/136) • [ภาษาไทย](https://github.com/donnemartin/system-design-primer/issues/187) • [Türkçe](https://github.com/donnemartin/system-design-primer/issues/39) • [tiếng Việt](https://github.com/donnemartin/system-design-primer/issues/127) • [Français](https://github.com/donnemartin/system-design-primer/issues/250) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)*
**Help [translate](TRANSLATIONS.md) this guide!**
@ -45,10 +45,7 @@ Additional topics for interview prep:
## Anki flashcards
<p align="center">
<img src="images/zdCAkB3.png">
<br/>
</p>
![Anki flashcards](images/zdCAkB3.png)
The provided [Anki flashcard decks](https://apps.ankiweb.net/) use spaced repetition to help you retain key system design concepts.
@ -62,10 +59,7 @@ Great for use while on-the-go.
Looking for resources to help you prep for the [**Coding Interview**](https://github.com/donnemartin/interactive-coding-challenges)?
<p align="center">
<img src="images/b4YtAEN.png">
<br/>
</p>
![Interactive Coding Challenges](images/b4YtAEN.png)
Check out the sister repo [**Interactive Coding Challenges**](https://github.com/donnemartin/interactive-coding-challenges), which contains an additional Anki deck:
@ -183,7 +177,7 @@ Review the [Contributing Guidelines](CONTRIBUTING.md).
> Suggested topics to review based on your interview timeline (short, medium, long).
![Imgur](images/OfVllex.png)
![Study Guide](images/OfVllex.png)
**Q: For interviews, do I need to know everything here?**
@ -306,49 +300,49 @@ Check out the following links to get a better idea of what to expect:
[View exercise and solution](solutions/system_design/pastebin/README.md)
![Imgur](images/4edXG0T.png)
![Scaled design of Pastebin.com (or Bit.ly)](images/4edXG0T.png)
### Design the Twitter timeline and search (or Facebook feed and search)
[View exercise and solution](solutions/system_design/twitter/README.md)
![Imgur](images/jrUBAF7.png)
![Scaled design of the Twitter timeline and search (or Facebook feed and search)](images/jrUBAF7.png)
### Design a web crawler
[View exercise and solution](solutions/system_design/web_crawler/README.md)
![Imgur](images/bWxPtQA.png)
![Scaled design of a web crawler](images/bWxPtQA.png)
### Design Mint.com
[View exercise and solution](solutions/system_design/mint/README.md)
![Imgur](images/V5q57vU.png)
![Scaled design of Mint.com](images/V5q57vU.png)
### Design the data structures for a social network
[View exercise and solution](solutions/system_design/social_graph/README.md)
![Imgur](images/cdCv5g7.png)
![Scaled design of the data structures for a social network](images/cdCv5g7.png)
### Design a key-value store for a search engine
[View exercise and solution](solutions/system_design/query_cache/README.md)
![Imgur](images/4j99mhe.png)
![Scaled design of a key-value store for a search engine](images/4j99mhe.png)
### Design Amazon's sales ranking by category feature
[View exercise and solution](solutions/system_design/sales_rank/README.md)
![Imgur](images/MzExP06.png)
![Scaled design of Amazon's sales ranking by category feature](images/MzExP06.png)
### Design a system that scales to millions of users on AWS
[View exercise and solution](solutions/system_design/scaling_aws/README.md)
![Imgur](images/jj3A5N8.png)
![Scaled design of a system that scales to millions of users on AWS](images/jj3A5N8.png)
## Object-oriented design interview questions with solutions
@ -439,11 +433,8 @@ Generally, you should aim for **maximal throughput** with **acceptable latency**
### CAP theorem
<p align="center">
<img src="images/bgLMI2u.png">
<br/>
<i><a href=http://robertgreiner.com/2014/08/cap-theorem-revisited>Source: CAP theorem revisited</a></i>
</p>
![CAP theorem](images/bgLMI2u.png)
[Source: CAP theorem revisited](https://robertgreiner.com/cap-theorem-revisited)
In a distributed computer system, you can only support two of the following guarantees:
@ -580,11 +571,8 @@ If both `Foo` and `Bar` each had 99.9% availability, their total availability in
## Domain name system
<p align="center">
<img src="images/IOyLj4i.jpg">
<br/>
<i><a href=http://www.slideshare.net/srikrupa5/dns-security-presentation-issa>Source: DNS security presentation</a></i>
</p>
![Simple DNS lookup](images/IOyLj4i.jpg)
[Source: DNS security presentation](https://www.slideshare.net/srikrupa5/dns-security-presentation-issa)
A Domain Name System (DNS) translates a domain name such as www.example.com to an IP address.
@ -618,11 +606,8 @@ Services such as [CloudFlare](https://www.cloudflare.com/dns/) and [Route 53](ht
## Content delivery network
<p align="center">
<img src="images/h9TAuGI.jpg">
<br/>
<i><a href=https://www.creative-artworks.eu/why-use-a-content-delivery-network-cdn/>Source: Why use a CDN</a></i>
</p>
![Content delivery network](images/h9TAuGI.jpg)
[Source: Why use a CDN](https://www.creative-artworks.eu/why-use-a-content-delivery-network-cdn/)
A content delivery network (CDN) is a globally distributed network of proxy servers, serving content from locations closer to the user. Generally, static files such as HTML/CSS/JS, photos, and videos are served from CDN, although some CDNs such as Amazon's CloudFront support dynamic content. The site's DNS resolution will tell clients which server to contact.
@ -659,11 +644,8 @@ Sites with heavy traffic work well with pull CDNs, as traffic is spread out more
## Load balancer
<p align="center">
<img src="images/h81n9iK.png">
<br/>
<i><a href=http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html>Source: Scalable system design patterns</a></i>
</p>
![Load balancer pattern](images/h81n9iK.png)
[Source: Scalable system design patterns](https://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html)
Load balancers distribute incoming client requests to computing resources such as application servers and databases. In each case, the load balancer returns the response from the computing resource to the appropriate client. Load balancers are effective at:
@ -729,12 +711,8 @@ Load balancers can also help with horizontal scaling, improving performance and
## Reverse proxy (web server)
<p align="center">
<img src="images/n41Azff.png">
<br/>
<i><a href=https://upload.wikimedia.org/wikipedia/commons/6/67/Reverse_proxy_h2g2bob.svg>Source: Wikipedia</a></i>
<br/>
</p>
![Reverse proxy (web server)](images/n41Azff.png)
[Source: Wikipedia](https://upload.wikimedia.org/wikipedia/commons/6/67/Reverse_proxy_h2g2bob.svg)
A reverse proxy is a web server that centralizes internal services and provides unified interfaces to the public. Requests from clients are forwarded to a server that can fulfill it before the reverse proxy returns the server's response to the client.
@ -772,11 +750,8 @@ Additional benefits include:
## Application layer
<p align="center">
<img src="images/yB5SYwm.png">
<br/>
<i><a href=http://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer>Source: Intro to architecting systems for scale</a></i>
</p>
![Load balancing requests](images/yB5SYwm.png)
[Source: Intro to architecting systems for scale](https://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer)
Separating out the web layer from the application layer (also known as platform layer) allows you to scale and configure both layers independently. Adding a new API results in adding application servers without necessarily adding additional web servers. The **single responsibility principle** advocates for small and autonomous services that work together. Small teams with small services can plan more aggressively for rapid growth.
@ -807,11 +782,8 @@ Systems such as [Consul](https://www.consul.io/docs/index.html), [Etcd](https://
## Database
<p align="center">
<img src="images/Xkm5CXz.png">
<br/>
<i><a href=https://www.youtube.com/watch?v=kKjm4ehYiMs>Source: Scaling up to your first 10 million users</a></i>
</p>
![Scaled database serving traffic](images/Xkm5CXz.png)
[Source: Scaling up to your first 10 million users](https://www.youtube.com/watch?v=kKjm4ehYiMs)
### Relational database management system (RDBMS)
@ -830,11 +802,8 @@ There are many techniques to scale a relational database: **master-slave replica
The master serves reads and writes, replicating writes to one or more slaves, which serve only reads. Slaves can also replicate to additional slaves in a tree-like fashion. If the master goes offline, the system can continue to operate in read-only mode until a slave is promoted to a master or a new master is provisioned.
<p align="center">
<img src="images/C9ioGtn.png">
<br/>
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
</p>
![Master-slave replication](images/C9ioGtn.png)
[Source: Scalability, availability, stability, patterns](https://www.slideshare.net/jboner/scalability-availability-stability-patterns)
##### Disadvantage(s): master-slave replication
@ -845,11 +814,8 @@ The master serves reads and writes, replicating writes to one or more slaves, wh
Both masters serve reads and writes and coordinate with each other on writes. If either master goes down, the system can continue to operate with both reads and writes.
<p align="center">
<img src="images/krAHLGg.png">
<br/>
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
</p>
![Master-master replication](images/krAHLGg.png)
[Source: Scalability, availability, stability, patterns](https://www.slideshare.net/jboner/scalability-availability-stability-patterns)
##### Disadvantage(s): master-master replication
@ -873,11 +839,8 @@ Both masters serve reads and writes and coordinate with each other on writes. I
#### Federation
<p align="center">
<img src="images/U3qV33e.png">
<br/>
<i><a href=https://www.youtube.com/watch?v=kKjm4ehYiMs>Source: Scaling up to your first 10 million users</a></i>
</p>
![Functional partitioning (federation)](images/U3qV33e.png)
[Source: Scaling up to your first 10 million users](https://www.youtube.com/watch?v=kKjm4ehYiMs)
Federation (or functional partitioning) splits up databases by function. For example, instead of a single, monolithic database, you could have three databases: **forums**, **users**, and **products**, resulting in less read and write traffic to each database and therefore less replication lag. Smaller databases result in more data that can fit in memory, which in turn results in more cache hits due to improved cache locality. With no single central master serializing writes you can write in parallel, increasing throughput.
@ -894,11 +857,8 @@ Federation (or functional partitioning) splits up databases by function. For ex
#### Sharding
<p align="center">
<img src="images/wU8x5Id.png">
<br/>
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
</p>
![Sharding](images/wU8x5Id.png)
[Source: Scalability, availability, stability, patterns](https://www.slideshare.net/jboner/scalability-availability-stability-patterns)
Sharding distributes data across different databases such that each database can only manage a subset of the data. Taking a users database as an example, as the number of users increases, more shards are added to the cluster.
@ -1038,11 +998,8 @@ Document stores provide high flexibility and are often used for working with occ
#### Wide column store
<p align="center">
<img src="images/n16iOGk.png">
<br/>
<i><a href=http://blog.grio.com/2015/11/sql-nosql-a-brief-history.html>Source: SQL & NoSQL, a brief history</a></i>
</p>
![Wide column store](images/n16iOGk.png)
[Source: SQL & NoSQL, a brief history](https://blog.grio.com/2015/11/sql-nosql-a-brief-history.html)
> Abstraction: nested map `ColumnFamily<RowKey, Columns<ColKey, Value, Timestamp>>`
@ -1061,11 +1018,8 @@ Wide column stores offer high availability and high scalability. They are often
#### Graph database
<p align="center">
<img src="images/fNcl65g.png">
<br/>
<i><a href=https://en.wikipedia.org/wiki/File:GraphDatabase_PropertyGraph.png>Source: Graph database</a></i>
</p>
![Graph database](images/fNcl65g.png)
[Source: Graph database](https://en.wikipedia.org/wiki/File:GraphDatabase_PropertyGraph.png)
> Abstraction: graph
@ -1089,11 +1043,8 @@ Graphs databases offer high performance for data models with complex relationshi
### SQL or NoSQL
<p align="center">
<img src="images/wXGqG5f.png">
<br/>
<i><a href=https://www.infoq.com/articles/Transition-RDBMS-NoSQL/>Source: Transitioning from RDBMS to NoSQL</a></i>
</p>
![SQL or NoSQL](images/wXGqG5f.png)
[Source: Transitioning from RDBMS to NoSQL](https://www.infoq.com/articles/Transition-RDBMS-NoSQL)
Reasons for **SQL**:
@ -1131,11 +1082,8 @@ Sample data well-suited for NoSQL:
## Cache
<p align="center">
<img src="images/Q6z24La.png">
<br/>
<i><a href=http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html>Source: Scalable system design patterns</a></i>
</p>
![Cache](images/Q6z24La.png)
[Source: Scalable system design patterns](https://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html)
Caching improves page load times and can reduce the load on your servers and databases. In this model, the dispatcher will first lookup if the request has been made before and try to find the previous result to return, in order to save the actual execution.
@ -1202,11 +1150,8 @@ Since you can only store a limited amount of data in cache, you'll need to deter
#### Cache-aside
<p align="center">
<img src="images/ONjORqk.png">
<br/>
<i><a href=http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast>Source: From cache to in-memory data grid</a></i>
</p>
![Cache-aside](images/ONjORqk.png)
[Source: From cache to in-memory data grid](https://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast)
The application is responsible for reading and writing from storage. The cache does not interact with storage directly. The application does the following:
@ -1238,11 +1183,8 @@ Subsequent reads of data added to cache are fast. Cache-aside is also referred
#### Write-through
<p align="center">
<img src="images/0vBc0hN.png">
<br/>
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
</p>
![Write-through](images/0vBc0hN.png)
[Source: Scalability, availability, stability, patterns](https://www.slideshare.net/jboner/scalability-availability-stability-patterns)
The application uses the cache as the main data store, reading and writing data to it, while the cache is responsible for reading and writing to the database:
@ -1273,11 +1215,8 @@ Write-through is a slow overall operation due to the write operation, but subseq
#### Write-behind (write-back)
<p align="center">
<img src="images/rgSrvjG.png">
<br/>
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
</p>
![Write-behind (write-back)](images/rgSrvjG.png)
[Source: Scalability, availability, stability, patterns](https://www.slideshare.net/jboner/scalability-availability-stability-patterns)
In write-behind, the application does the following:
@ -1291,11 +1230,8 @@ In write-behind, the application does the following:
#### Refresh-ahead
<p align="center">
<img src="images/kxtjqgE.png">
<br/>
<i><a href=http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast>Source: From cache to in-memory data grid</a></i>
</p>
![Refresh-ahead](images/kxtjqgE.png)
[Source: From cache to in-memory data grid](https://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast)
You can configure the cache to automatically refresh any recently accessed cache entry prior to its expiration.
@ -1323,11 +1259,8 @@ Refresh-ahead can result in reduced latency vs read-through if the cache can acc
## Asynchronism
<p align="center">
<img src="images/54GYsSx.png">
<br/>
<i><a href=http://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer>Source: Intro to architecting systems for scale</a></i>
</p>
![Asynchronism](images/54GYsSx.png)
[Source: Intro to architecting systems for scale](https://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer)
Asynchronous workflows help reduce request times for expensive operations that would otherwise be performed in-line. They can also help by doing time-consuming work in advance, such as periodic aggregation of data.
@ -1369,11 +1302,8 @@ If queues start to grow significantly, the queue size can become larger than mem
## Communication
<p align="center">
<img src="images/5KeocQs.jpg">
<br/>
<i><a href=http://www.escotal.com/osilayer.html>Source: OSI 7 layer model</a></i>
</p>
![OSI 7 Layer Model](images/5KeocQs.jpg)
[Source: OSI 7 layer model](https://www.escotal.com/osilayer.html)
### Hypertext transfer protocol (HTTP)
@ -1401,11 +1331,8 @@ HTTP is an application layer protocol relying on lower-level protocols such as *
### Transmission control protocol (TCP)
<p align="center">
<img src="images/JdAsdvG.jpg">
<br/>
<i><a href=http://www.wildbunny.co.uk/blog/2012/10/09/how-to-make-a-multi-player-game-part-1/>Source: How to make a multiplayer game</a></i>
</p>
![TCP](images/JdAsdvG.jpg)
[Source: How to make a multiplayer game](http://www.wildbunny.co.uk/blog/2012/10/09/how-to-make-a-multi-player-game-part-1)
TCP is a connection-oriented protocol over an [IP network](https://en.wikipedia.org/wiki/Internet_Protocol). Connection is established and terminated using a [handshake](https://en.wikipedia.org/wiki/Handshaking). All packets sent are guaranteed to reach the destination in the original order and without corruption through:
@ -1425,11 +1352,8 @@ Use TCP over UDP when:
### User datagram protocol (UDP)
<p align="center">
<img src="images/yzDrJtA.jpg">
<br/>
<i><a href=http://www.wildbunny.co.uk/blog/2012/10/09/how-to-make-a-multi-player-game-part-1/>Source: How to make a multiplayer game</a></i>
</p>
![UDP](images/yzDrJtA.jpg)
[Source: How to make a multiplayer game](http://www.wildbunny.co.uk/blog/2012/10/09/how-to-make-a-multi-player-game-part-1)
UDP is connectionless. Datagrams (analogous to packets) are guaranteed only at the datagram level. Datagrams might reach their destination out of order or not at all. UDP does not support congestion control. Without the guarantees that TCP support, UDP is generally more efficient.
@ -1454,11 +1378,8 @@ Use UDP over TCP when:
### Remote procedure call (RPC)
<p align="center">
<img src="images/iF4Mkb5.png">
<br/>
<i><a href=http://www.puncsky.com/blog/2016-02-13-crack-the-system-design-interview>Source: Crack the system design interview</a></i>
</p>
![RPC](images/iF4Mkb5.png)
[Source: Crack the system design interview](https://www.puncsky.com/blog/2016-02-13-crack-the-system-design-interview)
In an RPC, a client causes a procedure to execute on a different address space, usually a remote server. The procedure is coded as if it were a local procedure call, abstracting away the details of how to communicate with the server from the client program. Remote calls are usually slower and less reliable than local calls so it is helpful to distinguish RPC calls from local calls. Popular RPC frameworks include [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/), and [Avro](https://avro.apache.org/docs/current/).
@ -1680,11 +1601,8 @@ Handy metrics based on numbers above:
> Articles on how real world systems are designed.
<p align="center">
<img src="images/TcUo2fw.png">
<br/>
<i><a href=https://www.infoq.com/presentations/Twitter-Timeline-Scalability>Source: Twitter timelines at scale</a></i>
</p>
![Twitter timeline scalability](images/TcUo2fw.png)
[Source: Twitter timelines at scale](https://www.infoq.com/presentations/Twitter-Timeline-Scalability)
**Don't focus on nitty gritty details for the following articles, instead:**

24
deeplists.tex Normal file
View File

@ -0,0 +1,24 @@
\usepackage{enumitem}
\setlistdepth{9}
\setlist[itemize,1]{label=$\bullet$}
\setlist[itemize,2]{label=$\bullet$}
\setlist[itemize,3]{label=$\bullet$}
\setlist[itemize,4]{label=$\bullet$}
\setlist[itemize,5]{label=$\bullet$}
\setlist[itemize,6]{label=$\bullet$}
\setlist[itemize,7]{label=$\bullet$}
\setlist[itemize,8]{label=$\bullet$}
\setlist[itemize,9]{label=$\bullet$}
\renewlist{itemize}{itemize}{9}
\setlist[enumerate,1]{label=$\arabic*.$}
\setlist[enumerate,2]{label=$\alph*.$}
\setlist[enumerate,3]{label=$\roman*.$}
\setlist[enumerate,4]{label=$\arabic*.$}
\setlist[enumerate,5]{label=$\alpha*$}
\setlist[enumerate,6]{label=$\roman*.$}
\setlist[enumerate,7]{label=$\arabic*.$}
\setlist[enumerate,8]{label=$\alph*.$}
\setlist[enumerate,9]{label=$\roman*.$}
\renewlist{enumerate}{enumerate}{9}

BIN
images/3X8nmdL.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

BIN
images/48tEA2j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

BIN
images/B8LDKD7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
images/BKsBnmG.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

BIN
images/E8klrBh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

BIN
images/KqZ3dSx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
images/OZCxJr0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

BIN
images/raoFTXM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

BIN
images/rrfjMXB.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
images/vwMa1Qu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
images/wxXyq2J.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
images/xjdAAUv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

16
pandoc-docker.sh Executable file
View File

@ -0,0 +1,16 @@
#! /bin/sh
# Install dependencies for successful PDF generations
tlmgr install collection-fontsrecommended ctex enumitem float greek-fontenc koma-script polyglossia realscripts xltxtra
fc-cache
# Generate PDFs using pandoc
for filename in pandoc-*yaml; do
# Create variable for language based on filename
language=`echo $filename | cut -d'.' -f1 | cut -d'-' -f2-3`
# Attempt to create the PDF
echo "Generating ${language} PDF with solutions..."
pandoc -d ${filename}
[[ $? -eq 0 ]] && echo "Success! The ${language} PDF has been successfully created!"
done

39
pandoc-en-US.yaml Normal file
View File

@ -0,0 +1,39 @@
---
metadata:
title: System Design Primer
subtitle: Learn how to design large-scale systems. Prep for the system design interview.
author: Donne Martin
category: "License: Creative Commons Attribution 4.0 International License"
keywords:
- "system"
- "design"
- "primer"
standalone: true
variables:
documentclass: scrbook
lang: en-US
links-as-notes: true
lot: false
lof: false
margin-top: 1.27cm
margin-left: .635cm
margin-right: .635cm
margin-bottom: 1.27cm
table-of-contents: true
toc-depth: 2
include-in-header: deeplists.tex
verbosity: ERROR
pdf-engine: xelatex
template: unicode.latex
input-files:
- ./README.md
- ./solutions/system_design/social_graph/README.md
- ./solutions/system_design/web_crawler/README.md
- ./solutions/system_design/scaling_aws/README.md
- ./solutions/system_design/pastebin/README.md
- ./solutions/system_design/sales_rank/README.md
- ./solutions/system_design/twitter/README.md
- ./solutions/system_design/mint/README.md
- ./solutions/system_design/query_cache/README.md
output-file: system-design-primer.pdf
...

34
pandoc-zh-Hans.yaml Normal file
View File

@ -0,0 +1,34 @@
---
metadata:
title: 系统设计入门
subtitle: 学习如何设计大型系统。为系统设计的面试做准备。
author: Donne Martin
category: "License: Creative Commons Attribution 4.0 International License"
standalone: true
variables:
documentclass: scrbook
links-as-notes: true
lot: false
lof: false
margin-top: 1.27cm
margin-left: .635cm
margin-right: .635cm
margin-bottom: 1.27cm
table-of-contents: true
toc-depth: 2
include-in-header: deeplists.tex
verbosity: ERROR
pdf-engine: xelatex
template: unicode.latex
input-files:
- ./README-zh-Hans.md
- ./solutions/system_design/social_graph/README-zh-Hans.md
- ./solutions/system_design/web_crawler/README-zh-Hans.md
- ./solutions/system_design/scaling_aws/README-zh-Hans.md
- ./solutions/system_design/pastebin/README-zh-Hans.md
- ./solutions/system_design/sales_rank/README-zh-Hans.md
- ./solutions/system_design/twitter/README-zh-Hans.md
- ./solutions/system_design/mint/README-zh-Hans.md
- ./solutions/system_design/query_cache/README-zh-Hans.md
output-file: system-design-primer-zh.pdf
...

31
pandoc.sh Executable file
View File

@ -0,0 +1,31 @@
#! /bin/bash
# Generate PDFs using pandoc
generate_pdfs_with_solutions() {
for filename in pandoc-*yaml; do
# Create variable for language based on filename
IFS=- read _ language <<< "${filename}"
language=${language/.yaml/}
# Attempt to create the PDF
echo "Generating ${language} PDF with solutions..."
pandoc -d ${filename}
[[ $? -eq 0 ]] && echo "Success! The ${language} PDF has been successfully created!"
done
}
# Check if dependencies exist
check_dependencies () {
for dependency in "${dependencies[@]}"
do
if ! [ -x "$(command -v $dependency)" ]; then
echo "Error: $dependency is not installed." >&2
exit 1
fi
done
}
dependencies=("pandoc" "tex")
check_dependencies
generate_pdfs_with_solutions

View File

@ -80,7 +80,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/E8klrBh.png)
![High level design of Mint.com](https://i.imgur.com/E8klrBh.png)
## Step 3: Design core components
@ -327,7 +327,7 @@ class SpendingByCategory(MRJob):
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/V5q57vU.png)
![Scaled design of Mint.com](https://i.imgur.com/V5q57vU.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -79,7 +79,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/BKsBnmG.png)
![High level design of Pastebin.com (or Bit.ly)](https://i.imgur.com/BKsBnmG.png)
## Step 3: Design core components
@ -235,7 +235,7 @@ To delete expired pastes, we could just scan the **SQL Database** for all entrie
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/4edXG0T.png)
![Scaled design of Pastebin.com (or Bit.ly)](https://i.imgur.com/4edXG0T.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -58,7 +58,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/KqZ3dSx.png)
![High level of a key-value cache to save the results of the most recent web server queries](https://i.imgur.com/KqZ3dSx.png)
## Step 3: Design core components
@ -212,7 +212,7 @@ Refer to [When to update the cache](https://github.com/donnemartin/system-design
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/4j99mhe.png)
![Scaled design of a key-value store for a search engine](https://i.imgur.com/4j99mhe.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -70,7 +70,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/vwMa1Qu.png)
![High level design of Amazon's sales ranking by category feature](https://i.imgur.com/vwMa1Qu.png)
## Step 3: Design core components
@ -239,7 +239,7 @@ For internal communications, we could use [Remote Procedure Calls](https://githu
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/MzExP06.png)
![Scaled design of Amazon's sales ranking by category feature](https://i.imgur.com/MzExP06.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -64,7 +64,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/B8LDKD7.png)
![High level design of an AWS service](https://i.imgur.com/B8LDKD7.png)
## Step 3: Design core components
@ -139,7 +139,7 @@ Add a **DNS** such as Route 53 to map the domain to the instance's public IP.
### Users+
![Imgur](http://i.imgur.com/rrfjMXB.png)
![Scaled design of an AWS service to lighten load on a single box and allow for independent scaling](https://i.imgur.com/rrfjMXB.png)
#### Assumptions
@ -191,7 +191,7 @@ We've been able to address these issues with **Vertical Scaling** so far. Unfor
### Users++
![Imgur](http://i.imgur.com/raoFTXM.png)
![Scaled design of an AWS service to address web server scaling](https://i.imgur.com/raoFTXM.png)
#### Assumptions
@ -220,7 +220,7 @@ Our **Benchmarks/Load Tests** and **Profiling** show that our single **Web Serve
### Users+++
![Imgur](http://i.imgur.com/OZCxJr0.png)
![Scaled design of an AWS service to address MySQL scaling](https://i.imgur.com/OZCxJr0.png)
**Note:** **Internal Load Balancers** not shown to reduce clutter
@ -258,7 +258,7 @@ Our **Benchmarks/Load Tests** and **Profiling** show that we are read-heavy (100
### Users++++
![Imgur](http://i.imgur.com/3X8nmdL.png)
![Scaled design of an AWS service with autoscaling added](https://i.imgur.com/3X8nmdL.png)
#### Assumptions
@ -297,7 +297,7 @@ Our **Benchmarks/Load Tests** and **Profiling** show that our traffic spikes dur
### Users+++++
![Imgur](http://i.imgur.com/jj3A5N8.png)
![Scaled design of a system that scales to millions of users on AWS](https://i.imgur.com/jj3A5N8.png)
**Note:** **Autoscaling** groups not shown to reduce clutter

View File

@ -50,7 +50,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/wxXyq2J.png)
![High level design of the data structures for a social network](https://i.imgur.com/wxXyq2J.png)
## Step 3: Design core components
@ -250,7 +250,7 @@ For internal communications, we could use [Remote Procedure Calls](https://githu
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/cdCv5g7.png)
![Scaled design of the data structures for a social network](https://i.imgur.com/cdCv5g7.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -93,7 +93,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/48tEA2j.png)
![High level design of the Twitter timeline and search (or Facebook feed and search)](https://i.imgur.com/48tEA2j.png)
## Step 3: Design core components
@ -223,7 +223,7 @@ The response would be similar to that of the home timeline, except for tweets ma
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/jrUBAF7.png)
![Scaled design of the Twitter timeline and search (or Facebook feed and search)](https://i.imgur.com/jrUBAF7.png)
**Important: Do not simply jump right into the final design from the initial design!**

View File

@ -69,7 +69,7 @@ Handy conversion guide:
> Outline a high level design with all important components.
![Imgur](http://i.imgur.com/xjdAAUv.png)
![High level design of a web crawler](https://i.imgur.com/xjdAAUv.png)
## Step 3: Design core components
@ -256,7 +256,7 @@ For internal communications, we could use [Remote Procedure Calls](https://githu
> Identify and address bottlenecks, given the constraints.
![Imgur](http://i.imgur.com/bWxPtQA.png)
![Scaled design of a web crawler](https://i.imgur.com/bWxPtQA.png)
**Important: Do not simply jump right into the final design from the initial design!**

814
unicode.latex Normal file
View File

@ -0,0 +1,814 @@
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode$for(hyperrefoptions)$,$hyperrefoptions$$endfor$}{hyperref}
\PassOptionsToPackage{hyphens}{url}
$if(colorlinks)$
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
$endif$
$if(CJKmainfont)$
\PassOptionsToPackage{space}{xeCJK}
$endif$
%
\documentclass[
$if(fontsize)$
$fontsize$,
$endif$
$if(papersize)$
$papersize$paper,
$endif$
$if(beamer)$
ignorenonframetext,
$if(handout)$
handout,
$endif$
$if(aspectratio)$
aspectratio=$aspectratio$,
$endif$
$if(babel-lang)$
$babel-lang$,
$endif$
$endif$
$for(classoption)$
$classoption$$sep$,
$endfor$
]{$documentclass$}
$if(beamer)$
$if(background-image)$
\usebackgroundtemplate{%
\includegraphics[width=\paperwidth]{$background-image$}%
}
% In beamer background-image does not work well when other images are used, so this is the workaround
\pgfdeclareimage[width=\paperwidth,height=\paperheight]{background}{$background-image$}
\usebackgroundtemplate{\pgfuseimage{background}}
$endif$
\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbols$if(navigation)$$navigation$$else$empty$endif$
$for(beameroption)$
\setbeameroption{$beameroption$}
$endfor$
% Prevent slide breaks in the middle of a paragraph
\widowpenalties 1 10000
\raggedbottom
$if(section-titles)$
\setbeamertemplate{part page}{
\centering
\begin{beamercolorbox}[sep=16pt,center]{part title}
\usebeamerfont{part title}\insertpart\par
\end{beamercolorbox}
}
\setbeamertemplate{section page}{
\centering
\begin{beamercolorbox}[sep=12pt,center]{part title}
\usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
\centering
\begin{beamercolorbox}[sep=8pt,center]{part title}
\usebeamerfont{subsection title}\insertsubsection\par
\end{beamercolorbox}
}
\AtBeginPart{
\frame{\partpage}
}
\AtBeginSection{
\ifbibliography
\else
\frame{\sectionpage}
\fi
}
\AtBeginSubsection{
\frame{\subsectionpage}
}
$endif$
$endif$
$if(beamerarticle)$
\usepackage{beamerarticle} % needs to be loaded first
$endif$
\usepackage{amsmath,amssymb}
$if(linestretch)$
\usepackage{setspace}
$endif$
\usepackage{iftex}
\ifPDFTeX
\usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
$if(mathspec)$
\ifXeTeX
\usepackage{mathspec} % this also loads fontspec
\else
\usepackage{unicode-math} % this also loads fontspec
\fi
$else$
\usepackage{unicode-math} % this also loads fontspec
$endif$
\defaultfontfeatures{Scale=MatchLowercase}$-- must come before Beamer theme
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
$if(fontfamily)$
$else$
$-- Set default font before Beamer theme so the theme can override it
\usepackage{lmodern}
$endif$
$-- Set Beamer theme before user font settings so they can override theme
$if(beamer)$
$if(theme)$
\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
$endif$
$if(colortheme)$
\usecolortheme{$colortheme$}
$endif$
$if(fonttheme)$
\usefonttheme{$fonttheme$}
$endif$
$if(mainfont)$
\usefonttheme{serif} % use mainfont rather than sansfont for slide text
$endif$
$if(innertheme)$
\useinnertheme{$innertheme$}
$endif$
$if(outertheme)$
\useoutertheme{$outertheme$}
$endif$
$endif$
$-- User font settings (must come after default font and Beamer theme)
$if(fontfamily)$
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$endif$
\ifPDFTeX\else
% xetex/luatex font selection
$if(mainfont)$
$if(mainfontfallback)$
\ifLuaTeX
\usepackage{luaotfload}
\directlua{luaotfload.add_fallback("mainfontfallback",{
$for(mainfontfallback)$"$mainfontfallback$"$sep$,$endfor$
})}
\fi
$endif$
\setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$}
$endif$
$if(sansfont)$
$if(sansfontfallback)$
\ifLuaTeX
\usepackage{luaotfload}
\directlua{luaotfload.add_fallback("sansfontfallback",{
$for(sansfontfallback)$"$sansfontfallback$"$sep$,$endfor$
})}
\fi
$endif$
\setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$$if(sansfontfallback)$,RawFeature={fallback=sansfontfallback}$endif$]{$sansfont$}
$endif$
$if(monofont)$
$if(monofontfallback)$
\ifLuaTeX
\usepackage{luaotfload}
\directlua{luaotfload.add_fallback("monofontfallback",{
$for(monofontfallback)$"$monofontfallback$"$sep$,$endfor$
})}
\fi
$endif$
\setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$if(monofontfallback)$,RawFeature={fallback=monofontfallback}$endif$]{$monofont$}
$endif$
$for(fontfamilies)$
\newfontfamily{$fontfamilies.name$}[$for(fontfamilies.options)$$fontfamilies.options$$sep$,$endfor$]{$fontfamilies.font$}
$endfor$
$if(mathfont)$
$if(mathspec)$
\ifXeTeX
\setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
\else
\setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
\fi
$else$
\setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
$endif$
$endif$
$if(CJKmainfont)$
\ifXeTeX
\usepackage{xeCJK}
\setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$}
$if(CJKsansfont)$
\setCJKsansfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKsansfont$}
$endif$
$if(CJKmonofont)$
\setCJKmonofont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmonofont$}
$endif$
\fi
$endif$
$if(luatexjapresetoptions)$
\ifLuaTeX
\usepackage[$for(luatexjapresetoptions)$$luatexjapresetoptions$$sep$,$endfor$]{luatexja-preset}
\fi
$endif$
$if(CJKmainfont)$
\ifLuaTeX
\usepackage[$for(luatexjafontspecoptions)$$luatexjafontspecoptions$$sep$,$endfor$]{luatexja-fontspec}
\setmainjfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$}
\fi
$endif$
\fi
$if(zero-width-non-joiner)$
%% Support for zero-width non-joiner characters.
\makeatletter
\def\zerowidthnonjoiner{%
% Prevent ligatures and adjust kerning, but still support hyphenating.
\texorpdfstring{%
\TextOrMath{\nobreak\discretionary{-}{}{\kern.03em}%
\ifvmode\else\nobreak\hskip\z@skip\fi}{}%
}{}%
}
\makeatother
\ifPDFTeX
\DeclareUnicodeCharacter{200C}{\zerowidthnonjoiner}
\else
\catcode`^^^^200c=\active
\protected\def ^^^^200c{\zerowidthnonjoiner}
\fi
%% End of ZWNJ support
$endif$
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[$for(microtypeoptions)$$microtypeoptions$$sep$,$endfor$]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
$if(indent)$
$else$
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
\usepackage{xcolor}
$if(geometry)$
$if(beamer)$
\geometry{$for(geometry)$$geometry$$sep$,$endfor$}
$else$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
$endif$
$if(beamer)$
\newif\ifbibliography
$endif$
$if(listings)$
\usepackage{listings}
\newcommand{\passthrough}[1]{#1}
\lstset{defaultdialect=[5.3]Lua}
\lstset{defaultdialect=[x86masm]Assembler}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(tables)$
\usepackage{longtable,booktabs,array}
$if(multirow)$
\usepackage{multirow}
$endif$
\usepackage{calc} % for calculating minipage widths
$if(beamer)$
\usepackage{caption}
% Make caption package work with longtable
\makeatletter
\def\fnum@table{\tablename~\thetable}
\makeatother
$else$
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
$endif$
$endif$
$if(graphics)$
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
\sbox\pandoc@box{#1}%
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
\else\usebox{\pandoc@box}%
\fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother
$endif$
$if(svg)$
\usepackage{svg}
$endif$
$if(strikeout)$
$-- also used for underline
\ifLuaTeX
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\else
\usepackage{soul}
$if(beamer)$
\makeatletter
\let\HL\hl
\renewcommand\hl{% fix for beamer highlighting
\let\set@color\beamerorig@set@color
\let\reset@color\beamerorig@reset@color
\HL}
\makeatother
$endif$
$if(CJKmainfont)$
\ifXeTeX
% soul's \st doesn't work for CJK:
\usepackage{xeCJKfntef}
\renewcommand{\st}[1]{\sout{#1}}
\fi
$endif$
\fi
$endif$
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
$if(numbersections)$
\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
$else$
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
$endif$
$if(subfigure)$
\usepackage{subcaption}
$endif$
$if(beamer)$
$else$
$if(block-headings)$
% Make \paragraph and \subparagraph free-standing
\makeatletter
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}{
\@ifstar
\xxxParagraphStar
\xxxParagraphNoStar
}
\newcommand{\xxxParagraphStar}[1]{\oldparagraph*{#1}\mbox{}}
\newcommand{\xxxParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}{
\@ifstar
\xxxSubParagraphStar
\xxxSubParagraphNoStar
}
\newcommand{\xxxSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}}
\newcommand{\xxxSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\makeatother
$endif$
$endif$
$if(pagestyle)$
\pagestyle{$pagestyle$}
$endif$
$if(csl-refs)$
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
\setlength{\parsep}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1
\setlength{\leftmargin}{\cslhangindent}
\setlength{\itemindent}{-1\cslhangindent}
\fi
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$
$if(lang)$
\ifLuaTeX
\usepackage[bidi=basic]{babel}
\else
\usepackage[bidi=default]{babel}
\fi
$if(babel-lang)$
\babelprovide[main,import]{$babel-lang$}
$if(mainfont)$
\ifPDFTeX
\else
\babelfont{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$}
\fi
$endif$
$endif$
$for(babel-otherlangs)$
\babelprovide[import]{$babel-otherlangs$}
$endfor$
$for(babelfonts/pairs)$
\babelfont[$babelfonts.key$]{rm}{$babelfonts.value$}
$endfor$
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
$if(selnolig-langs)$
\ifLuaTeX
\usepackage[$for(selnolig-langs)$$it$$sep$,$endfor$]{selnolig} % disable illegal ligatures
\fi
$endif$
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(dir)$
\ifPDFTeX
\TeXXeTstate=1
\newcommand{\RL}[1]{\beginR #1\endR}
\newcommand{\LR}[1]{\beginL #1\endL}
\newenvironment{RTL}{\beginR}{\endR}
\newenvironment{LTR}{\beginL}{\endL}
\fi
$endif$
$if(natbib)$
\usepackage[$natbiboptions$]{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex}
$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
$endif$
$if(nocite-ids)$
\nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
$endif$
$if(csquotes)$
\usepackage{csquotes}
$endif$
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{$if(urlstyle)$$urlstyle$$else$same$endif$}
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allow verbatim text in footnotes
$endif$
\hypersetup{
$if(title-meta)$
pdftitle={$title-meta$},
$endif$
$if(author-meta)$
pdfauthor={$author-meta$},
$endif$
$if(lang)$
pdflang={$lang$},
$endif$
$if(subject)$
pdfsubject={$subject$},
$endif$
$if(keywords)$
pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$},
$endif$
$if(colorlinks)$
colorlinks=true,
linkcolor={$if(linkcolor)$$linkcolor$$else$Maroon$endif$},
filecolor={$if(filecolor)$$filecolor$$else$Maroon$endif$},
citecolor={$if(citecolor)$$citecolor$$else$Blue$endif$},
urlcolor={$if(urlcolor)$$urlcolor$$else$Blue$endif$},
$else$
$if(boxlinks)$
$else$
hidelinks,
$endif$
$endif$
pdfcreator={LaTeX via pandoc}}
$if(title)$
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
$endif$
$if(subtitle)$
$if(beamer)$
$else$
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
\apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
$endif$
\subtitle{$subtitle$}
$endif$
\author{$for(author)$$author$$sep$ \and $endfor$}
\date{$date$}
$if(beamer)$
$if(institute)$
\institute{$for(institute)$$institute$$sep$ \and $endfor$}
$endif$
$if(titlegraphic)$
\titlegraphic{\includegraphics$if(titlegraphicoptions)$[$for(titlegraphicoptions)$$titlegraphicoptions$$sep$, $endfor$]$endif${$titlegraphic$}}
$endif$
$if(logo)$
\logo{\includegraphics{$logo$}}
$endif$
$endif$
\begin{document}
$if(has-frontmatter)$
\frontmatter
$endif$
$if(title)$
$if(beamer)$
\frame{\titlepage}
$else$
\maketitle
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
$if(beamer)$
\begin{frame}[allowframebreaks]
$if(toc-title)$
\frametitle{$toc-title$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
\end{frame}
$else$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$endif$
$if(lof)$
\listoffigures
$endif$
$if(lot)$
\listoftables
$endif$
$if(linestretch)$
\setstretch{$linestretch$}
$endif$
$if(has-frontmatter)$
\mainmatter
$endif$
$body$
$if(has-frontmatter)$
\backmatter
$endif$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(has-chapters)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
$if(beamer)$
\begin{frame}[allowframebreaks]{$biblio-title$}
\bibliographytrue
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$if(beamer)$
\end{frame}
$endif$
$endif$
$endif$
$if(biblatex)$
$if(beamer)$
\begin{frame}[allowframebreaks]{$biblio-title$}
\bibliographytrue
\printbibliography[heading=none]
\end{frame}
$else$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$endif$
$for(include-after)$
$include-after$
$endfor$
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
% 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[utf]{inputenc}
\usepackage{ucs}
$if(euro)$
\usepackage{eurosym}
$endif$
\else % if luatex or xelatex
\usepackage{fontspec}
\ifxetex
\usepackage{xltxtra,xunicode}
\fi
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\newcommand{\euro}{€}
$if(mainfont)$
\setmainfont{$mainfont$}
$endif$
$if(sansfont)$
\setsansfont{$sansfont$}
$endif$
$if(monofont)$
\setmonofont{$monofont$}
$endif$
$if(mathfont)$
\setmathfont{$mathfont$}
$endif$
\fi
$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$
$if(graphics)$
\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}}
$endif$
\ifxetex
\usepackage[setpagesize=false, % page size defined by xetex
unicode=false, % unicode breaks when used with xetex
xetex]{hyperref}
\else
\usepackage[unicode=true]{hyperref}
\fi
\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
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$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)$
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(lang)$
\ifxetex
\usepackage{polyglossia}
\else
\usepackage[$lang$]{babel}
\fi
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(title)$
\title{$title$}
$endif$
\author{$for(author)$$author$$sep$ \and $endfor$}
\date{$date$}
\begin{document}
$if(title)$
\maketitle
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
{
\hypersetup{linkcolor=black}
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$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}