Content AND Presentation

2017-10-23 Styles in TikZ

Many TeX users learned to love the great TikZ package. I used to be a great fan of Metapost (even back in the good ol’ days of DOS), but when a friend told me about TikZ, I checked it out and instantly fell in love. No more external compilation, no more strange syntax, no more problems with labels etc. Yes, MP has its advantages, like the declarative way of solving linear equations or the Hobby algorithm for finding the nicest curve fitting to a set of points. And yes, with \write18 or LuaTeX (or just plain old makefiles), you don’t have to run a separate program to compile your MP diagrams. But I made my switch, and most of the time I’m really glad I did.

There are a few things, however, which are a bit uncool with TikZ. One of them is that I find it notoriously difficult to define commands to draw repetitive things in my diagrams. (Yes, I know that I can define pics and nodes. The former have limited use, since it appears that they cannot be parametrized, and the latter are a pain to define – been there, done that, believe me it’s true.)

Some time ago, I’ve been giving a lecture on calculus. As I mentioned a few times, after a short affair with reveal.js (through Org-mode) I settled for Beamer. The thing is, I wanted to have nice pictures. And lots of them. So I finally sat down to figure out how to apply the DRY principle to TikZ pictures.

For starters, lots of my pictures involved a (two-dimensional) coordinate system. I decided to write a command to draw it. It’s not very TikZ-ish, but it works quite nice, and it accepts a bunch of key-value style parameters to customize my coordinate axes.

Of course, if one wants to have key-value syntax in LaTeX, one thing immediately comes to mind: the pgfkeys package. However, its documentation, while extensive, does not give an example of how to achieve what I wanted. And that was basically: have some keys, with some default values (note: this is a bit different from what pgfkeys calls a default value of a key; here, the defaults should be used not when the key is present without a value, but when the key is completely absent), which should then be easy to use within some TeX code.

Happily, we have TeX.SE. This answer by Ryan Reich gives a very detailed, complete example. I highly recommend it if you want to use pgfkeys for customizing some LaTeX commands (not necessarily in connection with TikZ). And here’s my code for the coordinate system:

\usepackage{etoolbox}
\pgfkeys{/mbork/.is family,/mbork,
  default/.style={
    xmin=-0.5,
    ymin=-0.5,
    xmax=3,
    ymax=3,
    xlabel={$x$},
    ylabel={$y$},
    zerolabel={$0$},
  },
  xmin/.store in=\mborkxmin,
  ymin/.store in=\mborkymin,
  xmax/.store in=\mborkxmax,
  ymax/.store in=\mborkymax,
  xlabel/.store in=\mborkxlabel,
  ylabel/.store in=\mborkylabel,
  zerolabel/.store in=\mborkzerolabel,
}

\newcommand{\coordsystem}[1][]{%
  \pgfkeys{/mbork,default,#1}%
  \draw[->] (\mborkxmin,0) -- (\mborkxmax,0);
  \draw[->] (0,\mborkymin) -- (0,\mborkymax);
  \ifblank{\mborkxlabel}{}{
    \node[below] at (\mborkxmax,0) {\mborkxlabel};
  }
  \ifblank{\mborkylabel}{}{
    \node[left] at (0,\mborkymax) {\mborkylabel};
  }
  \ifblank{\mborkzerolabel}{}{
    \node[below left] (0,0) {\mborkzerolabel};
  }
}

Notice that I made use of etoolbox’s \ifblank test here.

Then, I wanted to have a consistent look of my function graphs, so I wrote a small TikZ style I used whenever I was drawing a curve. It turned out that it was both easy and effective, so I’ll be definitely using this technique more and more in the future.

The style can be defined in the following way:

\tikzset{graph/.style={very thick,darkgray}}

and used like this:

\draw[graph] (0,0) rectangle (1,1);

As you can see, it’s really nothing magical. (Note that there is another way of defining a style, namely the \tikzstyle command, but it is deprecated.) Also, there is .append style, which adds given options at the end of an existing style (see the manual for more details).

Enjoy!

CategoryEnglish, CategoryBlog, CategoryTeX, CategoryLaTeX

Comments on this page

2017-10-16 emacs-reveal

Some time ago, I learned from the Org-mode mailing list about a very interesting extension to the well-known org-reveal package. The emacs-reveal package allows to embed audio files in reveal.js presentations. I find this quite fascinating, especially that I actually did prepare quite a few educational presentations. My ones were done in a much simpler way – I just set up a simple camera against a blackboard (or a whiteboard), pressed the “record” button and started talking and writing on the board. While this may seem strange, it actually does make sense, at least in case of mathematics: using LaTeX (with Beamer, for instance) to show the steps of derivation of some formula, while perfectly possible, is rather nightmarish, both in terms of the amount of work involved and in terms of robustness (try changing anything in an overlay-heavy display equation in Beamer!). In this case, using modern technology involves a huge cost against a relatively minor gain. Besides, I’m inclined to think that watching an actual human being explaining some topic may be more effective (and definitely more pleasant) than watching the presentation slides alone. (Of course, all of this is just my guts, and I can’t back it by any kind of science. Whether (a) backing it up by science is doable and (b) said science, involving a huge amount of variability, as is usual in the case for human sciences, is actually trustworthy, is of course a separate problem.)

Anyhow, for presentations about, say, programming, it seems actually better to use a computer instead of a blackboard. It is notoriously hard (although possible) to get your code indented properly on a blackboard, not to mention font locking a.k.a. syntax highlighting.

I did not (yet) try to use emacs-reveal, but from what I see in an example, provided by its author, using emacs-reveal is fairly easy. You basically write your Org-mode/Org-reveal slides as usual, and add a special property with a link to an ogg file for each heading you want to be associated with an audio track. You can even add audio files for individual “fragments” (like, list items)! The latter is slightly worse than ideal, since you have to put the list of audio files at the top of the list (so that reordering the list involves manually reordering the audio files for items), but this is a small price to pay for a really cool feature.

Now I can’t wait to prepare my first presentation using this tool. Unfortunately, I do not have any immediate use for that, but I’ll be looking for one!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

2017-10-08 Me an minimalism in 2017

It’s been very interesting for me to read my post from previous year about Life, productivity, and faith. After almost a year my situation has changed a bit (although I’d prefer it to change more, in a sense), so I thought I’d like to share some of my views.

First things first: after giving some more thought to the relation between salvation and love, I guess a correction is necessary. While catchy, my idea was probably wrong after all. Of course, thoughts about salvation and/or damnation (depending on one’s attitude) can be huge motivators for practicing love. But I suppose I didn’t make this obvious enough: doing everything to get to heaven is much more than a way to motivate you – this is basically the goal, period. And these days I think (though still far from being sure that I’m 100% right) that the two are basically one and the same thing. My current answer to the objection of “thinking about getting to heaven is egotistic” would be that it’s not only because of you. It’s also because that’s where those who love you want you to be – they want to meet you there. (All that remembering that the “where” is not in a sense of a physical place.) And the first of those is God himself, obviosly.

With that explained, let me get to the main point of today’s post. I’ve been reading a bit about minimalism recently, and I am more and more tempted to introduce some minimalist changes to my life. (This can be even seen in my previous post, though it turned out to be more difficult than I thought – or rather, I turned out to be more procrastinating on that than I thought.) Of course, minimalism is not really a new idea – you can actually find it in the Gospels and in the Church’s teaching (which is not a surprise at all, of course). The new thing (at least for me) are some associations I came upon lately.

It seems that there are some well-known software engineering principles which seem to apply very well to life in general. It was kind of funny for me, but now that I think of it, it should not be surprising at all. Software enginering is about managing complex systems, and human life is surely a complex system, so some common generalizations are to be expected. The first one that comes to mind is probably YAGNI. Enough said – I don’t have a lot to add to it, really. Another one is KISS.

Of course, as with many (if not all) analogies, this one is probably not perfect, and I’m not trying to say that blindly following principles from one field in another one is necessarily a good idea. (Worse is better seems especially suspicious, in both computing and even more so in life, and Python’s famous “easier to ask for forgiveness than permission” is an easy recipe for disaster.) But I’ll definitely keep YAGNI and KISS in mind from now on when thinking about whether to get rid of some thing or not.

CategoryEnglish, CategoryBlog, CategoryFaith

Comments on this page

More...

CategoryEnglish, CategoryBlog