Posts Tagged ‘variable’


Sunday, July 10th, 2011

Imagemagick hackery

This post outlines how to create an image containing text, using imagemagick. The comment made by Severin improved upon the original snippet by cropping the image to just fit around the text.

One could use this in a script if you just set the following variables: width, height, fontsize, text and filename. I could have added another variable for font, but that would have made the example code below less informative.

convert -size ${width?}x${height?} xc:transparent -font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf -fill black -pointsize ${fontsize?} -draw "text 0,${fontsize?} '${text?}'" -trim +repage ${filename?}.png

LaTeX and variables

One of the neatest things about LaTeX (except for the automagic table of contents generation, ease of use when it comes to references, and never having to worry much about typesetting) is that it really is a markup language. A markup language where you can define your own “macros” (commands as they are called in LaTeX). And these commands can be just as simple or complex as you have the skill to make them.

So for instance, if you are writing something in LaTeX, and you find that you have to write the same thing over and over again, you could define a new command which prints that for you wherever you call the command (this of course relies on that what you are writing many times is longer than the name you give your command, otherwise it wouldn’t make much sense. Unless of course this something you are repeating, may be subject to change later, and you don’t look forward to doing a search / replace across the entirety of the document(s).

I remember that our group used this during a semester at ITU, but then I “rediscovered” it this Monday as I embarked on a small writing project, being unsure if I liked the names I’d given my characters.

So now I have a “characters.tex” file, which just defines a couple of commands. These commands, in turn, do little more than return the name I have currently given the character. characters.tex is then imported into the main file (“novel.tex“) and whenever I need to call a character by name, I just use the command I defined for that character.

This question over at helped me with an answer:


I.e. We call the command \newcommand which takes two arguments, whereof the first is the name of the new command (in this case \protagonist1) and a command body, what the new command should do, which, in this case simply is to output the string “Tony”.

Ok, protagonist1 sounds kindof silly, and perhaps I should have named the command nightclubOwnerFname instead, but that would have been a fingerfull to type.

What you take away from all this is that if I ever decide to rename Tony to… iunno, Mark? I will only have to change it in one place, the characters.tex file.

To include a file in LaTeX you use:


Why the “.tex” from “characters.tex” should be omitted in the input command I have no idea about, but that’s how I learnt it, and it works. One day I should really sit down and figure that one out.

Finally, to use the command inside your text you just write your stuff, but instead of writing the name you call the command:

She looked at \protagonist1{} in disbelief.

That’s pretty much all there is to it. Ain’t LaTeX neat?

Creating diffs in git

I started looking into fugitive but hit a brick wall smack dab in the beginning of the adventure as I’m running Arch, and its version of git was just slightly newer than that of p4bl0.

Once I got fugitive running, I wanted to get it to handle markdown (i.e. parse the markdown marked up as a part of the process of generating the published html), which had some unintended consequences for the <title> tag (i.e. markdown had already parsed the first line in the file, which is used as the post title) and this resulted in <title><p>my post title here</p></title>… that ain’t so good ;)

The upside to it was that I got to do a little digging around in code (which I need to get better at anyway) and I ended up solving that little problem (but that introduced a bug (yes, I suck, should’ve tested more first) but I have submitted another patch which should undo all my stupidity and make it right. This time I have done more testing ;))

BUT, it also meant that I needed to generate a diff that p4bl0 could use to patch fugitive. This blog post gave me all I needed to know, i.e.:

$ git diff --no-prefix > patchfile

Automatically mounting removable media in Arch

Although it can be reckless to automount stuff (because you never know where that USB stick has been ;)) it can be nice (comfortable) to have it all done for you, and that’s where autofs can help you.


Update: fixed silly typo, thank you mina86