## How to add subcategories to templates in WordPress

This is the snippet I have added to my category template in my blog’s child theme. I paste the following snippet usually after the taxonomy-description paragraph. This is how it looks (the two paragraphs Parents and Subcategories):

This is the code:

<?php
// Parents
$parents = get_category_parents($cat, true, " +++ ");
$parents = explode(" +++ ",$parents);
$parents = array_slice($parents, 0, -2);
?>
<?php if ( count($parents) > 0 ) : ?> <div class="taxonomy-parents"><em>Parents:</em> <?php print(implode(', ',$parents)); ?></div>
<?php endif; ?>

<?php
// Subcategories
$list = wp_list_categories('depth=-1&orderby=name&style=none&echo=0&title_li=&child_of='.$cat);
$list = substr(trim(str_replace('<br />', ', ',$list)), 0, -1); // replace newlines by commas, trim whitespace, cut of final comma
?>
<?php if ( !preg_match("/No categorie/",$list) ) : ?> <div class="taxonomy-subcategories"><em>Subcategories:</em> <?php echo$list; ?></div>
<?php endif; ?>


## How to horizontally align beamer columns with surrounding text

If you (like me) assumed that placing two columns width 50% of textwidth next to each other would align with preceding or following text on a beamer slide, then you are mistaken (like me).

Fortunately, a discussion on Bug #262: Provide more usable columns environment showed a viable solution in form of the optional argument onlytextwidth.

However, in order to use it successfully, one must then take care of spacing oneself. Here is my result of some experimentation:

Here is the corresponding document:

\documentclass{beamer}
\usepackage{mathtools}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\usepackage{hyperref}

\begin{document}
\begin{frame}{Testing columns spacing}{How to achieve correctly spaced columns with beamer}
\emph{The documentation doesn't tell you anything about the alignment of the columns or the space inbetween them. In particular, the side effect of totalwidth (which changes the columns to be left aligned within the textarea of the slide rather than center aligned on the page).}
\vspace{.5cm}
\begin{columns}[t,onlytextwidth]
\begin{column}{.5\textwidth-.25cm}
This slide shows the successfull result to align the margins of these two columns with the surrounding text to exactly \lstinline{\\textwidth}.
\end{column}
\begin{column}{.5\textwidth-.25cm}
What to do?

Do your own math and specify column widths with spacing. These columns have equal width of \lstinline{.5\\textwidth-.25cm}.
\end{column}
\end{columns}
\vspace{.5cm}
From: \href{https://bitbucket.org/rivanvx/beamer/issue/262/provide-more-usable-columns-environment}{Issue \#262: Provide more usable columns environment}
\end{frame}
\end{document}


## My Python setup

In this post, I summarise my custom settings for my IPython, Matplotlib and IPython Notebook for my Windows machine at work.

## IPython

First some aesthetic preferences:

# select qt backend for plotting from terminal
from IPython.terminal.ipapp import TerminalIPythonApp
TerminalIPythonApp.matplotlib='qt'

c = get_config()
# bigger plots in IPython notebooks
c.InlineBackend.rc = {'figure.figsize': (16.0, 8.0), 'savefig.dpi': 72}


These are for productivity, mainly:

# always reload packages interactively

# import mainly used packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# change to pandas default "beautiful" style
pd.options.display.mpl_style = 'default'
# but keep sans-serif fonts (instead of monospace)
plt.rcParams['font.family'] = 'sans-serif'


## Matplotlib

For coherence with my employer’s style guide, I set my plot font to Arial with the following two lines:

font.family         : sans-serif
font.sans-serif     : Arial


All this results in the following default plot appearance (here for a Pandas area plot of multiple timeseries):

## Share as Gist toolbar button

Once that is prepared, get the file gist.js from minrk’s ipython extensions GitHub repository and place it in in the folder .ipython/nbextensions.

Then add the following lines to file custom.js, located in your profile:

require(["nbextensions/gist"], function (gist_extension) {
});


The next time you launch ipython notebook, a share button should appear in every notebook’s toolbar. The first time you click it, you must paste your GitHub access token. From there on, it will work automatically. Here is how it looks in action:

(And here is the link to the corresponding Notebook: urbs-result-plot.ipynb.)

## Full-frame graphics on a LaTeX beamer presentation

This snippet defines the custom command \fullframegraphic. Paste it into the document preamble (header) of your presentation:

\newcommand{\fullframegraphic}[1]{
\begin{frame}1
\includegraphics[height=\textheight,width=\textwidth,keepaspectratio]{#1}
\end{frame}
}


Then, you can create a full-frame graphic slide anywhere (outside a frame) using

\fullframegraphic{image}


## How to git push to multiple remotes with one command

There are multiple questions with even more answers on this exact question at Stack Overflow. The simplest answer, which I failed to find again, looks like this. Add the following lines to your repo’s .git/config:

[alias]
pushall = !git push origin master && git push github master && git push remote3 master


Simply change remote and branch names to fit yours and from thereon, a git pushall will do all the work.

## How to use TikZ for inline polygons

The trick is to define inner sep=0pt when beginning the tikzpicture environment, as I learned from pgf bug report #172 minimum size in regular polygon fails for small length from last year. Here is a minimum working example, adapted to my use case of inline polygon symbols with roughly text height, i.e. 2ex in my case:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\poly}[2]{\tikz[inner sep=0pt] {%
\node[regular polygon,%
regular polygon sides=#1,%
regular polygon rotate=#2,%
minimum size=2ex, fill] (0,0) {};}}

\begin{document}
Triangle upwards \poly{3}{0},
triangle downward \poly{3}{180}
and diamond \poly{4}{45}.
\end{document}


This snippet yields the following result:

## How to change the default matplotlib font

The default fonts for matplotlib are set in file matplotlibrc in the folder \$USER_HOME/.matplotlib. You can find them here, depending on your operating system:

• Windows: C:\Users\YourName\.matplotlib\matplotlibrc
• Linux: /home/YourName/.matplotlib/matplotlibrc

Within the file, search for the font section, and uncomment (remove the hash symbol # at beginning of line) or add the following settings as desired. In the shown example, I set Arial as the default:

font.family         : sans-serif
#font.style          : normal
#font.variant        : normal
#font.weight         : medium
#font.stretch        : normal

# ...

#font.serif          : Times New Roman, ...
font.sans-serif     : Arial, ...
#font.cursive        : ... cursive
#font.fantasy        : ... fantasy
#font.monospace      : ... monospace


Upon the next start of the Python interpreter, your plots should be labelled with the new font.

## How to autoreload packages while using them in IPython

I use IPython to interactively use and debug code that I edit in a text editor at the same time. Unfortunately, Python does not automatically reload packages and functions after an initial import foo, simply for performance reasons.

Fortunately, there is a solution: the IPython extension autoreload does what its name says: either all (how I use it) or only selected (imported using magic function %aimport) are refreshed, whenever I hit the Enter key. Here’s a short how-i-use-it demo, involving a minimal package foo with a helloworld function bar:

In [1]: %load_ext autoreload
In [3]: import foo
In [4]: foo.bar()
Hello World!

In [5]: !cat foo.py
def bar():
print('Hello World!\n')

In [6]: # edit foo.py in editor
In [7]: !cat foo.py
def bar():
print('Hello me!\n')

In [8]: # bar() is automagically reloaded
In [9]: foo.bar()
Hello me!


How do you get it? It’s already bundled with IPython by default! Happy hacking!

## How to use custom colours in LaTeX

I will post short minimum working examples (MWEs) of minimal LaTeX documents, showing a certain feature in action. Though the well-maintained LaTeX Wikibook is a much more extensive resource than a collection of such examples could ever be, they show directly compilable examples compared to isolated snippets.

I start simple: custom text colours, using different colour models. Shown here are RGB (0-255) and HTML (00-FF) style definitions. The text shows two different ways to access them. Bonus: these colours can be used in TikZ as well.

\documentclass{article}
\usepackage{xcolor}
\definecolor{cool}{RGB}{0, 110, 220}
\definecolor{heat}{RGB}{240, 120, 40}
\definecolor{pink}{HTML}{FF00FF}
\begin{document}
I am some \textcolor{heat}{really hot},
though \textcolor{cool}{also cold} text.
{\color{pink}Bright colors} are discouraged.
\end{document}


## How to list size of directories in current folder

Note to self, it’s deceptively simple, once one manages to read the manpages properly:

du -hd 1 /path/to/directory

If directory is the current folder, this shortens to:

du -hd 1