Skip to content

Commit 9e18543

Browse files
committed
see changkun#6: pdf for english version
1 parent 70250c2 commit 9e18543

9 files changed

+318
-11
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
all: pdf website
22

33
pdf:
4-
cd pdf/zh-cn && pwd && make
4+
cd pdf/zh-cn && make
5+
cd pdf/en-us && make
56

67
website:
78
cd website && make
@@ -11,6 +12,7 @@ serve:
1112

1213
clean:
1314
cd pdf/zh-cn && make clean
15+
cd pdf/en-us && make clean
1416
cd website && make clean
1517

1618
.PHONY : pdf website clean

README-en-us.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ In addition, The author would like to encourage that readers should be able to u
3232
You can choose from the following reading methods:
3333

3434
- [GitHub Online](./book/en-us/toc.md)
35-
- [PDF document]
36-
- [Website]
35+
- [PDF document](./pdf/en-us/modern-cpp-tutorial.pdf)
36+
- [Website](https://changkun.de/modern-cpp)
3737

3838
## Code
3939

@@ -43,11 +43,15 @@ Each chapter of this book has a lot of code. If you encounter problems when writ
4343

4444
There are few exercises At the end of each chapter of the book. It is for testing whether you can use the knowledge points in the current chapter. You can find the possible answer to the problem from [here](./exercise). The folder name is the chapter number.
4545

46+
## Website
47+
48+
The source code of the [website](https://changkun.de/modern-cpp) of this book can be found [here](./website), which is built by [hexo](https://hexo.io) and [vuejs](https://vuejs.org). The website provides you another way of reading the book, it is also adapts to mobile.
49+
4650
## Acknowledgements
4751

4852
This book is originally written in Chinese.
4953

50-
The author has limited time and language skills. If readers find any mistakes of the book or any language improvements, please feel free to open an [issue](https://github.com/changkun/modern-cpp-tutorial/issues).
54+
The author has limited time and language skills. If readers find any mistakes of the book or any language improvements, please feel free to open an [Issue](https://github.com/changkun/modern-cpp-tutorial/issues) or start a [Pull request](https://github.com/changkun/modern-cpp-tutorial/pulls).
5155

5256
## Licenses
5357

pdf/en-us/Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
title = 'C++11/14/17 On the Fly'
2+
filename = 'modern-cpp-tutorial'
3+
outputname='modern-cpp-tutorial'
4+
5+
all: pdf
6+
7+
pdf: markdown
8+
@echo "Compiling PDF file..."
9+
@pandoc -s $(filename).md -o $(outputname).pdf \
10+
--title-prefix $(title) \
11+
--listings -H meta/cpp-listings.tex \
12+
--template=meta/template.tex \
13+
--normalize \
14+
--smart \
15+
--latex-engine=`which xelatex`
16+
@echo "Done."
17+
@rm *.md
18+
19+
markdown:
20+
@echo "Copy markdown files..."
21+
@cp -r ../../book/en-us/* .
22+
@echo "Aggregating markdown files..."
23+
@python3 aggregator.py
24+
25+
clean:
26+
rm -rf *.md *.pdf
27+
28+
.PHONY: markdown pdf clean

pdf/en-us/aggregator.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# !/usr/bin/env python3
2+
# author: changkun<hi@changkun.us>
3+
4+
import os
5+
6+
chapters = ['00-preface.md', '01-intro.md', '02-usability.md', '03-runtime.md', '04-containers.md', '05-pointers.md', '06-regex.md', '07-thread.md', '08-filesystem.md', '09-others.md', '10-cpp20.md', 'appendix.md']
7+
8+
ignores = ['TOC', 'Return to TOC', 'License', 'license']
9+
10+
11+
with open('modern-cpp-tutorial.md', 'w') as outfile:
12+
outfile.write("""---
13+
title: "C++11/14/17 On the Fly"
14+
author: Changkun Ou <hi@changkun.us>
15+
copyright: cc-by-nc-nd 4.0
16+
---
17+
""")
18+
for chapter in chapters:
19+
if os.path.isfile(chapter):
20+
with open(chapter) as ch:
21+
outfile.write('\n')
22+
for line in ch:
23+
if any(keyword in line for keyword in ignores):
24+
continue
25+
else:
26+
outfile.write(line)

pdf/en-us/meta/cpp-listings.tex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
\usepackage{xcolor}
3+
4+
\definecolor{keyword}{HTML}{BA2CA3}
5+
\definecolor{string}{HTML}{D12F1B}
6+
\definecolor{comment}{HTML}{008400}
7+
8+
\lstset{
9+
basicstyle={\small\ttfamily},
10+
keywordstyle={\color[rgb]{0.13,0.29,0.53}\bfseries},
11+
breaklines=true,
12+
emphstyle={\bfseries\color{Rhodamine}},
13+
commentstyle={\color[rgb]{0.56,0.35,0.01}\itshape},
14+
stringstyle={\color[rgb]{0.31,0.60,0.02}},
15+
showstringspaces=false,
16+
frame=shadowbox,
17+
breakatwhitespace=false,
18+
captionpos=b,
19+
extendedchars=true,
20+
keepspaces=true,
21+
numbers=left,
22+
numberstyle=\tiny,
23+
rulecolor=\color{black},
24+
rulesepcolor={\color{blue!20!white}},
25+
showspaces=false,
26+
}

pdf/en-us/meta/template.tex

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
\documentclass[a4paper, 10pt]{article}
2+
\usepackage{geometry}
3+
\geometry{
4+
top=1in,
5+
inner=1in,
6+
outer=1in,
7+
bottom=1in,
8+
headheight=3ex,
9+
headsep=2ex
10+
}
11+
\usepackage{tabu}
12+
\usepackage[T1]{fontenc}
13+
\usepackage{lmodern}
14+
\usepackage{booktabs}
15+
\usepackage{amssymb,amsmath}
16+
\usepackage{ifxetex,ifluatex}
17+
18+
\linespread{1.2}\selectfont % 行距
19+
%\XeTeXlinebreaklocale "zh" % 针对中文自动换行
20+
%\XeTeXlinebreakskip = 0pt plus 1pt % 字与字之间加入 0pt 至 1pt 的间距,确保左右对齐
21+
%\parindent 0em % 段落缩进
22+
%\setlength{\parskip}{20pt} % 段落间距
23+
\ifxetex
24+
\usepackage{xltxtra,xunicode}
25+
\fi
26+
$if(mainfont)$
27+
\setmainfont{$mainfont$}
28+
$endif$
29+
$if(sansfont)$
30+
\setsansfont{$sansfont$}
31+
$endif$
32+
$if(monofont)$
33+
\setmonofont{$monofont$}
34+
$endif$
35+
$if(mathfont)$
36+
\setmathfont{$mathfont$}
37+
$endif$
38+
39+
% use microtype if available
40+
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
41+
$if(geometry)$
42+
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
43+
$endif$
44+
$if(natbib)$
45+
\usepackage{natbib}
46+
\bibliographystyle{plainnat}
47+
$endif$
48+
$if(biblatex)$
49+
\usepackage{biblatex}
50+
$if(biblio-files)$
51+
\bibliography{$biblio-files$}
52+
$endif$
53+
$endif$
54+
$if(listings)$
55+
\usepackage{listings}
56+
$endif$
57+
$if(lhs)$
58+
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
59+
$endif$
60+
$if(highlighting-macros)$
61+
$highlighting-macros$
62+
$endif$
63+
$if(verbatim-in-note)$
64+
\usepackage{fancyvrb}
65+
$endif$
66+
$if(tables)$
67+
\usepackage{longtable}
68+
$endif$
69+
70+
\usepackage{graphicx}
71+
\usepackage{caption}
72+
73+
% We will generate all images so they have a width \maxwidth. This means
74+
% that they will get their normal width if they fit onto the page, but
75+
% are scaled down if they would overflow the margins.
76+
\makeatletter
77+
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
78+
\else\Gin@nat@width\fi}
79+
\makeatother
80+
\let\Oldincludegraphics\includegraphics
81+
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=0.7\maxwidth]{#1}}
82+
\ifxetex
83+
\usepackage[setpagesize=false, % page size defined by xetex
84+
unicode=false, % unicode breaks when used with xetex
85+
xetex]{hyperref}
86+
\else
87+
\usepackage[unicode=true]{hyperref}
88+
\fi
89+
\hypersetup{breaklinks=true,
90+
bookmarks=true,
91+
pdfauthor={$author-meta$},
92+
pdftitle={$title-meta$},
93+
colorlinks=true,
94+
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
95+
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
96+
pdfborder={0 0 0}}
97+
\urlstyle{same} % don't use monospace font for urls
98+
$if(links-as-notes)$
99+
% Make links footnotes instead of hotlinks:
100+
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
101+
$endif$
102+
$if(strikeout)$
103+
\usepackage[normalem]{ulem}
104+
% avoid problems with \sout in headers with hyperref:
105+
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
106+
$endif$
107+
\setlength{\parindent}{10pt}
108+
%\setlength{\parskip}{6pt plus 2pt minus 1pt}
109+
\setlength{\emergencystretch}{3em} % prevent overfull lines
110+
\usepackage{titling}
111+
%\setlength{\droptitle}{-8em} % 将标题移动至页面上方
112+
113+
\usepackage{fancyhdr}
114+
\usepackage{lastpage}
115+
\pagestyle{fancyplain}
116+
117+
$if(numbersections)$
118+
\setcounter{secnumdepth}{5}
119+
$else$
120+
\setcounter{secnumdepth}{0}
121+
$endif$
122+
$if(verbatim-in-note)$
123+
\VerbatimFootnotes % allows verbatim text in footnotes
124+
$endif$
125+
$if(lang)$
126+
\ifxetex
127+
\usepackage{polyglossia}
128+
\setmainlanguage{$mainlang$}
129+
\else
130+
\usepackage[$lang$]{babel}
131+
\fi
132+
$endif$
133+
$for(header-includes)$
134+
$header-includes$
135+
$endfor$
136+
137+
$if(title)$
138+
\title{$title$}
139+
$endif$
140+
\author{$for(author)$$author$$sep$ \and $endfor$}
141+
\date{$date$}
142+
143+
%%%% 段落首行缩进两个字 %%%%
144+
\makeatletter
145+
\let\@afterindentfalse\@afterindenttrue
146+
\@afterindenttrue
147+
\makeatother
148+
\setlength{\parindent}{2em} %中文缩进两个汉字位
149+
150+
%%%% 下面的命令设置行间距与段落间距 %%%%
151+
\linespread{1.4}
152+
\setlength{\parskip}{1ex}
153+
\setlength{\parskip}{0.5\baselineskip}
154+
155+
156+
\begin{document}
157+
158+
\newcommand{\tightlist}{%
159+
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
160+
161+
\thispagestyle{plain}
162+
\begin{center}
163+
164+
{\LARGE\textbf{C++11/14/17 On the Fly}}
165+
166+
\vspace{1em}
167+
{\large Changkun Ou (hi@changkun.us)}
168+
169+
\vspace{1ex}
170+
Last update: \today
171+
172+
\vspace{1em}
173+
\textbf{\large License}
174+
175+
\noindent This work is written by \href{https://github.com/changkun}{Ou Changkun} and licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. \texttt{\small http://creativecommons.org/licenses/by-nc-nd/4.0/}
176+
177+
\vspace{8em}
178+
\includegraphics{../../assets/cover-2nd-en}
179+
180+
\end{center}
181+
182+
$for(include-before)$
183+
$include-before$
184+
185+
$endfor$
186+
187+
{
188+
\newpage
189+
\hypersetup{linkcolor=black}
190+
\setcounter{tocdepth}{3}
191+
\tableofcontents
192+
}
193+
\newpage
194+
195+
$body$
196+
197+
$if(natbib)$
198+
$if(biblio-files)$
199+
$if(biblio-title)$
200+
$if(book-class)$
201+
\renewcommand\bibname{$biblio-title$}
202+
$else$
203+
\renewcommand\refname{$biblio-title$}
204+
$endif$
205+
$endif$
206+
\bibliography{$biblio-files$}
207+
208+
$endif$
209+
$endif$
210+
$if(biblatex)$
211+
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
212+
213+
$endif$
214+
$for(include-after)$
215+
$include-after$
216+
217+
$endfor$
218+
\end{document}

pdf/en-us/modern-cpp-tutorial.pdf

1.41 MB
Binary file not shown.

pdf/zh-cn/aggregator.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# !/usr/bin/env python3
22
# author: changkun<hi@changkun.us>
33

4+
import os
5+
46
chapters = ['00-preface.md', '01-intro.md', '02-usability.md', '03-runtime.md', '04-containers.md', '05-pointers.md', '06-regex.md', '07-thread.md', '08-filesystem.md', '09-others.md', '10-cpp20.md', 'appendix.md']
57

68
ignores = ['TOC', '返回目录', '许可', 'license']
@@ -13,10 +15,11 @@
1315
---
1416
""")
1517
for chapter in chapters:
16-
with open(chapter) as ch:
17-
outfile.write('\n')
18-
for line in ch:
19-
if any(keyword in line for keyword in ignores):
20-
continue
21-
else:
22-
outfile.write(line)
18+
if os.path.isfile(chapter):
19+
with open(chapter) as ch:
20+
outfile.write('\n')
21+
for line in ch:
22+
if any(keyword in line for keyword in ignores):
23+
continue
24+
else:
25+
outfile.write(line)

pdf/zh-cn/modern-cpp-tutorial.pdf

1 Byte
Binary file not shown.

0 commit comments

Comments
 (0)