Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

There are several methods for importing code to your project. We will here provide you with some of our different methods and styles, hopefully enabeling you to find or create the one you enjoy the most. As always, keep in mind that there are many other good tutorials online, covering both the methods we explain here, but also other methods. To improve the most, we highly recommend you to locate these!


Info

The example code used on this page is written in C++, but the difference is negligible for other languages.



Panel
borderColor#dfe1e5
bgColor#eff9ff
borderWidth2
titlePage content

Table of Contents


Minted

Minted is a package that allows formatting and highlighting source code in LaTeX. Some minted documentation may be found here.

We will only use the option of including code through external files, but you may also include code directly. An example is shown below.

Expand
titleInclude code in Minted - Example


Code Block
languagetext
// Method 1 - Assumed that the code included in 'isPrime.cpp' is the same as in Method 2
\inputminted[breaklines]{C++}{isPrime.cpp}

// Method 2
\begin{minted}[breaklines]{C++}
bool isPrime() {
	int number;
	std::string question = "Please enter a number: ";

	std::cout << question << std::endl;
	std::cin >> number;

	for (int i = 2; i < number; i++) {
		if (number % i == 0)	// If prime number
			return false;
	}
	return true;
}
\end{minted}

BibTeX Display Table

There are several methods for importing code to your project. We will here provide you with some of our different methods and styles, hopefully enabeling you to find or create the one you enjoy the most. As always, keep in mind that there are many other good tutorials online, covering both the methods we explain here, but also other methods. To improve the most, we highly recommend you to locate these!

Info

The example code used on this page is written in C++, but the difference is negligible for other languages.

Panel
borderColor#dfe1e5
bgColor#eff9ff
borderWidth2
titlePage content

Table of Contents

Minted

Minted is a package that allows formatting and highlighting source code in LaTeX. We will only use the option of including code through external files, but you may also include code directly. An example is shown below.

Expand

\inputminted[breaklines]{C++}{isPrime.cpp}

\begin{minted}[breaklines]{C++}
bool isPrime() {
int number;
std::string question = "Please enter a number: ";

std::cout << question << std::endl;
std::cin >> number;

for (int i = 2; i < number; i++) {
if (number % i == 0) // If prime number
return false;
}
return true;
}
\end{minted}





BibTeX Display Table