3

I'm a newbie to LaTeX, especially the minted package. I would like to customize it such that the code has a similar style to the attached screenshot. Specifically, I wish to be able to customize:

  • The font and background shape / color of mintinline
  • The spacing between background edge and text inside minted
  • Round corners of background in minted
  • The line spacing in minted

Here's what I have thus far:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{newverbs}

\definecolor{inline}{RGB}{187,57,82}
\definecolor{bg}{RGB}{22,43,58}

\newverbcommand{\cverb}{\color{inline}}{}
\usemintedstyle{paraiso-dark}
\setminted[java]{bgcolor=bg, fontfamily=fdm, fontsize=\footnotesize}

\begin{document}

\begin{minted}{java}
    public class ClassName
\end{minted}

enter image description here

  • 1
    Could you extend the code to a full but minimal compilable document, please? People will be more eager to help if they don't need to find a way to make your sample compilable before they can start working on the actual issue. – siracusa Sep 24 '18 at 0:58
4

Here's something to get you started. This uses tcolorbox to create a box around your listing (the keys left, right, top and bottom allow you to specify the distance between box and text).

For a customization of your \mintinline see the examples on \DeclareTotalTCBox (page 440 in the tcolorbox manual).

tcblisting

% arara: pdflatex: {shell: 1}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins}

\tcbset{listing engine=minted}

\newtcblisting{javalst}{listing only, minted language=java, minted style=paraiso-dark,
    colback=bg, enhanced, frame hidden, minted options={fontfamily=fdm, 
    fontsize=\footnotesize, tabsize=2, breaklines, autogobble}}

\definecolor{inline}{RGB}{187,57,82}
\definecolor{bg}{RGB}{22,43,58}
\setminted[java]{bgcolor=bg, fontfamily=fdm, fontsize=\footnotesize}

\begin{document}

\begin{javalst}
    public class ClassName {
            public static void main(String[] args) {
                System.out.println(args);
            }
    }
\end{javalst}
\end{document}
  • Thanks so much! Works perfectly! With regards to mintinline, I tried implementing the \DeclareTotalTCBox command, however I still am unable to figure out how to get it to be like in my example. Could you help out with that as well please? – Richard Robinson Sep 24 '18 at 13:44
  • 1
    @RichardRobinson I did not quite get what you want. The example you have shown looks like rendered markdown where inline code is normally not syntax highlighted while minted does so. If you only want to reproduce this you only need to set colback (with frame hidden as in my example) and the font color (I do not know the key's name, but it should be easy to find this in the documentation). – TeXnician Sep 24 '18 at 13:47
  • Yes, thats exactly what I want to do! How do I go about setting colback and the font for mintinline though? – Richard Robinson Sep 24 '18 at 13:50
  • 1
    @RichardRobinson Use the example provided in the manual. If that doesn't work, please ask a new question showing what exactly did not work for you. – TeXnician Sep 24 '18 at 13:52
  • Ok, I did as such: tex.stackexchange.com/questions/452249/… – Richard Robinson Sep 24 '18 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.