惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Martin Fowler
Martin Fowler
雷峰网
雷峰网
IT之家
IT之家
小众软件
小众软件
M
MIT News - Artificial intelligence
博客园 - 聂微东
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
C
Check Point Blog
云风的 BLOG
云风的 BLOG
腾讯CDC
H
Help Net Security
Y
Y Combinator Blog
I
InfoQ

Comments for all models are wrong

-> Going both ways in R <- Simple animation and saving movies in Python Simple animation and saving movies in Python
Latex, Beamer, Python, Beauty
mikedewar · 2009-02-26 · via Comments for all models are wrong

This post quickly shows how to create pretty latex beamer slides, that don’t look anything much like maths seminar slides, and  that can include well formatted (Python) code, as well as the normal stuff that Beamer is so good at (maths, videos, etc). I’m assuming you’ve got a `standard’ install of latex (by standard I mean: like mine) that includes beamer and the listings package. I’m also assuming that you already know how to use beamer, so I’ve not included all the documentclass junk and so on. Here’s a taster of what it looks like, how to do it is after the break:

beamer_screen

There are three things we need to do to make beamer slides like this that don’t look like those endless maths-y beamer slides that everyone seems to like for some reason.

  1. Get rid of all the junk on the top and the bottom! No-one can see it anyway!
  2. Make the colours of the presentation very pretty.
  3. Make the listings use a better font than courier, and also use pretty colours!

1: get rid of all the junk

This is an awesome command. It’s (maybe) the longest single command ever in the world, sort of like that village in Wales with the huge name:

/usetheme{default}
/beamertemplatenavigationsymbolsempty

So now, your beamer presentation is nice and clean and happy.

2: Make Pretty Colours

This is just like knowing the magic words. We define a colour, then we assign it to a magic word. So lets define three colours, a background, a foreground and a title colour:

/definecolor{fore}{RGB}{249,242,215}
/definecolor{back}{RGB}{51,51,51}
/definecolor{title}{RGB}{255,0,90}

These colours are awesome but obviously you can choose your own if you’re a philistine and disagree. I’ve chosen the names (like fore), but they can be whatever you like. You can use other colour specifications instead of RGB, though using RGB for a presentation makes sense to me because it’s probably never going to be read seriously on paper. Now we need to tell beamer to actually use them:

/setbeamercolor{titlelike}{fg=title}
/setbeamercolor{normal text}{fg=fore,bg=back}

there are millions of these magic words like ‘titlelike’ but no-one will tell you what they are.

3: Make the listings pretty!

To include code listing (like Python) we use the listings package because it’s brilliant. We need:

/usepackage{listings,bera}
/definecolor{keywords}{RGB}{255,0,90}
/definecolor{comments}{RGB}{60,179,113}
/lstset{language=Python,
keywordstyle=color{keywords},
commentstyle=color{comments}emph}

The packages are for the listsings (clearly) and bera is the font. It’s secretly Bitstream Vera but they had to change the name or something because the world is messed up! Anyway bera is a lovely font in my honest opinion and you should use this and not courier which is ugly and very last century.

The colours are for comments and keywords which you’ll see in a sec, be patient.

The funny lstset command tells the listings package some things. The first is that we’re using Python. There are other languages, I think, but why we wouldn’t be using Python is beyond me. Then we ask listings to make our keywords the colour we defined above (pink!) and our comments to be the comment colour and also emphasised!

Finally, we must make a sample page to demonstrate the lstlisting environment, and because there’s one more important thing that is NOT OBVIOUS! Here’s a sample page:

/begin{frame}[fragile]
/frametitle{A Page}
/begin{lstlisting}
def list_of_vectors(n,T):
 return [matlib.zeros((n,1)) for t in T]
/end{lstlisting}
 Here is an equation:
 /begin{equation}
 x_t = Ax_{t-1} + w_t
 /end{equation}
/end{frame}

The thing to note is the [fragile] command. Here’s what it does. It means that the weird error that happens if you don’t include it DOESN’T HAPPEN! Enjoy!