# Cheat Sheets and Study Summaries

This is a quite long post about cheatsheets and also about effective studying. When you need a cheatsheet, chances are you’re trying to learn something (or use something or not yet very familiar with). Because if you already were and experiened expert, you wouldn’t need a cheatsheet, right?

First, I only wanted to share this cheatsheet template I made and explain why I did what I did. I ended up explaining the concept of the “survival summary” for effective studying and exam preparation, rant about what I think people do wrong when making cheatsheets and why I think the theory of effective learning should ultimately reflect in your cheatsheets. By the way, I hardly ever stick to my own rules when making cheatsheets… 😉

If you only care about the cheatsheet, please just scroll down and go get the template or skip to the section on the ‘design principles’ for my template 😉 . Everything else is a (prolonged) explanation of what I did and why I did it on a more theoretical level but I think (hope?) it might be a beneficial read 😉

## Cheatsheet philosophy

### Space

If you google how to create a cheatsheet, people will recommend you redefine all the section headings etc. as to remove as much unnecessary space as possible. But space is what gives you overview, it’s what guides your eves. If you remove it, you will lose a tremendous amout of time looking for information and not finding it straightaway. It would make more sense to actually reflect what you’re doing and try to save space by reducing unnecessary contents.

### Content

But apart from squeezing too much info on cheatsheets per page, another problem is the content itself. I checked out some cheatsheets to research this post and obviously with LaTeX-based cheatsheet templates, many take LaTeX itself as the subject. With what I found, the results often contain pretty superfluous information. That is to say that, for example, in many cases, almost the whole first page is made up of information with a way too short half-life. The starting out info will become obsolete once you’ve used LaTeX 3 times. Do you really want to add that to your cheatsheet? Maybe you could leave it out or create another resource (a getting started manual) or just reduce it to a bare minimum with a small font size.

### Font

Chose an easy-to-read font. Especially one which is easy to read from a little bit further away. Information which is very easily readable will be remembered more than some serify font. Resetting this might actually benefit your cheatsheet more than removing space because an easy to read font will make sure your document is readable from further away. Meaning you can reduce the font size. LaTeX’s standard font, Computer Modern, is very beautiful but it’s (modern) serif. Serif fonts are not good for study summaries or cheatsheets since the require a “closer reading”. Ever wondered why advertisements hardly use serif fonts? Sans-serif fonts are easier to read even when you’re not really looking. I would, by the way, also suggest you write your handwritten summaries in print type rather than in cursive writing for better overview.

### Cramming in more

If you have to, downsize the font size but don’t get rid of the spacing. Of course that’s going to save you time and allow you to cram in as much information as possible. But is that really the most effective thing to do? Don’t you want the cheatsheet in the first place to reduce the complexity of the topic? If you’re going to just copy it in from any source, you might as well not make a summary but always use the internet so you can find the information you need quickly. Thus, wouldn’t getting rid of all the structuring elements amount to the opposite result of what you intially wanted?

A good cheatsheet (or study summary, which is probably more accurate), in my opinion, will contain shockingly little information but all the information included will be highly relevant. Also, instead of listing all the possible commands, why not mention or introduce them, while explaining something actionable? You could group your cheatsheet not into types of commands but into topics or problems one might want solved. An actionable and task-oriented cheatsheet is more effective than a reference style one.

## The “survival summary”

When I write about cheatsheets, I can’t help but mix it up with the concept of the “survival summary” somehow. I got to know the concept in Krengel 2012 (see references) where he writes about how to study best. I am aware they’re not the same but thought you might be interested to learn about them anyway. In his book, after demonstrating effecitve note-taking (very visual and structured), Krengel explains his concept of the “survival summary” where you condensate all the material to be learned in one single page, in a late stage of studying for an exam when you already have the overview (also this method forces you to get yourself an overview…).

The idea behind this is that you can’t remember one hundred pages. But you can sure as hell remember one. So make sure everything which is absolutely necessary (what you need “to survive”) is on this page and act like your survival depended on it. Only add key concepts, not detail facts. Except maybe one or two indispensable, central ones which help to make it more visual. Using examples is always good as it induces some kind of “storytelling” which is good for memory.

Of course, if your exam consists in knowing detail facts by heart, this is just a good guideline for your memory. This summary is not meant to replace everything else. It just serves as the “memory hook” where you can localize your detailed knowledge. But I will exclusively reveal here that I have passed many exams by just knowing this most important info and having prepared a really good “survival summary” (without studying anything else before). You can definitely get by like this because the survival summary is basically the definition of a “pass grade”, embodied in an object in the form of a piece of paper. It contains all the info you need to succeed. Of course, you’ll really need to know its contents well, but if the summary is visual enough, it will be quite easy to remember. Hardly anyone will have problems remembering just one page if they really try.

## Note taking and ‘reducing’ information to the most imporant bits

Reducing is probably not the right word. It’s more like condensing lots of bla into the info behind it. Once you start doing this that the bla-to-info ratio is quite scary. In most kinds of schooling, there is tons of bla and, usually, very little info. So reduce complexity, introduce clarity and overview. Be visual. Focus on the bigger picture. Unnecessary detail will only cloud your mind. Don’t try to remember everything. It’s a recipe for disaster and, if anything, will ensure you remember nothing at all.

This overview, this summary is your security. Think of it as insurance. If done well, it will ensure you pass the exam. If you aim higher, it will be a sound base to ground your details on and give you a sense of security which will make you more confident. You can remember one single page, right? This page contains everything you need to pass, so what could really go wrong?

I personally started even taking my lecture notes like “survival summaries” rightaway, to save even more time. You end up with 10-12 survival summaries which you can reduce into the final study summary just before the exam. This will save you lots of time. So rather than just mindlessly noting down everything the professor says, only note down important stuff or information which is likely difficult to find outside of the lecture notes. If the information is on Wikipedia, only write down the keyword. Or make a glossary rightaway where you put all the ‘difficult words’ and their definitions.

These words alone often can go as a survival summary. If you know what they all mean and the concepts they’re related to, you already have the gist of what’s going on. When in class, always make three columns on your paper.

1. Left column: Leave empty to fill in the summary / keyword / heading of the current topic.
2. Middle column: Your actual notes.
3. Right column:  Anything you need to remember, be it historical dates in history, vocabulary in a language class or a glossary of difficult words.

In the middle column, highlight the important words as you write, so you don’t have to re-read everything to remember what paragraphs were about. You need this info to fill in the topic heading in the left column. The left and right columns are the prep work for your study summary. When preparing for the final summary, cut out everything repeating itself or not strictly necessary. Sum it all up in one final survival summary.

## Reduction and reflection >  mindless note-taking

Dare to only note the most important stuff. Most people want to note down everything because it makes them feel safe. Leaving things out, they fear to end up not understanding their notes anymore. This is not an issue if you take good notes and give thought to how you write things down. Often you don’t need to write a whole sentence to unambiguously understand the content. Or, if you have the keyword and the context, it takes 5 seconds to look it up on the internet should you really not remember what it meant. It is way more time-consuming to have to work through extensive notes. That’s why lots of people fail exams despite lots of work taking excessive notes. Every single word you note down you will have to work through again. Do yourself a favour and note down only what’s actually important.

Not noting down everything is beneficial for many reasons:

1. It’s the first stage of reduction of the material, if done right.
2. Taking good notes makes creating summaries so much faster.
3. Having condensed visual notes from the last lessons allows you to have the overview and keep you from noting down things multiple times.
4. If you never take more than one page of notes per lesson, reviewing the content before the next lesson will be really easy. You can learn things straightaway rather than waiting until the exam. Learn things as they come up! This advice from Steve Pavlina is probably the best studying advice ever.
5. Not writing complete sentences, using visual boxes with no more than 3-5 concepts per block, you actively make the information easy to grasp for your brain. Also, you find things more quickly.

### 8. Learn material the very first time it’s presented.

One of the biggest time wasters in school is having to relearn something you didn’t learn properly the first time. When students say they’re studying, most of the time they’re making up for a previous failure to learn the material.

In software development it’s well known that bugs should be fixed as soon as possible after they’re introduced. Waiting to fix a bug near the end of a project can take 50x as much effort as it would take to fix the bug the first time it was noticed. Failing to learn what you’re supposedly taught each day is a serious bug. Don’t try to pile new material on top of an unstable foundation, since it will take even more time to rebuild it later.

If you don’t understand something you were taught in class today, treat it as a bug that must be fixed ASAP. Do not put it off. Do not pile new material on top of it. If you don’t understand a word, a concept, or a lesson, then drop everything and do whatever it takes to learn it before you continue on. Ask questions in class, get a fellow student to explain it to you, read and re-read the textbook, and/or visit the professor during office hours, but learn it no matter what.

10 Tips for College Students, Steve Pavlina

Once you’re not new anymore at university and know your way around, you will quickly know where the lecturer has gotten his or her information on. (Hint: it’s probably somewhere in the literature list you never cared to notice). This is why my survival summaries and notes only contain insights or information so condensed you wouldn’t find them anywhere else. If your summary is supposed to be a go-to resource alongside the omniscience of Google, it has to be really good and give you access to information Google (or the library) couldn’t give you.

If it can be looked up quickly, is a detail and not extremly central to the point, don’t bother writing it down. You won’t be able to read your own handwriting in a few weeks anyway. If you type your notes on a computer and have decent typing skills, chances are you’ll procude so much text you’ll never be able to go through when studying.

I used to be quite religious about lecture notes and summaries. I wanted to make perfect notes, grasp all the information, constantly improve my note-taking skills until I realized the true art of good summaries lies in leaving things out.

Good notes glow with simplicity. If you’re notes are digital (written in LaTeX like my cheatsheets of course), use \href{http://link.com}{Name} to hide reference links in the texts. This will stop ugly links from ruining the overview but calm your fear of “forgetting or leaving out important information”.

Of course, since you’re not the one teaching the class, you can never quite know exactly what is most important, or completely unimportanty respectively, to the teacher. This is why, perfectly simplicistic survival summaries will remain a theoretical ideal you can never fully achieve. But that’s not a reason not to try. Don’t think this is the lazy way out either. It is actually quite hard, challenging work and requires a very good overview about the subject in question. I have created many bad survival summaries because I didn’t bother take enough time to understand the material at hand. These bad summaries will not get you very far.

Ideally there should be no need to study outside of class, at least in the sense of relearning material you didn’t learn the first time. You can review old material to refresh your memory, but you shouldn’t have to devote a minute of your time to learning something that was taught a month or two earlier.

[…]

During each semester ask yourself this question: Am I ready to be tested right now on everything that has been taught up to this point? If your answer is ever “no,” then you know you’re falling behind, and you need to catch up immediately. Ideally you should be able to answer “yes” to this question at least once a week for every subject.

[…] Put in the effort to learn your material well enough to get As in all your classes. It will pay off. Much of the material you learn will build on earlier material. If you get As in your freshman courses, you’ll be well prepared to pile on new material in your sophomore year. But if you get Cs that first year, you’re already going into your second year with an unstable foundation, making it that much harder to bring your grades up and really master the material. Make straight As your goal every semester. In the long run, it’s much easier. I found that C students tended to work a lot harder than I did, especially in their junior and senior years, because they were always playing catch up. Despite my packed schedule, it wasn’t stressful for me because I kept on top of every subject. Consequently, I had plenty of time for fun while other students experienced lots of stress because they constantly felt unprepared.

Steve Pavlina, Do it now

## How to know if a summary is good?

How do you know the summary is good? Well, you’ll never be able to guarantee. But usually, you’ll have a good feeling about it. If it doesn’t contain all the topics, for example, that’s a good indicator of a bad one. Or, when you went into a lot of detail in subject one and left out subject two because you spent all your energy on subject one, this is a classical example of the “unbalanced survival summary”. This happens, but shouldn’t. Thankfully, seeing as these summaries are quite visual, it will be quite apparent to you.

A summary or part of summary with tons of detail also mostly is an indicator you should deepen your knowledge about the subject first. A lot of detail usually means you lack the general understanding of the bigger picture and are very unfamiliar with the topic. See my comments about how an advanced person’s cheatsheet is not the same thing as beginner’s intro. This is exactly what I’m talking about here. A beginner will add detail which is necessary only for the very limited amount of time you’re a beginner. It might even be very relevant then. But it will turn to completely irrelevant once you’ve moved on to advanced user. An advanced user will add very little detail unless there is a good reason for it. The result will visibly be more balanced, topic-oriented, containin key concepts and an overview of the bigger picture.

You will learn a lot trying to condense information into a survival summary like this. In fact, this had turned out to be the most effective study strategy for me as you’re not complelely passive in this kind of revision.

So make sure to:

• use the methods of chunking (2-4 chunks) or storytelling (I mostly use chunking only though)
• Garbage In, Garbage Out –> if you don’t do some serious “editing” with your learning materials, this is what you’ll get…
• Condensate: “zoom out”
• Reduce: get rid of anything redundant or trivial
• get visual
• Facts versus skills: Operationalize

## What is a cheat sheet? Theory and practice

### What it should be

A memory aid which stores information you might need quick access to and need fairly frequently but not frequently enough so you would recall it without the cheatsheet.

#### What it shouldn’t be A crib

The thing you used in school to cheat (ok, yes I did too. I fact, quite masterfully so^^). I used to have these really full cribs which contained EVERYTHING and I printed them out, using the 16 pages or 32 pages on one page mode. Used to work pretty well.

#### A beginner’s guide

Beginner’s guides are totally legitimate but please, if you want both a cheatsheet and a beginner’s guide, make sure to create two different documents.

The problem is: A beginner’s guide includes tons of information you totally do need when starting out. But once you’ve successfully gotten started, most of this information is 100% obsolete. You’ll either never need it again (because it was one time information, like how to install something) or you will have it memorized by heart because you use it too frequently. The information contained in the beginner’s guide can intersect with the one still relevant later on, but in part, certainly will be obsolete once you’re not a beginner anymore. And, believe it or not, once you actually get started, you will reach advanced status fairly quickly. So make sure to keep those documents seperate. Just take the time to make one sheet with basic info and another one with info which might still pass as “basic” but will remain at least somewhat relevant to an advanced user.

#### A lexicon or a reference

I see this with LaTeX cheatsheets a lot. People cram in all the information there is. Including a minimal working example of a LaTeX document. Please, people, you will need this information exactly once. If you’re using an editor which provides some setup support (like Overleaf or even TeXmaker etc.) you will never use this information again. Unless you’re one of those hardcore people who don’t use IDEs. And even then, you probaly won’t need it more than three times until you have memorized it.

#### The command graveyard

Or, instead of the minimal working example, they add in all the symbols you can possibly use in LaTeX. Even if you use LaTeX for math purposes, there is no way you’ll ever need all those symbols. Some you will need fairly frequently, some you won’t need at all. And, if you have some basic familiarity with the greek alphabet, you will know the names of the letters. And can just write them as commands. No need to print the whole alphabet, right? If you don’t know the Greek alphabet and need it regularly, learn it please?

Like I will elaborate in the “design” section below, every detail which is in the slightest bit  unnecessary will ruin the overview and undermine the purpose of your cheatsheet (quick access to relevant info).

If the overview is so poor and you’re faster Google-ing your wanted information, what the hell do you need a cheatsheet for? Unless you have no internet, of course. So when preparing a cheatsheet, don’t go thorugh all the beginner’s tutorials and add everything they have (unless you want to make a beginner’s guide, but if you do so, please do so explicitly).

Look for information which fits the criteria below:

1. If you feel you absolutely need to add in some basic function, don’t waste a lot of space for it. Or demonstrate the basic thing while demonstrating something more advanced or rare.
2. Don’t add things you might ever only need once, like infrequent symbols.
3. Don’t add startup info unless you’ll need it more than once. Also, make this a “detail on demand” (see design principles below) if you feel you absolutely can’t go without it.
4. Also, just generally avoid adding “extensive lists”. If your cheatsheet is supposed to be a memory aid, keep in mind that the brain can only process so many chunks at a time (3-5). Accordingly, one block of information should not include more than 3-5 elements at a time.
5. Cut out anything unnecessary. Summarize, cut and shorten radically. Keep to the absolute minimum. Make it zen. Simplify. Really take the time to do this, it will maximize your benefits.
6. Good cheatsheet design takes up a lot of time. But once the cheatsheet is done, it will be useful to you for a long time.
7. Don’t just sit down and create a cheat sheet. A really good cheatsheet will need some design first. Brainstorm, see what information you want to include. Note down everything you feel you need, then shorten radically and find creative ways to make it more to the point.
8. This creative process is what we might call editing. There is this quote: The first draft of everything is bullshit. What it means is that most people stop before the actual work starts and that’s why their results are bad. Outputs only get really good if you sit down to edit them and make them better, design them carefully, etc. When writing a paper, for example, putting the info on paper is only half of the work. Internal editing, peer review, etc. will make the final result take about twice as long as the inital step of “writing the paper”. Most seminar papers are bad because students just stop after they have sloppily collected and written down the information. The papers end up lacking detail in research but also lacking grammatical corrections, reformulating to make the outline and the sentences more clear, etc. The same goes for anything you produce.
9. A good cheatsheet is something you might want to use for a long time or even share with others so they can profit from it too. If you make a good summary for studying, you can use this as a memory aid or refresher long after the exam. If, and only if, you did it well to begin with. Or imagine you want to take an advanced class. A good cheatsheet will make sure you master the basics, and if you don’t, have them at the ready whenever you need them. Or, when preparing for an exam, the extra time might seem a waste of time – but, on the plus side, you’ll be way further along in your studying if you have taken the time to make a high quality cheatsheet, and you also have a good point to start should you happen to fail the exam. Whoops.

## Basic design principles

Data vizualization 101 also applies to effective learning and, thankfully, the most important principle can be summed up in one single sentence:

Overview first, zoom in, detail on demand. (Shneiderman’s Mantra)

1. Overview first: means big headings about the subject of every block.
2. Zoom in: you go from the “hook” which is the heading to the actual information, i.e. details (in this case).
3. Detail on demand: this works well in responsive applications but how to implement this on an analogous piece of paper, you ask?

When I prepared class summary sheets for studying (and I used to be very religious and peculiar about this, believe me. In fact, I probably still am.), I made big headings (stage 1: overview first), then added the info below (stage 2: zoom in) and added details in such a small font size that you had to physically get close to the paper to be able to read it. As I wrote this by hand, the writing became almost impossible to read. And that was the brilliant part of it.

The point is, we mostly are so afraid to leave some less than important piece of information out, because we feel like we’re going to miss out (or something, I can’t even really explain why). We’re afraid this information is a crucial detail when mostly, you’ll never need it again. Also, by noting down all the information, we are lured into the false security of thinking we have it noted down anyway, so it’s not so important we actually memorize it.

While this is not exactly the goal of learning, it also makes us end up with pages and pages of notes which we will never get through when studying for the exam. Also, working like this, we will never ever actually have an overview what the class was about and since teachers mostly fail to mention which ones were the most important contents, we will probably remember the least important detail only. Congratulations.

The cheatsheet is not a universal reference and not the place where you “write down everything”. You only write down that which is important and choosing what is important always means you’ll have to discard certain items. The study cheatsheet does not need to include everything, that’s what books, Google or your notes are for. The cheatsheet sums up the most important stuff in an overview.

I don’t always follow my own advice, of course, and tend to want to include every little detail. But once the summary is done and I acutally use it, I always regret including too much detail, especially the absolute basics. I find the best way here is to include them but

a) keep it small and

b) include it combined with some other less important information you kind of want to include but wouldn’t be important enough otherwise.

I sometimes write my summaries while a class still goes on: I reserve a spot on the (analogous) paper for every session. My university classes are usually 12 to 14 sessions. This is more tricky, of course, since something which seemed new and important at the beginning might be obvious and unnecessary once you’re deeper into the topic. Avoid reserving too much space for the basics as they are likely to end up not being important anymore. Or write your cheatsheet in LaTeX (of course 😉 ). You’ll be able to modify it in the way that makes the most sense once the class is over, there is nothing more to be added and you’re doing revisions. So these are the key principles:

2. Boxes ( don’t add more than 3-5 chunks)
3. White space: Unlike many other cheatsheets, don’t use every inch available to you. Don’t cram in every detail. Space it out, it will greatly benefit the overview (and thus, your learning).
4. If you absolutely can’t go without some detail, make it so small you’re almost unable to read it. Force yourself to have to remember it. Don’t count on the fact that it’s all there and all available at one click.

## The Cheatsheet – Template and explanation

The \mycommand command for displaying commands and their explanations uses \detokenize to display code. It functions as explained here . However, some problems remain, like you can’t use \maketitle or comments (%) in the command.

Also, don’t forget you can’t add any styling to the command part of \mycommand. This should be obvious but I catch myself trying to insert commands and wondering that they’re just displayed as text all the time. 😉 It usually takes me a few seconds before I realized this is a feature I actually knowlingly configured to work as such.

The subboxes are done using tcbraster (indicating the number of columns). There would be an option to indicate rows as well, but I couldn’t see why I would need that and if one ever should, one could just use 2 mulitboxes (works just fine, if you ask me…).

## Playing around: Cheatsheet to beamer

After I created a cheatsheet using this template, I had the idea that I could ‘generate’ presentation slides from it. This was quite easy. I opened a beamer template and pasted the document body of the cheatsheet into it, replacing all the \begin{textbox} with \begin{frame}[allowframebreaks] and the \end{textbox} with \end{frame}.

This seemed like a quick and easy way to create slides from the cheatsheet. It turned out, however, that tcblisting has some issues with enumerate or itemize environments in the beamer documentclass. The co-presence of those two in one document will stop the whole thing from compiling due to a bug in the beamer class, apparently. It took me very long to find out why exactly, believe me.

Also, the resulting slides are not, like, suuuuper beautiful, if you know what I mean. The automatic framebreaks are not great but, at least, will give you working slides instantly, even if your boxes were very full (which probably they shouldn’t be in the first place…). The slides are nothing special, but they work as long as you never have code examples and lists in the same document. Or you’d have to rearrange your code exmaples from tcblisting to lstlistings. I do quite prefer tcblistings to be honest. And, in the concrete case, if you care to know, I had been late preparing my class which was supposed to happen in a few hours time, so I decided my students didn’t need the code on beamer 😉

So, that’s it for now.

So Long, and Thanks for All the Fish

the LaTeX Ninja

# References

1. Martin Krengel, Bestnote. Lernerfolg verdoppeln, Prüfungsangst halbieren. Berlin 2012.
2. 10 Tips for College Students, Steve Pavlina
3. Steve Pavlina, Do it now

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# Typesetting Code in LaTeX

Since I recently pulled a few all-nighters to prepare code slides to teach my students R and they were less than enthusiastic, I thought I’d use the opportunity to at least write up a post on how to display code in LaTeX for you guys. It focuses on displaying the code for teaching, writing tutorials and so on. So the integration of code in beamer will be dominant, or at least the example on which I demonstrate things. Of course, you can also use the tips to just display it in a ‘normal’ document.

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 😉  You can find the example document here on Overleaf. It uses the beautiful metropolis beamer theme, which is worth looking into as well.

## The \texttt{} command

This one isn’t a verbatim way to express code, but it will change the font to typewriter, so it ‘looks like code’. However, in these short bits of code, you will have to use escape sequences for reserved characters. Furthermore, it (shockingly!) is not natively included in beamer, so you have to add it yourself in the preamble if you want it (as demonstrated in the template). How can one write about code without over-using \texttt{}?

I make massive use of \texttt{} when ‘talking’ about code or, you know, writing explanatory text sequences. It is especially useful for bits of code where there is no excessive (or none at all) use of escape sequences. Then it is a really handy way to quickly typeset code. Once you have lots of reserved characters, you might be better of just using this next one.

## The verbatim environment

This one really is a staple and pretty failsafe, but also doesn’t have code highlighting which you might want in most cases, apart from very short bits of code where highlighting isn’t important.

You can use verbatim as an environment for multiple lines of code which appear like a quote as a separate block in your text. In other cases, where you just want \texttt{} but without having to escape reserved characters, you might want to use the \verb|some code| command. You can use any characters as delimiters to denote beginng and end of code. To be more precise, a quote from the Overleaf site: “Any character, except letters and *, can be used as delimiter. ” So it can also be \verb+test+. The idea is that you can choose one which you will not need inside the code, as not to ‘confuse’ the enviroment.

## A note about code in beamer

When you use code in beamer, make sure to always use the fragile option for the frames in question. This is necessary due to the way how beamer handles verbatim, apparently.

Also, beamer and code can generally can wreck quite some havoc. I have had problems with lots of KnitR where it would stop working for no reason, then the exact same code would work again later, etc. And there are lots of conflicts and bugs you need to know about. So if you run into problems here, don’t blame yourself. It might easily be beamer which is ‘responsible’ for some of the problems.

## The lstlisting package

You can just use the lstlisting environment without configuring anything but then again, it will not have code highlighting which is kind of the point in typesetting code (most times at least).

However, I find that without setting your own colours for the listings, it still looks quite boring with the black and white hightlighting (bold vs. non-bold). You can configure it any way you like, can even define yourself which elements are to be hightlighted and how. But it is quite a lot of work if there isn’t something you like out of the box. I personally prefer minted and especially tcblisting – that is minted with tcolorbox (as far as I know, even though it’s called listing). It has these cute little boxes. I like boxes.

## Using KnitR

When using knitr to run R in LaTeX, don’t forget to change the file extension from .tex to .Rtex so LaTeX gets a heads up that you want to use KnitR. Otherwise you’ll end up with jumbled code and might spend hours trying to find the mistake, since it isn’t actually in your code. (Just so you know, I speak from experience here 😉 It’s just so easy to forget to do this. Basically happens to me all the time…)

You can use KnitR out of the box on Overleaf. Note, however, that they might not have all the packages you might want. But if, like me, you just want to display code to teach coding, you can eval=FALSE the results (which will be error messages due to lacking packages) and let the students run the code themselves. Since my elaborated fancy didactical plan was not to share the code as a file but rather have them type it themselves from the presentations, to increase the learning effect. Disclaimer: It did not work out the way I had hoped it would 😉

## The minted package

If you like fancy, minted probably is for you. It’s kind of like lstlisting but with more beautiful colours and preset options. Give it a try. It’s probably the go-to solution.

## Minted and tcblistings

tcblistings use minted and tcolorbox to create highlighted code listings in cute boxes. For me, that’s just too good to be true 😉 Note, however, that Beamer, tcblisting and enumitem are not compatible with each other. There is a bug I haven’t yet found a way around. So you can’t use customized enumerates oder itemize in the same presentation as these code listings! Sad, but true. But maybe there is a not-all-that-inconveniant way for you to keep presentation and code parts in separate sets of slides anyway. Here, it’s on you to get creative 😉

Generally, with the beamer package, there are actually quite a few things which don’t work once you want to use some less common features. So in case you encounter a bug and really can’t see how it’s your fault, web search if it’s a common error or known bug. Maybe there will be a way around it, maybe there won’t.

A workaround for this specific case would be to use beamer with lstlisting.

### Wrapup

So, I hope this helped you and provided you with  an overview of possible ways of typesetting code in LaTeX, with a focus on presentations.

Best, the Ninja

## Resources

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# Two basic image manipulation life-savers

In this post, I wanted to share a few tricks for simple image manipulation (with the goal of making pictures look better) I’ve picked up over the years. While tip one will always be to learn to take better pictures, maybe these little tricks will help you when you are asked to put the latest conference pictures online and realize they’re not good and really need a makeover first. So one thing will be to beautify event photos. Another tip I share is how to easily create a nice little vector graphic from a photo of some historical object or person.

## First things first

This might seem obvious, but make sure you only use images you actually have the right to use. Check explicitly, don’t just assume! Get written permisson, if it’s not 100% clear what your rights are. If you are supposed to take pictures for an event, most people now mention that pictures will be taken in the event invitation already and that by attending, you agree to have your picture taken. Check what practices are at your institution.

Secondly, I am not a graphic designer or anything and fully self-taught in this realm. These tips work well for me and might work for you too. But just to make sure: I’m not actually competent to teach anyone on this topic 😉

## Vector graphic from photo

I want to give you a few tips on how to create a nice vector graphic from a historical photo. Vector graphics make for nice logos, for example. Adding one can be all the spicing up a simple template or poster needs. It’s an eye catcher. They take a while to make if you want a good one (a few hours), but can be done on a train ride or during a meeting 😉 and I’ve never regretted making one and people loved them. Even though I’m not a professional logo / graphic designer and my results are far from perfect.

### How to go about it

Scan very high quality if the image is from a book. Or take a high quality photo, reducing background elements if possible (will save lots of time later). Get rid of noise (Gaussian blur, 10px or something, try it). Then vectorize it, for example using Vectorizer.io: they will let you do quite enough if you sign up for a free account and disable your adblock. You can’t do very many images at the same time but since you’ll have other image manipulation taks to do in between, this will be just fine. Of if you’re pressed, use a trial account.  Or do Vectorization.org. I also like the Imaengine app. But you can only save the results when you pay a few bucks for the full version (worth it though). In this case, save it high quality. But maybe also get back to Imaengine only after you’ve cleaned out background elements you don’t need to add final touches. Play around with reducing the number of colour or adding some blur. But reducing the number of colours basically is the main thing you want to do. Maybe start with the smallest possible number of colours and go back up until you think you got the “feel” of the original image back, but without the details. (For example, with just two colours, you’re likely to have lost the original “feel”.)

Then the work starts: Manually get rid of patchy sections as well as all the background in GIMP. It will look a lot better and way more professional if you just take the time to do this (even if it’s not perfectly done). This is where you can invest the 1-2 hours I mentioned this would take. As I said, I am by no means an expert but I feel that most image manipulation things just take a lot of time and effort – they aren’t necessarily difficult to do. So even a beginner can achieve an ok result if they’re just willing to put in the time.

Edit: For getting rid of the background, you could also use services like Remove.bg to speed things up, as was pointed out thankfully by the #TeXLaTeX community on Twitter. It works super well with many types of photos. However, with my early modern print thingy, it didn’t know what the foreground was supposed to be: “Please select an image with a somewhat clear distinction between foreground and background. For instance, try a photo of a person, product, animal, car or another object.”

Manually drawing on the computer in an image manipulation program is not everybody’s thing an might take some getting used to. Many people will want to use a mouse for this. Don’t get discouraged by initial failures. It still is a question of practice and routine. You will, however, be able to get instantly better and more failsafe results if your base image is fairly big and you zoom in very closely. Start with baby steps. It will get easier once the most patchy areas are gone. Once you’re done, run it through the vectorizer once again to get rid of some of the small patchiness you might have overlooked or created while manually drawing around.

Delete the background. This can be done in multiple ways. If it’s all done in the same color, there is the option ‘color to transparency’ (or something like that). Else you might want to use the wand too and click delete or the like. Save (=export) the result. Voilà, your vector graphic is done.

### Some more tips

1. To take into account: If the logo is supposed to be displayed very small, be sure to reduce a lot of detail. Always opt for 30% less detail than you think you need.
2. Maybe make multiple logos or draw stuff on paper. Multiple quick sketches always yield better results than trying to get it perfect the first time. Fail fast and learn from your failures.
3. Another win when using vectors is that you can output them as SVG or enlarge their size without things getting pixely. This might also be a reason you want to create a vector graphic in the first place.

### Summary of a few GIMP shortcuts (learn some to significantly speed things up)

• O = get the color (click)
• P = switch to pencil
• CTRL + C: copy
• CTRL + V: past
• CTRL + SHIFT + V: paste as new image
• CTRL + SHIFT + E: export as (this is the ‘saving option’ in GIMP which will save the actual product, not the project itself – ‘save’ will save the project).
• CTRL+Z to undo
• paste (CTRL+V)

## Beautifying event photographs

### Use the GIMP Retinex filter

From my research into the retinex filter you should only change the bottom-most setting to adapt the filter. The stronger you make it, the less natural the result, the more noise will be created, the more colours will be enhanced.

Usually, the point will come quickly where you crank up the colours and sharpness too much so the result looks weird and gets a “steely” feel (try it out to see what I mean).

For more or less failsafe use of this if you want to achieve results that still look more or less natural: use the filter, then copy the product (CTRL+C). CTRL+Z to undo the effect in the base image. Then paste (CTRL+V) the version with the filter on top of the now reverted to its initial state image. Open the layer editor, click right: make the pasted section as a new layer. Then scale down the manipulated layer’s transparency to 50% (or as you like). The original picture will be improved without looking all unnatural. And you won’t have to take a lot of time looking for the perfect retinex setting. Just take one that looks ok. With the overlay, details will get lost anyway. And by the way, retinex will always create noise. The default settings reduce this to a minimum but it’s still pretty noticeable. So maybe use a relatively fine-grained Gaussian blur afterwards to make up for it again.

And maybe combine the effect with the “three layer trick” explained below. Play around with it. Find something that works for you. I’m no expert either but I found these tricks quite useful.

### The three layer trick to bring out colours and contrast

Copy your initial picture into three layers. Desaturate the first to grayscale and invert it. Then do a light Gaussian blur on it, set its transparency to 30-35% and ‘merge down’. Then (you’re ‘on’ the middle layer now) set this layer’s mode from ‘Normal’ to ‘grain merge’ (‘Faser mischen’ in German), then merge down. This will bring out colours and contrasts better. However, if the colours are not nice to begin with, they will just be intensified as if you’d cranked up the saturation too much.

If this is no good, mabye try the retinex filter to bring out the colours and sharpen instead. I found this three layer trick on the internet somewhere in the past and sadly, can’t find it anymore. If you accidentally happen to know the source, feel free to point it out to me 😉

Other things you could do to enhance your images would be to tamper with the white balance or colour curves. But I decided not to add other stuff here to keep it simple and actionable.

### Very basic ‘mini’ retouch for dummies

Select the eyes and increse colour and contrast. Select the skin regions where there are no lines (like the nose, elbow pit on the arm, etc.) and blur them – either manually or with the blur ‘pencil’. This will smoothen out impefections. Don’t overdo it though or it will be very noticeable. Don’t smooth over lines or the result will look comical at best.

### The best image manipulation is taking better pictures in the first place

But, the most important thing is: Try to get hold of a good camera and take pictures in good light. I personally find it easy to take good pictures when the light is good but when you would need flash, human beings always look bad. At least if you don’t have a clue what you’re doing. So I try to avoid situations where flash is necessary when taking pictures of people. Maybe other people are better at this. But if people are not wearning tons of foundation and powder to mattify their skin, flash is not advisable and you might get better people pictures without it.

Also, ever wondered why models spend so much time on makeup before photoshoots?That’s because image manipulation can only do so much. The better the pictures you start out with, the better the result.

## Conclusion

So, these were some simple tips. I’m not really good at this myself but I’ve been doing it for a few years. These little tips have helped me in situations where, for example, I was asked to beautify some snapshots of the last conference. My experience is that your suffering will be minimized when you have good light and can bring a good camera. This is the most important part. “Repairing” pictures taken under bad circumstances and making them look good is a really hard task. But making mediocre shots a little better is something you can learn. But then again, if you only need small pictures for social media, phone apps offer filters to improve your pictures with a few clicks. So maybe it’s not even relevant for you to “go traditional” and use GIMP at all.

Hope this helps someone,

best,

the Ninja

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# Hipster CV – A Template

Dear all,

sorry you haven’t been hearing from me so much lately. It’s been quite busy. To make it up to you, I wanted to share my hipster CV template on this occasion 😉 I will probably explain it later and also probably modify it in a way that it’s easiert to use for a beginner. If you want to use it and but don’t feel comfortable with how the template works, just check where the text you are looking to replace is in the main.tex and replace it with your content. That way, you should get away with fairly limited LaTeX skills and still be able to use the template if you want it.

It is available on the newly created LaTeX Ninja Github! The template is not exactly the same as shown in the Teaser: LaTeX Resumé Template Preview.

So you can look forward to more versions which will be kind of the same style. But I now have so many different elements that I could fill at least 10 different CV templates. Since I didn’t want to fall victim to my own perfectionism, I dedided to share the template now even though it could probably be better. It also doesn’t really comply with my own standards regarding good code, etc. 😉 Well, you can’t always have it all.

It is, however, more of a Saturday afternoon fun thing I did. I won’t give any recommendations as to whether it will be considered as appropriate in your field of work to actually use this CV 😉

Also, I hope I am allowed to have the Jack Sparrow images in the example. I am not so sure about it however. Come visit me in prison if this should go wrong 😉

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# XML to LaTeX (simple)

Today, I wanted to share this super simple XML to LaTeX tutorial. Using XSLT, you are going to transform XML data to LaTeX output which you can then go on to compile into your desired output PDF. There will be no fancy stuff whatsoever in this post, just the basics and what to keep in mind with these transformations. It is the quick intro to XML to LaTeX I did with my students a while ago which was done one day after they had their first contact with XSLT, so it should really be beginner-friendly. I labeled it “Advanced LaTeX” anyway because I think starting to automate things is always a step in the right direction 😉

## Configuring the transformation scenario in Oxygen

I am going to assume you use Oxygen now because that’s what a lot of people in the DH do and this post is directed towards my friends in the DH. Especially those who think print editions are an obsolete concept in times of the Digital Edition. Maybe having a nice little intro to XML to LaTeX transformations available will change their minds 😉

To set up the transformation scenario, choose XML transformation using XSLT, then choose your XML document and your XSL stylesheet (set up and open those document in the editor before you configure the scenario). Then choose a Saxon 9 version (whichever you like). Then ignore the FO tab and get right to the output tab.

Here you configure how to name your output. Best click the green arrow and choose cfn, then append -latex.tex. So the result the current filename with -latex.tex appended to it. This is an important step so you don’t accidentally overwrite the original. Which in this case is not so dramatic since it has a different ending anyway but if you do XML to XML transformations, this is even more crucial. Then tell Oxygen to show it in the editor as XML (even though you know it isn’t). The editor will then, of course, complain about the non-valid XML but don’t worry. Just copy all (CTRL+ACTRL+C) and paste it (CTRL+V) into a completely empty (!) project in Overleaf  or just compile the LaTeX directly if you have it installed on your machine.

There it is, you’re set. Now let’s get to the stylesheet.

## The stylesheet

So, this is the whole thing. You can just grab it and go if you don’t care for the explanation or read on to find out why things were done the way they were done. This tutorial assumes you’re already familiar with how XSLT works, just haven’t done transformations to LaTeX yet, by the way. I am also assuming, your base XML is in the TEI standard.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema"     xmlns:t="http://www.tei-c.org/ns/1.0"     exclude-result-prefixes="xs"     version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="text" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>

<xsl:template match="/">
<xsl:text>\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\DeclareUnicodeCharacter{2060}{\nolinebreak} % might not be necessary for you

\title{</xsl:text><xsl:apply-templates select="//t:title"/>
<xsl:text>}
\author{</xsl:text><xsl:apply-templates select="//t:author"/>
<xsl:text>}\date{\today}
\begin{document}
\maketitle
\tableofcontents\newpage</xsl:text>
<xsl:text>\begin{itemize}</xsl:text>
<xsl:text>\item </xsl:text>
<xsl:value-of select="." />
<xsl:text>

</xsl:text>
</xsl:for-each>
<xsl:text>\end{itemize}
\newpage</xsl:text>

<!--  <xsl:apply-templates/> OR -->
<xsl:apply-templates select="//t:text"/>
<!-- just use the pull paradigm on the TEI body so you don't get a meaningless TEI header dump in your document -->

<xsl:text>\end{document}</xsl:text>
</xsl:template>

<xsl:text>\section{</xsl:text><xsl:apply-templates/><xsl:text>} </xsl:text>
</xsl:template>

<xsl:template match="t:p">
<xsl:apply-templates/>
<xsl:text>

</xsl:text>
</xsl:template>

<xsl:template match="t:hi">
<xsl:text>\emph{</xsl:text><xsl:apply-templates/><xsl:text>} </xsl:text>
</xsl:template>

<xsl:template match="text()">
<xsl:analyze-string select="." regex="([&amp;])|([_])|([$])"> <xsl:matching-substring> <xsl:choose> <xsl:when test="regex-group(1)"> <xsl:text>\&amp;</xsl:text> </xsl:when> <xsl:when test="regex-group(2)"> <xsl:text>\_</xsl:text> </xsl:when> <xsl:when test="regex-group(3)"> <xsl:text>\$</xsl:text>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>

</xsl:stylesheet>


### The XSLT declaration and the LaTeX preamble

Put the following after your XML declaration. This will ensure output is LaTeX-friendly.

<xsl:strip-space elements="*"/> <!-- for LaTeX -->
<xsl:output method="text" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>


\DeclareUnicodeCharacter{2060}{\nolinebreak} was added because LaTeX complained about an undefined character in some of my students XML data. Personally, I had never gotten this error before, so you might as well leave it out.

### Creating environments

As we had just learnt some XSLT basics, I wanted the students to use at least one push and one pull paradigm type template. So the task was to process any element from the TEI header using the push paradigm and then a pull paradigm template for the body. To make this little template more efficient teaching-wise, I decided to introduce how to create a LaTeX environment using XSLT for the TEI Header / push paradigm and do at least one other command using the pull paradigm on the TEI body. Also this demonstrates as opposed to for the body.

So this next piece of code sets up an itemize environment for persons present in the header. In a “real” stylesheet, it would probably be more wise to check, using whether there is one potential element like that present and only paste the \begin and \end on that condition.

Also, as you might have noticed, all the LaTeX commands are inside . This looks a bit confusing at first but really isn’t. Just make sure you don’t create invalid XSLT by shuffling them around.

<xsl:text>\begin{itemize}</xsl:text>
<xsl:text>\item </xsl:text>
<xsl:value-of select="." />
<xsl:text>

</xsl:text>
</xsl:for-each>
<xsl:text>\end{itemize}</xsl:text>


When creating simple commands using the pull paradigm, be sure that you don’t end up with too many “overlaps” since “simple” commands in LaTeX don’t take multiple paragraphs as arguments. If in doubt, always use environment and the global switches (like \bfseries). Since you are automating things, you always have to take into account that data might not always be marked-up in a way which makes sense to you. There can easily be linebreaks inside a single italic highlight. If this is the case in you data, better create an environment. For simple purposes, however, this is good enough:


<xsl:template match="t:hi"><xsl:text>
\emph{</xsl:text><xsl:apply-templates/><xsl:text>} <xsl:text></xsl:template>


With these commands (and genereally when transforming to LaTeX), you sometimes need to make sure you don’t involuntarily add spaces or lack space which will make the output hard to read and debug.

In this example, I made sure not to add any whitespace inside the template rule and also did not have Oxygen format or indent the XML to avoid these unwanted spaces.

### And finally: Escaping entities

As you might remember, markup languages tend to use entities to escape certain characters. Bad thing is, LaTeX and XML use different entities. So we need to escape them. I know that the OxGarage standard stylesheet does this using the translate() function but I prefer to use since it’s less “messy” than a nested translate() construct.

Ah, and side info by the way: There is this standard stylesheet from the TEI consortium which might be of help if you are looking for inspiration. Since it is very generic, however, it might not be helpful if you are a newbie at both XSLT and LaTeX. The XSLT is pretty advanced and also the LaTeX probably uses some commands you might not be aware of.

    <xsl:template match="text()">
<xsl:analyze-string select="." regex="([&amp;])|([_])|([$])"> <xsl:matching-substring> <xsl:choose> <xsl:when test="regex-group(1)"> <xsl:text>\&amp;</xsl:text> </xsl:when> <xsl:when test="regex-group(2)"> <xsl:text>\_</xsl:text> </xsl:when> <xsl:when test="regex-group(3)"> <xsl:text>\$</xsl:text>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>


And that’s it. I hope this was useful to you.

Cheers,

the Ninja

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# A Humanities’ seminar paper with LaTeX – in 10 minutes

Don’t believe me when I claim you could write a whole seminar paper in 10 minutes? I wouldn’t either 😉 But I firmly believe you can learn how to write the next one in LaTeX in just ten minutes, so I prepared this pretty self-explanatory document. Everything is explained there, so I won’t ramble on about it here. The document is here on Overleaf as a template. There you go.

Little side note, in case you are completely new to LaTeX. Like in the picture below, LaTeX has source code (on the left) and the compiled output PDF on the right. If you mess up the source code, there might not be any ouput. Using CTRL+S will cause the Overleaf editor to try and compile automatically. You can download the resulting PDF by clicking on the symbol beside the ‘recompile’ button. Overleaf also provides info on how to use Overleaf.

So, that’s it with a very short post for today. Watch out for the upcoming “(Why) Should I use LaTeX for my PhD thesis” post!

So long and thanks for all the fish!

The Ninja

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!

€3.00

# The power of simplicity, or: How to use tutorials

This is just a quick post, telling you to use tutorials selectively. If you don’t have time, don’t burden yourself with the not-so-short intro to LaTeX or 30 min introductions. Jumpstart in 3 minutes and go.

This morning, I realized one thing: depending on what you want to do with LaTeX, you only need a very limited amount of commands. Even I use a very limited amout of commands for everyday tasks. Going through a whole tutorial might actually be a waste of time for you.

## You only need 3-5 go-to commands

What you always need (and, for example, an Overleaf blank document already supplies): You will typically need the general document setup (minimal example), \newpage, \maketitle, \tableofcontents, and \sections and \emph{}.

For teaching documents, I will additionally need \textbf{boldface}, enumerate and itemize environments. Then maybe \href{http://latex-ninja.com}{links} (\usepackage{hyperref}), \texttt{typeface} for code or the verbatim environment. And, of course, I often use my cheatsheet template.

For writing scientific articles, I will need bibliographic citation (biblatex), mostly using \footcite{} and \footnote{}. Then maybe sometimes the quote environment for longer quotes. Then a Pandoc conversion to .docx (see the post on how to quit MS Word).

But that’s basically it. The more complicated stuff I use only when I have real typesetting needs or do something overly visual. That’s how I managed to use LaTeX for 5+ years without going any deeper.

## The power of simplicity

What I want to say with this is: You don’t need to learn all the concepts to get started. You won’t be able to use all of them anyway. Only learn the ones you need right now to get going. Learn the rest as you go.

30 minute (or longer) introductions to LaTeX are great, but depending on your needs (especially if your a Humanities person who never uses any math or the like), you don’t need to go through complicated tutorials. Just starting  using LaTeX and add skills as you go.

LaTeX is supposed to have “a high learning curve” and take way more time than just using Word. People often say that if you’re not interested in typesetting technical stuff, there is no point in learning “complicated LaTeX”, but LaTeX is not complicated. Not unless you have complicated needs, then it is adequate. Especially if you’re a Humanities scholar – be happy that you can enjoy excellent typesetting without learning the more complicated technical parts of LaTeX. Once you’re used to the general gist, you can add the more fancy features without stress.

Don’t let listings of commands scare you away – you probaby won’t need them and, most importantly, you don’t need to remember them now. You probably don’t even need to know of their existence. If you have a problem, just type "latex how to [...]" in Google and you’ll most certainly find help. Or drop me a note, I’m always happy to help.

So, that’s all I wanted to say for now.

Cheers,

the LaTeX Ninja