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.

code-listings1
Be sure to check out the template on Overleaf.

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

Buy me coffee!

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

€3.00

Advertisements

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.

tikzposter-with-timeline
A TikZ poster for the exhibit “Lyrik des Widerstands – Richard Zach zum Gedenken”, PH Steiermark / Graz / Austria. It illustrates what I mean by “a nice vector graphic can go a long way”. At least I hope it does.

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.

maierus
This image is a direct result of a vectorization tool and now you probably understand why we need the manual labour. The simplicity of the end result is the result of lots of work. But tweaking the vector output can help, too. This was made from a scan of an engraving depicting the early modern iatrochemist Michael Maier.

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.

maierus3
After you’re finally done with the manual editing done and marvel at your finished vector graphic, you’ll be so relieved you’ll start making pop art out of it. Believe me, I know what I’m talking about 😉 Oh, those train rides…

 

 

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.

retinex-filter3
With retinex, adjust only the bottom-most option “dynamic”.

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).

 

retinex-filter2
Overdone retinex. Colours ruined. “Steely” feel.

 

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.

both-filters
Left: initial image. Not bad, but I’m not happy because these wooden rooms always give nasty light. Right: image after having used both techinques explained above. First the three layer trick, then retinex. The result is not much different in the way that it looks “obviously manipulated”, but it does kind of look better and more professional, I feel.

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

 

Buy me coffee!

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

€3.00

Don’t call it a database!

When I started this blog, one of my promises and goals, apart from LaTeX-Ninja’ing, was to demystify the Digital Humanities for non-DH people. For a long time I have watched and I think one of the big mysteries of the DH still persists in Normal Humanists’ heads and thus, really needs demystifying. You might have guessed it, I want to explain why DH people will cringe if you call digital resources ‘databases’ which are not, technically speaking, databases.

Is it ok to call any digital resource / corpus a ‘database’?

We know, that’s what you tend to call a digital corpus. But in most cases it’s not correct, it’s a pars pro toto. A database is just one possible technical implementation, but the term is used more broadly for any ‘digital base of data’. By laypeople, at least. A pars pro toto stylistic device is a Humanities’ thing, right? You do get stilistic devices. So you can also understand why you shouldn’t use imprecise terminology. You don’t like it when people misuse your fields’ terminology either and probably make quite a religion about it.

If you want to work with the DH, you need to understand their terminology and respect it by using it correctly. Even though it might initially feel unintuitive to you. Believe me, you will adapt quickly if you give it a try.

I’ve caught myself so many times now, educating my Normal Humanist friends about digital resources and why my (DH) colleagues won’t take you, as a Humanist, very seriously if the word “database” slips out your mouth at inappropriate moments. It’s kind of like the Tourette’s of NH-moving-in-a-DH-world. Which probably is not a politically correct analogy. No offense to people who actually have Tourette’s, I don’t want to devalue or disrespect your struggle in any way! It’s just analogical in the way of spluttering out inappropriate words at inappropriate moments.

Everybody has their cringe-prone terminology item, right?

To be honest, I am not sure how strict the English speaking DH world is in this, but I can guarantee you that this distinction is very valid concerning the German language use of “Datenbank”. When a quick web search yielded this result, I wasn’t sure anymore if it’s actually a thing in English too. Digital Humanities at King’s College define a database as follows:

Database is the term we use for any large collection of online material.

( https://libguides.kcl.ac.uk/dighum/dighumdbase )

This, however, is exactly the way I don’t suggest you use this term. I am aware that this is the association linked with it in many people’s minds. But hey, you are Humanists. You do have a sense for the intricacies of terminologies, right? I, for one, really hate it when people use the wrong gender on the term corpus (in German: neutral (!) for a collection of documents, so always neutral, unless you mean an actual body like that of a musical instrument). You probably have a thing like that, too, where you get furious at laypeople saying it wrong, don’t you? Well, the DH equivalent of this thing is the misuse of the term database.

Using terminology correctly is a sign of respect towards the DH community. It shows you respect us as researchers and don’t think of us as the ‘idiot who does the tech stuff’

Well, to be exact, it’s not even a misuse. You sure can use the term database in this way and it’s not, strictly speaking, completely incorrect. It’s just misleading, and – most importantly as the subject of this post – it is a strong pointer to the fact that you are not very tech-savvy and either unaware or else disrespectful of digital terminology. It will be seen as either a lack of respect and esteem towards the digital field or, I don’t know which is worse, a lack of competence in general. You would deem it impolite, too, and probably take it as a sign of general incompetence or lack of intellecutal ability/openness  if a DH person came along and persistently misused your terminology, right?

Edit/addition 2019/06/04: I think this issue is less about whether it is technically or theoretically correct to use a term like this or like that. It’s a question of being ‘politically correct’ and of not hurting people’s feelings. To show the point on an extreme example (which is maybe exaggerated applied to databases but illustrates the point): you could theoretically argue that the term ‘nigger’ has been used historically to mean ‘person of color’, ergo it would – terminologically speaking – not be incorrect to use it, right? Wrong. In this case, it’s obvious (to everyone, hopefully) that it would be extremely rude and not ok to call a person of color a ‘nigger’ nowadays. Nobody would be confused if people’s reaction to this was to feel insulted because the above explanation does not take connotations into account.

Like you could say that before the advent of the DH, it maybe wasn’t a big deal to throw around the term ‘database’ to mean any digital ‘base of data’, but since the DH is starting to be established as a discipline and not only as a tool like it might have been in the beginning, things have changed. DH people sometimes feel like their competencies are not taken seriously because their part of the job is seen as the ‘handiwork’ whereas the non-DH input data is the actual research. I think that this latent inferiority complex, or maybe rather some sort of struggle for recognition, is the reason non-precise use of DH-related terminology is sometimes taken bitterly.

So ultimately, it’s not about being right or wrong. It’s about being respectful and not hurting other people’s feelings. Also, non-DH people insisting on using the term in a non-DH way while simultaneously wanting to participate in a DH project will cause a clash of terminology. It might be ok for a non-DH person to use the term like this, but DH people are kind of bound to use the term in a strictly technical way or else they might be seen as incompetent of their own field. In this case, I think the non-DH person should give in because even when they will not be judged by their use of DH-specific terminology, a DH person will. You don’t want your imprecise language to reflect negatively on your cooperation partners.

Since the initial publication of the post, I received the feedback that some people with technical backgrounds are quite open to non-technical uses of the term ‘database’. But from my own experience of the DH overall, I feel this is not necessarily representative. And only because people will accept that it is theoretically valid to use the term to one’s own judgement, that doesn’t mean people will condone it in practice.

If you want collaboration, start actually collaborating by learning about DH terminology

Especially if you are trying to get a collaboration DH or label DH project, I suggest you prune your language a little bit here. After all, DH people usually have lots of people queueing to get a project with them. They will tend to take the ones interesting for them (in terms of subject) and/or those where the applicants seem nice. And it is deemed base politness to research your collaboration partners’ field so you don’t draw a complete blank. You want your partners to be understanding and reasonably well-educated on the baseline of your field too, right? And you probably catch yourself sometimes, secretly saying to yourself in indignation or disbelief ‘How can any academic not know that?! This is completely basic!’

Well, it happens to DH people, too. Often concerning so-called ‘databases’ which are not, in fact, databases. If you persistently use the term wrong, it’s seen as lack for trying or plain incompetence. Don’t be rude. Now you are aware of the problem, you have no excuse to continue saying it wrong.

How to know if it’s ok to call it a database?

Two questions to ask to get a feel for whether what you mean might actually be a database:

  1. Would it make sense to represent this data in an (Excel) spreadsheet? Then it is likely someone chose a database format to represent it digitally.
  2. Are there any other fitting means to represent it? Only because it outwardly looks like it stores spreadsheet-formatted data, this doesn’t mean it’s they way data is stored “behind the scenes”.
  3. In case of any doubt whatsoever, just refrain from calling it database. Just say ‘digital resource’, ‘digital corpus’ or basically anything else which seems half appropriate. Anything else is way less stigmatized and cringe-worthy than the misuse of ‘database’.
  4. So to be on the safe side: Just don’t call it a database unless you’re sure it is one (technically speaking). When not 100% sure, just term it a digital resource or digital data collection. I know you just mean a ‘digital base of data’. But please respect that the wide category ‘digital base of data’ doesn’t mean the same thing as the narrow term of ‘database’ in a technical field.

Just a little thought – hope this helps!

Best,

the Ninja

PS: Can someone tell me whether you think it is valid to inform people they should not use the term database or would it be ok with you when they use the term in a non-technical way? I only know that people around me react quite aggressively when you do and will think you’re a technical layperson, thus not trust you much once you did. You’d basically be ‘disqualified’ after that unless you really have some very interesting other assets or extremely good grant acquisition records or splendid networking connection value.

 

Buy me coffee!

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

€3.00

How to improve at programming when your current position doesn’t require it & Online Learning Resources

Have you ever felt like you would like to get better at programming, maybe even get a position involving more programming some day but the fact that you currently don’t really need it at your current position seems to hold you back? This post is for you.

Daily practice is key for improvement

You need daily practice if you actually want to improve. You already need daily practice just to keep your skills sharp during a time where you don’t need to use them. Also, if you don’t even have programming skills yet, you probably are too tired after work to sit down and work on a private programming project.

But you should. Programming is a skill which takes a long time to learn. That is, if you want to reach a decent skill level. This means that you have to start regular practice long before you actually need that skill or need to apply for a job, if possible.

The common advice: Find a starting out project to program in your free time

When I first informed myself on this, the most common advice was to find a cool project and try to program it in your free time. But I found that when you don’t have an idea for such a project which makes complete sense to you, you’re not going to go through with it. Without an acutal, urgent need you probably won’t sit down the amount of hours necessary to actually make progress. At least the great majority of people wouldn’t.

Then I tried setting myself mini-challenges. This was a good idea. But there wasn’t a lot of guidance (obviously). This, in return, was discouraging and wasted a lot of time. Of course, time well spent learning something. But since I am really interested in effective learning, I felt that I was wasting time. Effective learning is always better than just playing around. You need curriculum. At least some. That’s when I found out that there are a lot of competitive programming sites which offer useful short exercises where you can do one per day.

Before that, I had tried all sorts of “Learn programing” sites like SoloLearn, freeCodeCamp, the Enki app, just to name a few of my favourites. But really, I didn’t like them all that much. They went through the syntax of the language and that was it. Like learning the vocabulary of a living language but never using it.

Review of some of the materials out there

Here, I want to share links to all sorts of learn coding sites out there. Of course, it’s not extensive but I think it does cover a good few of the most important ones. And maybe has a bit of a different perspective from most other “here are 30 sites to learn coding for free” blog posts out there.

A constraint for me was that the site had to be completely free of charge. So, for example, DataCamp is a no-go. Although, I have still linked to some pay-sites in case you are interested.

But especially as there are so many pages where you can get a similar service for free, I don’t see why I should pay for one of them, when there are so many alternatives available. If it were really brilliant, I would probably pay for it, in theory. Like HackerRank, I like so much at the moment, that I would probably get access for a one-time payment. But most of those apps and sites ask for monthly payment of up to or even starting at 10€ – that is a crazy amount of money and you already get books starting from 10€. I personally would always put more trust in a book in terms of quality and the hope that there might be a logical progression to the teaching; and thus, rather go for that. Also, I just don’t do monthly subscriptions. They eat so much of your money and mostly, when you sum it all up, are not really worth it. 

Also, the amount of sites (plus all the apps!) out there has become so huge, it’s really a full-time job to check them all. That time might be better invested in just picking one and learning to code. These other sites that I found initially focused more on interview prep for experienced programmers or programming contests, but many of them have actually developped training tracks. They also tend to offer a broader range of subjects than many other very popular sites which focus on web development (“coding”) mainly.

Enki app

I had liked the Enki apps daily workouts, but the learning progression was not stable. They give you a random tutorial every day. This was not very effective and I quickly was through with all of their material. Ergo, the workouts started repeating very quickly.  For more, you would now have to pay monthly for access which I am not willing to do since learning-wise, it is not sooo well done. It was really good for a free site (for a while I used it a lot), but not good enough to be paying for it. Sadly, I have experienced this with most of the sites I have tried (and I have tried quite many).

App-wise, you will just get the Enki review here. I tried probably all the most important apps out there. But mostly, in their way of just explaining the syntax of a language, the progress was slow and it was ineffective for me who already knew most of the syntax. You usually can’t skip much or speed up if you’re getting bored. Still you never get any actual programming done which I found both useless and frustrating. Having tried all the apps and “learn the syntax of XY” (disguised as “Learn programming language XY” which is not the same thing, in my opinion), I now found competitive programming sites to be more what I had been looking for. 

Some of them don’t have all the languages you might want, especially the smaller ones and the web dev focused ones.

 

General-purpose learning sites (video-based, MOOCs, etc.)

Many popular sites (Coursera, Udemy, Udacity, Khan Academy, MOOCS like edx, OpenMIT) are video-based and I don’t personally like that. I prefer interactive sites where you can type your code directly. But well, now you have the links to those resources as well.

Online books or blog tutorials

Even though I have a tutorial blog myself, I personally would not try to learn a programming language from a blog. Sometimes you find useful posts for a specific problem you need to solve, that’s mainly what they are good for. I just think that the available interactive things are cooler for actually getting programming experience as a novice programmer.

Youtube tutorials or channels

Some posts on free “learn coding” resources recommend Youtube tutorials or channels. This is, I think, a valid point if there really is an excellent tutorial video out for exactly what you want. So, if what you want isn’t uncommon, there is likely to be one. Sometimes a 5min video can save you an hour of reading a tutorial. But I find that hardly any channels offer sensible curriculum for a motivated learner, so I’m not sure how much you would get out of it in the long run. That’s why I won’t recommend any here.

Sites just/mostly teaching the syntax of languages

 

Many of them are gamified as well

Sites I really like for practice / or of the type I like (challenge-based)

Learn the language tracks are available on for example: HackerRank, HackerEarth (teaches algorithms).

With Hackerrank, for example, I really like their testcases. They don’t just ask you to write a solution on your own (sites like SoloLearn, Codecademy hardly do that in their regular curriculum), they also provide testcases where, for example, overflow is bound to occur. So with every single test you are reminded to remember that. This is a good reinforcment method in  teaching, I think 😉 Also, have I mentioned that supposedly, the only thing which really works wonders in teaching is getting tested? So forget about what learning type you are (visual, audio-visual-bla, etc.) and become a tester. You can skip some of the testcases of course, but the frequent reminder still works wonders. Also, you can learn from other users good (high-ranked) solutions. Especially in algorithms, it’s really worth checking how more experienced programmers did it. However, these competitive programming platforms do kind of encourage bad programming style (and dirty hacks to improve speed), so be sure to take care of that yourselves. Be persistent disciplined when it comes to using good style! And remember to still work on bigger projects every once in a while, since the daily practice from these sites is just one single function without context.

Learn Catch the Flag / Hacking

Also, if you’re interesed, these are some sites where you can learn CTF (catch the flag), something like competitive ethical hacking.

Other / Tutorial-based

More tutorial-based sites which are useful but not for the kind of rapid learning I recommend:

Resources

Also, check these other posts on free coding resources:

 

Buy me coffee!

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

€3.00

Your 24 hours. Time management or How to get to know yourself while organizing your life. Part II

Today, I am yet again happy to present the second part of the latest LaTeX Noob guest post:

 

Last time, I told you about four important steps to organizing your life. They were:

  1. Know your priorities.
  2. Learn to say “no”.
  3. Leave your comfort zone.
  4. Never back down.

If you want to re-read the last post, you can find it here!

So, time management.

You will need a calendar, let’s start with that. Take your phone, open your Google calendar. Start. It is actually that easy. You have to know the most important basics. When do I work, what are my main working hours? Do I like a silent or slightly more lively environment for my work? Am I a morning person or a night owl? When will I need a break, when do I want to go to sleep?

When am I meeting my friends, when do I spend time with my partner or my family? What do I do for relaxing? How often? Exercise? Any activities? When and where?

What is there to do on household chores (you know, cooking, cleaning, gardening etc.) and when are they due?

Just write those things down. Think about it. It is creepy at first sight, I know, but hey…

Labyrinth-Girl

I am a morning person, I like to start early with my work.

I love good instrumental or orchestral music during work. I like other people around me while I work, because of the swift “office-noise”.

For relaxing, I like reading, listening to music, going climbing, watching TV, taking long walks, photography, writing, people-stuff (friends and family).

Basic week:

  • 4 work days, Monday to Thursday = 30 hours of work
  • 1 “thesis day” (also called somehow home-office)
  • 1 university course to teach and prepare
  • 4 university courses to attend and prepare
  • one evening to go climbing
  • (at least) one evening to have dinner with my partner

An example week

I will give you my five days of my working week in my calendar now, just as an example and to show you how I work on my organization and how I try to plan my days. You may have got it until now – it is all about your own rhythm: find it, then stick to it.

Monday

7:00 start work

15:00 short coffee break with friends

17:00 back home, dinner

18:15 climbing (1.5 to 2 h)

  • hair day, bathroom cleaning

  • prepare courses

22:00 bedtime

Tuesday

7:00 start work

10:00 Coffee break with colleagues

18:00 back home, dinner

  • washing clothes

  • prepare courses

  • TV/Dinnertime with my partner

22:00 bedtime

Wednesday

7:00 start work

10:00 teach my university class

12:00 lunch with friends

15:15 university course 1

18:45 university course 2

20:30 dinner with colleagues

22:00 back home

23:00 bedtime

Thursday

7:00 start work

13:00 end work

13:30 university course 3

15:00 prepare next course (learning a new language for work)

17:00 university course 4

19:00 back home

22:00 bedtime

Friday

7:00 morning routine

  • Thesis Day

  • kitchen cleaning

  • washing clothes

  • shopping supplies

14:00 lunch with my partner

15:00 beginning of my pre-weekend

Weekend

Normally spend with family and/or friends and /or partner – and sometimes spent with reading texts or papers connected to my research field

Conclusion

So I actually do have some kind of private life, but I have to organize it in a very strict way and I have to be very strict with myself sometimes. I am a morning person and I am in the possession of a “daylight alarm clock” – you know, it starts with deep red light approximately one hour before your actual alarm time and continues getting brighter like the sun rising, so your body can wake up before you actively open your eyes and wake up in your head. It works! At least, for me.

I need my bedtime set earlier now, so around 10 pm I am really grateful for a warm and cozy bed and sleep. I enjoy resting in my bed on the weekend, this is a fact, but it is like a reward I promise to myself.

I am still meeting my friends and I have still a lot of other things to do in my life, things which I enjoy and which are keeping me relaxed and sane.

It’s worth the hard work. You just have to start.

Some thoughts on grading

Grading is always a touchy and emotional subject. When students misbehave, you automatically feel the urge to punish them with a bad grade. When students receive a bad grade, they will be angry and pissed off. And ‘bad grade’ is relative to what they expected, not ‘realistically bad’, like in a fail grade. In most cases, they will also think you are unfair if they honestly expected a better grade. And they will be gradually more pissed off, the more work they put in your class. So make sure you put as much thought into planning your grading scheme as into the rest of the preparation, because the grade might just leave the biggest lasting impression on students looking back.

 

The good student receives bad grade problem

I just cleaned out my old archived data and remembered I had this class with a teacher I really liked. But now, I hardly remembered her. Then I realized it probably had something to do with a weird bad grading situation that had left a sour taste with me.  Also, it happens that situations like this (and I defintely had more than one) were always in the Linguistics department. Anybody who knows me is aware that I am a language nerd, I love dialects, etc. I came to university really looking forward to studying Linguistics. Now I hate it, not because it turned out I disliked the subject but because of many bad grading situations where I felt treated extremely unfairly.

This particular teacher had doted on me during the class. I also loved the subject and participated a lot. Then I handed in the paper, and I don’t remember exactly what the problem was, but she gave me a really bad mark and said I could only turn it into a positive one, if I made major changes. A C, to be exact! Which was as good as a negative mark for a student like me with overall high marks. This would ruin my GPA. But then again, I had such a tight schedule that I couldn’t afford just redoing this class. This whole situation came as a huge shock to me. I felt I had written an ok paper, as far as I was qualified to judge. It was in my fourth semester only, so you probably can’t expect a publication-ready work. It would have been be ok if I had felt I had put in minimal work only and performed badly. But I had honestly really tried to write a good paper. And it’s not like you generally get a lot of help in how that is actually done. I’d given it my all and ended up being treated like an abysmal student who had personally offended the teacher by handing in such a bad paper. Also, once I already knew that the only thing I could do is rework the paper but would still get a grade which would ruin my GPA, I was not exactly super-motivated to put in a lot more good work.

I had seen the papers my colleagues had handed in, they were obviously less good than mine (from formal standards already) and left an obvious impression of having been done carelessly in a haste. I was profoundly shocked. Maybe the teacher had taken to me so much because she had seen herself in me and thus, expected a publication-ready output. The teacher was not very experienced either, so this misconception might have easily happened to her. Since, of course, I was only in my fourth semester, I was not able to deliver that level of high quality she had expected from me and thus, graded me way more strictly than my less good colleagues.

 

If a good student underperforms, ask what went wrong instead of lashing out on them

Dear teachers, something like this happened to me mulitple times and is a surefire way to make your students hate you in retrospective. You don’t want your best students to hate you, right? They will talk badly about you (as I sure did) and ruin your reputation for generations of new students to come! Especially good students will get very angry at less-good-than-expected results since, unlike really bad students, they probably actually care about their grade point average which you just ruined!  Some people’s stipends also rest on this GPA. Don’t be so quick to give out bad marks to students of whom you would have expected more. Try to clarify what the problem was instead of just being angry. That’s just childish. Don’t let students’ outputs scratch on your ego. Students probably really don’t care about you all that much and if they did, they sure don’t have a positive impression anymore now. Maybe it was all a misunderstanding? Especially if you had expected better result, it’s obvious you should investigate what happened.

Beware of thinking a good student is you. Don’t expect your good students to be scientists. They are not, despite their apparent motivations to be come full-blown researchers one day. By ruining their GPA, you actually negatively influence whether they will one day be able to become researchers.

 

On silence and introverts in class

Silence does not mean disinterest, like many teachers assume. It might just be that they’re an introvert. And even though they might have participated in the beginning of the course, stopping later might not mean disinterest. To give a personal example, I often participated very actively in classes I was interested in. But then the teacher focused so much on me that I felt awkward and didn’t want to be the center of attention anymore. Actually I had never wanted or intended to become the center of attention. I therefore stopped participating because being the center of the attention made me feel uncomfortable. This, the teachers usually took as a horrible insult and were furious.

In multiple cases, I ended up with a really bad mark despite knowing (from having seen my colleagues papers) that my work had been well above average, if not even very good. Already formally, my papers were a few classes above those of my colleagues because I had way more experience writing papers than them. These times, I first wanted to complain. But then I was so annoyed that I never talked to the teacher about it. One teacher even told me my paper was an A but they would make it a B because I had stopped participating. I didn’t want to confront them and was ok with a B because, after all, it was true that I had stopped participating and found it to be their good right to take a grade off. A B, after all, would not hurt my GPA in bad ways. Then they put a C in the online system. That was pretty mean, seeing as my paper really was quite good (without being too fond of myself, but I had worked on that particular topic for a long time in another context already). The teacher offered no explanation for this behaviour except being hurt personally and stressed many times how good my contributions had been.

I’m sorry, extroverted teachers. Have you really never thought about the fact that it might be uncomfortable for a good student to be called out to answer questions all the time? It makes your fellow students dislike you. Please don’t take this as an insult and also, definitely don’t base your grading on it! You are scaring away good students. I continue to dislike this particular teacher after years. The lasting impression was extremely negative. This didn’t happen only once either.

 

Grade using check-lists to avoid mixing in personal emotions

I handle the problem of grading by having a check-list with points. So I don’t “grade” or hand out marks – they score on a check-list. That way, I as a person will not be the object of a student’s hatred. A lot of people actually recommend to do grading this way, especially if you’re still young or lack authority for whatever reason. That way, I can act like a mentor and trainer during my (very workshop-style) classes and still be fair in my grading.

Of course, coming up with these check-lists is some work in the beginning but it is very fair, good practice and will save you lots of trouble once complaints come in. And they will at some point. Another technique I find very useful is to ask a lot of the students (greater amounts of portfolio work to be done, in my case), but then am fairly easy on giving out points. That way, they feel like I grade so nicely, but they still have done more work than they would have otherwise, so it’s really ok when they all get very good marks.

Would be happy to hear how you handle these situations,

best,

the Ninja

 

Buy me coffee!

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

€3.00

LaTeX for PhD students

Today, I decided to finally publish some thoughts on why I think PhD students can profit from using LaTeX. In this post, I try to avoid common not-all-that-creative reasons and point you to some aspects you might not yet have thought about like the fact that your PhD thesis will yield two PDF outputs with (more or less) the same content but very distinct different formatting requirements. Enter LaTeX.

1 PhD = 2 (!) print outputs, i.e. thesis print and printed book publication

Typesetting your PhD in LaTeX is a good idea because of the citation management, for formulars and for images. You probably already know that. But another aspect a lot of people tend to forget while writing their PhD thesis is that a thesis will usually result in two different output PDFs with different typesetting needs: The thesis to be handed in at your university and the print publication which follows. But these two usually have some important differences in requirements. Like a thesis print will probably be a4 or letter paper, a font size of 12pt, etc. A print publication almost always has a smaller paper size and thus, a smaller font size. In my case, this was: paperwidth=170mm, paperheight=240mm and 11pt. Where as a4paper is 210:270, as far as I remember. If you take this into account beforehand, you can save yourself a lot of work and trouble. Also, it’s not like you will suddenly have tons of free time in the time after the PhD writing, probably the opposite. You don’t want to make that even harder by placing another unnecessary burden on yourself.

Already here, LaTeX really pays of. Just change two settings. That’s basically less than 10 characters (!) in your main.tex. If you don’t have to make other changes, that is. Well, you get what I mean. Whereas in MS Word, this can be a lot of effort since quotes probably have a different text size and unless you use the “Standard” predefined templates which you can then change, this can take you a while. Also, it probably often happens to people who don’t reflect on the typesetting while writing (which, after all, will occur long after the writing, so we don’t yet give it a lot of thought) that you don’t consistently use those templates and thus, will have to change or at least check everything manually. With LaTeX, you don’t. Isn’t this enough of a point for LaTeX already? But behold, we have more.

 

Typesetting concerns like orphans and widow lines

Another thing for producing nice typesetting: A (respectable) publisher will usually ask you to take care of orphans and widow lines. In a 300 page MS Word document, you will probably end up having to do this all manually which usually entails all sorts of horrible consequences you hadn’t even dreamt about this far. While this problem cannot be fully automated in LaTeX, you have the possibility of adding this simple statement to your preamble:

\setlength{\emergencystretch}{.25em} % avoid line overflow
\clubpenalty10000\widowpenalty10000\displaywidowpenalty=10000% avoid widow lines and orphans

This, supposing that you have included all the languages you use with \usepackage[ngerman,english]{babel} (for example, last one is the one active), will avoid most line overflows.

A problem that you, admittedly don’t have in MS Word but do have in LaTeX. But more important is the following line. There, we add to the internal ‘penalties’ which LaTeX has, thus preventing orphans and widow lines quite effectively. Maybe you’ll still have to correct one or two things. But one or two things in the whole document, speaking of a document wihch basically handles itself, is not that much of a big deal. In MS Word, calculate to sit down for a few hours. Thus, yet another plus for LaTeX: less grey hair and more time for work-life-balance. Isn’t it amazing?

 

Another plus: Relative and absolute positioning

It’s always better to use relative positioning and values and also, leave litterally everything up to LaTeX. Thank me later. For some info on relative and absolute sizing, consult the upcoming post LaTeX for Archaeologists: Typeset your PhD catalogue in LaTeX post.

 

The (lack of) comment function: A workaround

A possible down-side for LaTeX is that advisors often like to use the comment function in MS Word to correct and comment your work in progress. This, I personally have solved by converting it to MS Word using Pandoc and then uploading it to GoogleDocs for my advisor to make corrections. These have to be put back into the original by hand, of course. But you need to proof-read multiple times anyway, so I reckon it doesn’t make much of a difference. It’s a wee bit inconveniant, is all.

But… LaTeX is scary?! On common concerns

If the prospect of first “having to learn complicated LaTeX” sacres you, you might want to check my article on The power of simplicity, or: Why LaTeX needn’t be scarily complicated. If you think LaTeX will slow you down, you might want to check my post on typing fast in LaTeX. But then again, when writing highly qualitative work (like your dissertation should be), it might even be better if your writing slows you down a little. Pause to reflect!

Transition to LaTeX and get a life. A manifesto

“Well, at some point, LaTeX really had more features than Word but nowadays, I don’t see why you should bother using it anymore.” That’s a typical counter-argument, a justification why people don’t use LaTeX and don’t see why it’s worth the effort to learn it and finally make the transition. To this, I want to say: Well, can it do this? Hint: no. I rather suggest you don’t even try. Well at least, don’t hold me accountable if you should try and fail.

If you don’t see why using LaTeX would benefit you, maybe you just haven’t heard the facts yet? And well, probably you aren’t an archaeologist with 1 million images in a 500-page PhD thesis. If you are, don’t commit suicide just yet. There are other ways than Word. If your thesis document won’t even open anymore, don’t despair. Just convert it to LaTeX! And, thank me later.

Citation styles

LaTeX offers citation support. It’s basically a lot like Citavi or Zotero, only less complicated. Not that I have a lot experience with those, I do admit it. But the principle is the same. LaTeX and Bibtex seem complicated at first. But you’re most certainly just so conditioned and accustomed to MS Word workflows that you don’t remember anything else. And what we don’t know, we fear. But you need not fear, LaTeX is here for you.

A tutorial and more info on this will follow in a separate post.

Yes, LaTeX will throw warnings and errors. It’s not a big deal, really.

People are put off by the fact that you can get warnings or fatal compilation errors. Well yeah, it’s inconvienent to have to debug your own bullshit but well, sorry to have to break it to you, that’s life. Would you rather have a program that doesn’t complain there is a mistake, subsequently hide the problem from you entirely but just stop working for inexplicable reasons and you have no way of escaping? Wait, yes, maybe you do. It’s called MS Word.

You’re not a qualified typesetter

LaTeX is an art. It’s supposed to be an art. Typesetting is an art. And if you haven’t learned to be a typesetter, you probably are not and thus, should not act as a professional typesetter. But MS Word, one hell of a program (and I mean this litterally), makes you believe that you are or you could. It even suggests you should. Hint: You shouldn’t. And in your heart, you really know that’s true.

How to transition from an existing MS Word document or LaTeX-ify your workflow

  1. Migrate your document. (Oxgarage, Pandoc, you name it. Read how to do this in my post on who to quit MS Word).
  2. Continue writing in Word and transform your stuff to LaTeX before adding the images and thus, killing Word for good. Why the hell would anyone want to continue using MS Word? But hey, my opinion isn’t the truth. It’s just my opinion. Do what works for you. If it contains LaTeX, all the better. The LaTeX Noob uses this workflow and it seeems to work for her. Kind of like a “the best of the two worlds” compromise. You get the parts where MS Word is conveniant (letting your advisor use the comment function, etc.), but the typesetting and image handeling is done in LaTeX.
  3.  Just write it in LaTeX. It’s just a question of getting used to it. Using it exclusively will give you just that. Even though I had been using LaTeX for years, transitioning completely made me quite a bit better still. I now also write quick notes in LaTeX without batting an eyelash. Sometimes I still use a GoogleDoc to write things down that are just meant for note-taking, not for creating PDF output.

I will follow up with a post on citation styles and how to import your Citavi to BibTeX, etc. Until then, consider looking up some of my already existing posts which might be of interest, like Jumpstarting: Learn LaTeX in 3 minutes  or A Humanities’ seminar paper with LaTeX – in 10 minutes or How to quit MS Word for good.

Best,

your Ninja

Further resources

The not-so-short intro, also available in German. Tobias Oetiker, Hubert Partl, Irene Hyna & Elisabeth Schlegl: The Not So Short Introduction to LATEX 2ε. Or LATEX 2ε in 139 minutes. Version 6.2, February 28, 2018

https://www.latex-tutorial.com/tutorials/

https://learnxinyminutes.com/docs/latex/

https://en.wikibooks.org/wiki/LaTeX

A Survival Guide for a PhD: http://karpathy.github.io/2016/09/07/phd/

https://www.quora.com/I-wrote-my-PhD-dissertation-in-LaTeX-but-my-advisor-told-me-it-needs-to-be-in-a-format-other-than-PDF-to-send-to-my-committee-members-He-says-it-is-too-difficult-to-make-comments-or-corrections-on-PDF-What-is-the-best-format-for-a-dissertation Quote: “And I’ll even print out the occasional paper and use a red pen. ” yep, good idea. I thought that was actually very sensible advice 😉

https://tex.stackexchange.com/questions/1756/why-should-i-use-latex

https://www.overleaf.com/project/5c42fa03a343e77a02003def (The Scientific Paper: A Template with Tips for Working with LaTeX)

 

Buy me coffee!

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

€3.00