Skip to content

Commit d893df3

Browse files
committed
getting started: install python
1 parent a537014 commit d893df3

24 files changed

+232
-6
lines changed

notation/notation.sty

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
%
2+
\RequirePackage{notation/software}%
23
\RequirePackage{notation/sources}%
4+
\RequirePackage{notation/terms}%
35
%

notation/software.sty

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
%%
2+
%% Access to Source Codes
3+
%%
4+
%
5+
\protected\gdef\softwareStyle#1{\textrm{#1}}%
6+
%
7+
\newglossaryentry{python}{%
8+
name={\softwareStyle{Python}},
9+
sort={Python},
10+
description={The \href{https://python.org/}{\softwareStyle{Python}} programming language, i.e., what you will learn about in this book.}
11+
}%
12+
\protected\gdef\python{\gls{python}}%
13+
%
14+
\xdef\pythonVersion{3.10}%
15+
\protected\gdef\pythonWithVersion{\softwareStyle{\python~\pythonVersion}}%
16+
%
17+
\newglossaryentry{ubuntu}{%
18+
name={\softwareStyle{Ubuntu}},
19+
sort={Ubuntu},
20+
description={%
21+
\href{https://ubuntu.com/}{\softwareStyle{Ubuntu}} is a variant of the open source operating system \linux. %
22+
We recommend that you use this operating system to follow this class, for software development, and for research. %
23+
If you are in China, you can download it from \expandafter{\ubuntuDownloadUrl}.%
24+
}%
25+
}%
26+
\protected\gdef\ubuntu{\gls{ubuntu}}%
27+
\xdef\ubuntuDownloadUrl{https://mirrors.ustc.edu.cn/ubuntu-releases/}%
28+
%
29+
\newglossaryentry{linux}{%
30+
name={\softwareStyle{Linux}},
31+
sort={Linux},
32+
description={%
33+
\href{https://www.linux.org/}{\softwareStyle{Linux}} is an open source operating system, i.e., a free alternative for \windows. %
34+
Its variant \ubuntu\ is particularly easy to use and install. %
35+
We recommend using it for this course, for software development, and for research.%
36+
}%
37+
}%
38+
\protected\gdef\linux{\gls{linux}}%
39+
%
40+
\newglossaryentry{windows}{%
41+
name={\softwareStyle{Windows}},
42+
sort={Windows},
43+
description={%
44+
\href{https://www.microsoft.com/windows/}{\softwareStyle{Microsoft Windows}} is a commerical proprietary operating system. %
45+
It is widely spread, but we recommend using a \linux\ variant such as \ubuntu\ for software development and for our course.%
46+
}%
47+
}%
48+
\protected\gdef\windows{\gls{windows}}%
49+
%

notation/terms.sty

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%%
2+
%% Access to Source Codes
3+
%%
4+
%
5+
%
6+
\newglossaryentry{terminal}{%
7+
name={terminal},
8+
plural={terminals},
9+
description={%
10+
A terminal is a text-based window where you can enter commands and execute them by pressing \keys{\return}. %
11+
Knowing what a terminal is and how to use it is very essential in any programming- or system administration-related task. %
12+
If you want to open a terminal under \windows, you can press \keys{\OSwin + R}, type in \bashil{cmd}, and hit \keys{\return}, as shown, e.g., in \cpageref{fig:installingPythonWindows01openTerminal}. %
13+
Under \ubuntu\ \linux, \keys{\ctrl+\Alt+T} opens a terminal.%
14+
}
15+
}%
16+
%

styles/floats.sty

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%%
2+
%% Figure and Table tools.
3+
%%
4+
%
5+
\RequirePackage{subfig}%
6+
%
7+
\protected\gdef\tightbox#1{\bgroup%
8+
\fboxsep=0pt%
9+
\fboxrule=0.5pt%
10+
\mbox{\fcolorbox{black}{listing-background}{\mbox{#1}}}%
11+
\egroup}%
12+
%

styles/href.sty

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ bookmarksdepth=3%
2020
\renewcommand{\subsubsectionautorefname}{Section}%
2121
\renewcommand{\chapterautorefname}{Chapter}%
2222
%
23+
%

styles/keys.sty

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%%
2+
%% Keyboard keys.
3+
%%
4+
%
5+
\RequirePackage[os=win]{menukeys}%
6+
\renewmenumacro{\keys}[+]{shadowedroundedkeys}%
7+
%
8+
%% see https://tex.stackexchange.com/questions/387952
9+
\RequirePackage{fontawesome}%
10+
\tw@make@key@box{OS@mac}{\faApple}%
11+
\tw@make@key@box{OS@win}{\faWindows}%
12+
\tw@make@key@macro*{\OS}%
13+
%

styles/listing.sty

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,25 @@ literate=%
8585
\mbox{\fcolorbox{listing-rule}{listing-background}{\mbox{#1}}}%
8686
\egroup}%
8787
%
88-
%% print some code inline
88+
%% print some Python code inline
8989
%% #1 the optional args
9090
%% #2 the code to be printed inline
91-
\gdef\codeil#1{%
91+
\gdef\pythonil#1{%
9292
\@inlinelistingbox{\lstinline[style=python_style]$#1$}}%
9393
%
94+
%% print some Bash code inline
95+
%% #1 the optional args
96+
%% #2 the code to be printed inline
97+
\gdef\bashil#1{%
98+
\@inlinelistingbox{\lstinline[language=bash]$#1$}}%
99+
%
94100
\newlength\@lstbasicstylesheight%
95101
\settoheight{\@lstbasicstylesheight}{\mbox{\bgroup\@lstbasicstyle{s}\egroup}}%
96102
%
97-
%% print some code inline with an 's' added for plural
103+
%% print some Python code inline with an 's' added for plural
98104
%% #1 the optional args
99105
%% #2 the code to be printed inline
100-
\gdef\codeils#1{%
106+
\gdef\pythons#1{%
101107
\@inlinelistingbox{\lstinline[style=python_style]$#1$\resizebox{!}{\@lstbasicstylesheight}{\color{darkgray}s}}}%
102108
%
103109
%%

styles/styles.sty

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
\RequirePackage{styles/colors}%
1313
\RequirePackage{styles/bibliography}%
1414
\RequirePackage{styles/tables}%
15+
\RequirePackage{styles/floats}%
16+
\RequirePackage{styles/keys}%
17+
%
1518
\RequirePackage{styles/href}%
19+
%
1620
\RequirePackage{styles/latexgit}%
1721
\RequirePackage{styles/listing}%
1822
\RequirePackage{styles/glossary}%

text/back/backmatter.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
%\printRulesOfThumb%
1212
%\printsymbols%
1313
%\printacronyms%
14+
\printglossaries%
1415
\printbibliography%
1516
%

text/main/basics/basics.tex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\hsection{Basics}%
2+
%
3+
In this part of the book, we will gain the following abilities:%
4+
%
5+
\begin{itemize}%
6+
\item read, write, and execute simple \python\ programs%
7+
\item use some tools to help us looking for errors%
8+
\end{itemize}%
9+
%
10+
\hinput{gettingStarted}{gettingStarted.tex}%
11+
\endhsection%
12+
%
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
\hsection{Getting Started}%
2+
%
3+
This course should be a practical course, so we should get started with practical things right away.
4+
%
5+
\hinput{installingPython}{installingPython}%
6+
%
7+
\endhsection%
8+
%
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
\hsection{Installing Python}%
2+
In order to learn and use \python, we first need to install it.
3+
There are two major versions of \python\ out there: \python~\softwareStyle{2} and \python~\softwareStyle{3}.
4+
Our course focuses entirely on \python~\softwareStyle{3}.
5+
We assume that you have installed \pythonWithVersion\ or newer.
6+
Hopefully, you could figure out how to do that by yourself -- but we will at least provide some quick guide here as well.
7+
Help can be found at the following resources:%
8+
%
9+
\begin{itemize}%
10+
\item Python Downloads at \url{https://www.python.org/downloads/}%
11+
\item the Python 3 Installation \& Setup Guide at \url{https://realpython.com/installing-python/}%
12+
\end{itemize}%
13+
%
14+
\hinput{installingPythonWindows}{installingPythonWindows}%
15+
\hinput{pythonUnderUbuntu}{pythonUnderUbuntu}%
16+
%
17+
\endhsection%
18+
%
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
\hsection{Installing Python~3 under Microsoft Windows}%
2+
%
3+
\begin{figure}%
4+
\centering%
5+
\subfloat[][Opening the \gls{terminal} under \windows: \keys{\OSwin + R}, \bashil{cmd}, \keys{\return}.]{%
6+
\label{fig:installingPythonWindows01openTerminal}%
7+
\tightbox{\includegraphics[height=2.8cm]{\currentDir/installingPythonWindows01openTerminal}}%
8+
}%
9+
\hfill%
10+
%
11+
\subfloat[][Trying to get the \python\ version via \bashil{python3 --version}, but it is not installed.%
12+
\label{fig:installingPythonWindows02pythonVersion}]{%
13+
\tightbox{\includegraphics[height=2.8cm]{\currentDir/installingPythonWindows02pythonVersion}}%
14+
}%
15+
%
16+
\hfill%
17+
%
18+
\subfloat[][Installing it by typing \bashil{python3} and hitting \keys{\return}.%
19+
\label{fig:installingPythonWindows03python}]{%
20+
\tightbox{\includegraphics[height=2.8cm]{\currentDir/installingPythonWindows03python}}%
21+
}%
22+
%
23+
\\[10pt]%
24+
%
25+
\subfloat[][The install screen, where we click \keys{Get}.%
26+
\label{fig:installingPythonWindows04installGet}]{%
27+
\tightbox{\includegraphics[width=0.485\linewidth]{\currentDir/installingPythonWindows04installGet}}%
28+
}%
29+
\hfill%
30+
%
31+
\subfloat[][The install screen, downloading \python.%
32+
\label{fig:installingPythonWindows05downloading}]{%
33+
\tightbox{\includegraphics[width=0.485\linewidth]{\currentDir/installingPythonWindows05downloading}}%
34+
}%
35+
%
36+
\\[10pt]%
37+
%
38+
\subfloat[][The installation is finished.%
39+
\label{fig:installingPythonWindows06finished}]{%
40+
\tightbox{\includegraphics[height=4cm]{\currentDir/installingPythonWindows06finished}}%
41+
}%
42+
%
43+
\hfill%
44+
%
45+
\subfloat[][And the \bashil{python3 --version} command now works in the terminal.%
46+
\label{fig:installingPythonWindows07pythonVersion}]{%
47+
\tightbox{\includegraphics[height=4cm]{\currentDir/installingPythonWindows07pythonVersion}}%
48+
}%
49+
%
50+
\caption{Cropped screenshots of the installation steps for \python\ on \windows.}%
51+
\label{fig:installPythonWindows}%
52+
\end{figure}%
53+
%
54+
Example installation steps for \python\ on \windows\ (version~10) are sketched in \cref{fig:installPythonWindows}.
55+
First, you would open a \gls{terminal} using \keys{\OSwin + R}, type in \bashil{cmd}, and hit \keys{\return}, as shown in \cref{fig:installingPythonWindows01openTerminal}.
56+
If \python\ is installed, then typing \bashil{python3 --version} in the terminal and hitting \keys{\return} would print the version of the \python\ installation.
57+
If it is not installed, however, then \windows\ will print a message informing you that \python\ is not yet installed and that you can reach the web installer by just typing \bashil{python3} (and hitting \keys{\return}, of course).0
58+
We do this in \cref{fig:installingPythonWindows03python}, which leads us to the installation screen (\cref{fig:installingPythonWindows04installGet}), where we need to press the \keys{Get} button.
59+
This will then download (\cref{fig:installingPythonWindows05downloading}) and install \python.
60+
When this process is completed, the screen just shows nothing (\cref{fig:installingPythonWindows06finished}).
61+
If we go back to the \gls{terminal} and again try \bashil{python3 --version}, it will now work and print the version of our \python\ installation.
62+
In our case, this is version~\softwareStyle{3.12}.%
63+
%
64+
\endhsection%
65+
%
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
\hsection{Python under Ubuntu}%
2+
%
3+
\begin{figure}%
4+
\centering%
5+
\includegraphics[width=0.7\linewidth]{\currentDir/ubuntuTerminalPythonVersion}%
6+
\caption{Under \ubuntu\ \linux~\softwareStyle{22.04}, typing \bashil{python3 --version} in a \gls{terminal} and hitting return yields version~\softwareStyle{3.10}.}%
7+
\label{fig:ubuntuTerminalPythonVersion}%
8+
\end{figure}%
9+
%
10+
Under \ubuntu\ \linux, \python~\softwareStyle{3} is already pre-installed.
11+
You can open a \gls{terminal}, type \bashil{python3 --version}, hit \keys{\return}, and get the result illustrated in \cref{fig:ubuntuTerminalPythonVersion}:%
12+
My system has \python\ version~\softwareStyle{3.10} installed.%
13+
%
14+
\endhsection%
15+
%

text/main/introduction/introduction.tex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Maybe some of the libraries you use get outdated and need to be replaced?
3636
There are several reasonable situations in which a totally different person may need to work, read, modify, and improve \emph{your} code.
3737

38-
Or maybe you are a researcher, using \texttt{Python} to implement some algorithm and to run an experiment.
38+
Or maybe you are a researcher, using \python\ to implement some algorithm and to run an experiment.
3939
In order to make your experiments and results replicable, you would probably want to publish your algorithm implementation together with the results.
4040
This only makes sense if your code is at least a bit readable.
4141

@@ -50,7 +50,10 @@
5050
One may hope that, as one of the very first things, surgery students in medical school are taught to wash their hands before performing surgery.
5151
Hence, we will teach you how to write clean, well-documented, and properly tested programs.
5252
Right from the start.
53-
Such that all of your code will be reusable, readable, clear, clean, and beautiful.%
53+
Such that all of your code will be reusable, readable, clear, clean, and beautiful.
54+
55+
As a result, this will be a course which is very practice centered.
56+
Our goal is to get familiar with programming, with the programming language \python, and with the tools and ecosystem surrounding it.%
5457
%
5558
\endhsection\endhsection%
5659
%

text/main/mainmatter.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
\bookmarksetup{startatroot}%
44
%
55
\hinput{introduction}{introduction.tex}%
6+
\hinput{basics}{basics.tex}%
67
%

0 commit comments

Comments
 (0)