COPCSE-NTNU / bachelor-thesis-NTNU

A Latex template, class file, and examples for writing a bachelor thesis at NTNU
15 stars 51 forks source link

better code listings #6

Open SimonMcCallum opened 7 years ago

TJuberg commented 7 years ago

For code listing with syntax highlighting one could possibly also mention the minted package.

Eksempel på bruk av minted sammen med tcolorbox

% Minted og tcolorbox for syntax highlighting og fargerike bokser
\usepackage[many,minted]{tcolorbox}
\usepackage{minted}
% Default settings for Minted
\setminted{breaklines=true,autogobble=true}

% Macro for å opprette nytt minted miljø og tcolobox samtidig
\newcommand{\mynewminted}[3]{%
  \newminted[#1]{#2}{#3}%
  \tcbset{myminted/#1/.style={minted language=#2,minted options={#3}}}}

% Definere de forskjellige minted miljøene vi vil benytte
\mynewminted{myconsole}{console}{}
\mynewminted{myconsolelong}{console}{breakanywhere=true}
\mynewminted{mybash}{bash}{}
\mynewminted{mymanpage}{man}{}

% Kodeblokker
\newtcblisting[auto counter,number within=section,
  list inside=mypyg]{kode}[3][]{%
  listing only,title={#3},
  list entry={\protect\numberline{\thetcbcounter}#3},
  breakable,
  enhanced,colframe=blue!50!black,drop fuzzy shadow,myminted/#2,#1}

% oppgavesitater
\newtcolorbox{oppgave}[1][]{%
    title=Oppgavesitat,
    breakable,
    enhanced,colframe=brown!50!black,drop fuzzy shadow,
    #1
}

% Endring
\newtcolorbox{altered}[1][]{%
    title=Endring,
    breakable,
    enhanced,colframe=red!50!black,drop fuzzy shadow,
    #1
}
ifarup commented 5 years ago

After reading this discussion

https://tex.stackexchange.com/questions/389191/minted-vs-listings-pros-and-cons

I prefer to stay with listings. However, the listings package is highly configurable, so we could make much better use of it than we currently do.