This repository has been archived on 2024-08-29. You can view files and clone it, but cannot push or open issues or pull requests.
LaTeX-Snippets/minted/main.tex

107 lines
3.2 KiB
TeX
Raw Normal View History

2023-09-05 11:42:55 +00:00
\documentclass{article}
% ===================================================
2023-09-05 14:11:29 +00:00
% _____ _
2023-09-05 11:42:55 +00:00
% | ____|_ ____ _ _ __ ___ _ __ | | ___
% | _| \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
% | |___ > < (_| | | | | | | |_) | | __/
% |_____/_/\_\__,_|_| |_| |_| .__/|_|\___|
2023-09-05 14:11:29 +00:00
% |_|
2023-09-05 11:42:55 +00:00
% License: MIT
% Author: Sven Vogel
% Copyright: Sven Vogel (2023)
% Based on the tutorial at:
% https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted
2023-09-05 14:11:29 +00:00
% More infos can be found here:
% https://tug.ctan.org/macros/latex/contrib/minted/minted.pdf
2023-09-05 11:42:55 +00:00
% ===================================================
% include the required package
% make sure this is installed:
% > tlmgr install minted
2023-09-27 15:38:46 +00:00
\usepackage[outputdir=.tmp]{minted}
2023-09-05 14:11:29 +00:00
% ===================================================
% set global style for minted
2023-09-27 15:38:46 +00:00
\usemintedstyle{tango}
2023-09-05 14:11:29 +00:00
% set global options for all listings
% these can also be applied locally to individual listings
\setminted {
linenos=true, % enable line numbers
2023-09-27 15:38:46 +00:00
bgcolor=white, % background color
2023-09-05 14:11:29 +00:00
resetmargins=true,
tabsize=4, % white spaces for tabs
xleftmargin=24pt, % margin to the left side. can be used to include line numbers
escapeinside=|| % symbols used to escape LaTeX
}
2023-09-05 11:42:55 +00:00
% ===================================================
\title{Minted-Syntax-Hightlightning-Test}
\author{Sven Vogel}
\date{September 2023}
\begin{document}
\maketitle
% ===================================================
% Add the list of listings
\renewcommand\listoflistingscaption{List of source codes}
\listoflistings % Now typeset the list
% ===================================================
\section{Introduction}
The following will show some syntax highlighted source code:
% ===================================================
% define some source code and specifiy the language
% every minted block is wrapped in a listing block for alignment and
% the option to add some caption and label
\begin{listing}[ht]
2023-09-27 15:38:46 +00:00
% specifiy language
2023-09-05 11:42:55 +00:00
\begin{minted}{python}
2023-09-27 15:38:46 +00:00
2023-09-05 11:42:55 +00:00
def incmatrix(genl1,genl2):
for i in range(m-1):
for j in range(i+1, m):
2023-09-05 14:11:29 +00:00
// TODO: do sth.
2023-09-05 11:42:55 +00:00
[r,c] = np.where(M2 == M1[i,j])
for k in range(len(r)):
VT[(i)*n + r[k]] = 1;
VT[(i)*n + c[k]] = 1;
VT[(j)*n + r[k]] = 1;
VT[(j)*n + c[k]] = 1;
2023-09-05 14:11:29 +00:00
# the following text is escaped LaTeX
|\colorbox{yellow}{test}|
2023-09-05 11:42:55 +00:00
if M is None:
M = np.copy(VT)
else:
M = np.concatenate((M, VT), 1)
VT = np.zeros((n*m,1), int)
return M
2023-09-27 15:38:46 +00:00
2023-09-05 11:42:55 +00:00
\end{minted}
\caption{Some python code} % add a caption
\label{listing:1} % add a label for referencing
\end{listing}
2023-09-05 14:11:29 +00:00
% inline code:
Here we have inline code: \mintinline{python}{print(x**2)}. See?
2023-09-05 11:42:55 +00:00
This code is imported from a file:
% import code from a file:
\begin{listing}[ht]
\inputminted{latex}{some_code.txt}
\caption{Some latex code}
\label{listing:2}
\end{listing}
% ===================================================
2023-09-05 14:11:29 +00:00
\end{document}