Syntax highlighting in LaTeX
First of all, you have to add new package to your document:
\usepackage{minted}
Then you can use in the document:
\begin{minted}{csharp}
// your_code
\end{minted}
Adding configuration:
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
...
Changing code block identation:
\begin{minted}
[
xleftmargin=...
]
{python}
...
Changing line numbers size (you have to add it before \begin{document}
):
\renewcommand\theFancyVerbLine{\large\arabic{FancyVerbLine}}
For adding label and caption to the code listing, you have to add something like below:
\begin{listing}[H]
\begin{minted}
[
// config
]
{csharp}
// code
\end{minted}
\caption{Caption}
\label{lst:label}
\end{listing}
Useful resources:
- Code Highlighting with minted
- Stack Exchange: Alignment of minted line numbers
- Stack Overflow: How to change the font size of line numbers using the Minted Latex Package
- The minted package: Highlighted source code in LaTeX
Newsletter
Thank you for visiting my website. I hope you enjoyed content which I prepared and learned something valuable from it. If you want to be informed about my next entries or occasionally get a message with a collection of some interesting links, please subscribe to my newsletter. I will be extremely pleased if you do this and join my community!