Code_Presentations_Example__different_ways__shown_in_Beamer_Metropolis_
Code_Presentations_Example__different_ways__shown_in_Beamer_Metropolis_
LATEX Ninja
June 2019
Introduction
Intro i
When I thought about it, I realized there are actually so many ways of
displaying code using LaTeX packages. So I’ll start with the most
basic and then go on to the more advanced ones ;)
1/15
Intro ii
2/15
Intro iii
3/15
Bugs
4/15
Tcblisting
Tcblisting
The code is quite tiny because I set the font size to very small in the
definition of the little myr
Load files
1 # text <- readLines(file.choose())
2 filePath <- "http://www.link.com/a_text.txt"
3 text <- readLines(filePath)
5/15
lstlisting
Using Code Listings
my_ v e c t o r <− c ( ” t e s t i n g ” , ” v e c t o r s ” )
my_ v e c t o r # a t e s t
6/15
Using Code Listings II
7/15
Code highlighting with listings
Listing 2: A demonstration
import numpy as np
You can also use the inline shorthand for small snippets:
while{$a || $b}
8/15
List of listings
Well, this is how it’s supposed to be, but sadly, using sections inside
frames will add up to this result. – So you can’t use this list of
listings here.
9/15
Importing listing from file
<codelisting ref="#test">
<fun>
<bla>
lalalalala <lb/>
<!-- comment -->
</bla>
</fun>
</codelisting>
10/15
Using Knitr
# Create sequence
my_sequence = 1:5
11/15
Using Knitr with options
12/15
Using minted
int main() {
printf("hello, world");
return 0;
}
13/15
Using minted
There also is the option to include math mode stuff in the comments.
/*
π = limn→∞ Pdn
*/
const double pi = 3.1415926535;
14/15
Using minted with options
1 import numpy as np
2
3 test = 5
15/15
This is it ⌣
15/15