Syntax highlighting in LaTeX

Thu, Aug 20, 2020 2-minute read

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:

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!

  • By clicking button below you agree to send you news from my blog, about my products and services. Above data are stored in Mailchimp and I do not share them to anyone. More info you can find in privacy policy.