-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistings.tex
61 lines (41 loc) · 1.6 KB
/
listings.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
% !TeX program = xelatex
% !TeX encoding = UTF-8
% !TeX root = listings.tex
\documentclass{../mirea-prog-lang}
\usepackage{hyperref}
\hypersetup{pdftitle={Демонстрация пакета Listings в mirea-prog-lang}, pdfauthor={В. С. Верхотуров}}
\usepackage{listings}
\usepackage{xcolor}
\lstset{basicstyle=\footnotesize, breaklines=true, numbers=left, captionpos=t, showstringspaces=false, commentstyle=\color{teal}, stringstyle=\color{red}, keywordstyle=\color{violet}} % Настройки, применяемые ко всем листингам
\usepackage{caption}
\captionsetup[lstlisting]{justification=raggedright, singlelinecheck=false}
\title{Демонстрация пакета listings\footnote{\url{https://github.com/ValeryVerkhoturov/mirea-kb2-programming-languages}}}
\date{\today}
\begin{document}
\maketitle
\addtocounter{page}{1}
\tableofcontents
\section{Документация listings}
Документацию listings см. в~\url{https://ctan.org/pkg/listings}.
\section{Пример листинга для С++ ISO}
См. листинг~\ref{lst:factorial}.
\begin{lstlisting}[language={[ISO]{C++}}, caption={Нахождение факториала}, label=lst:factorial]
#include <iostream>
using namespace std;
int main() {
int n;
long double factorial = 1.0;
cout << "Enter a positive integer: ";
cin >> n;
if (n < 0)
cout << "Error! Factorial of a negative number doesn't exist.";
else {
for(int i = 1; i <= n; ++i) {
factorial *= i;
}
cout << "Factorial of " << n << " = " << factorial;
}
return 0;
}
\end{lstlisting}
\end{document}