TransWikia.com

Automatic Labelling of objects in IPE

TeX - LaTeX Asked by llualpu on February 8, 2021

IPE is an extensible drawing editor for creating figures in PDF format. It is a tool with which you can easily draw figures that can be later included into your LaTeX project easily, without having to rack your brain using pstricks or tickz, especially if you are new with them (though that’s my personal opinion). The extensible comes into play in that people can make plugins, or ipelets, for the program and extend IPE with additional features.

For the past few months I’ve been using IPE to create figures for my projects, and I’ve got the feeling the program is missing a little something. For example, in many situations I had to draw several points and do things with them (like joining them with lines, but the exact nature of these "things" is not relevant here) and refer to them in the text, so I had to add a little "label" next to the points in the figure. But this can get terribly slow whenever I have to name several points. For example, in the figure I had to label the 6 points one by one with $p_1$, $p_2$, $p_3$, …

Is there any tool that can automatize this process? Below I give an affirmative answer to this question.

One Answer

Since I could not find any ipelet that could solve this problem (several weeks ago, and not even in this comprehensive list), I decided to make one myself. You will find it in this repository on github. The usage is fairly simple and is explained in the repo, but let me write a short and sweet summary so you can comment on this.

Once the ipelet has been added to the ipelets directory (and added the recommended keyboard shortcuts for easier, faster access) one can "label" objects quite easily with very few steps.

  1. The first step is to set the "labelling expression". This expression is a string containing %%-delimited substrings. Within the %% one can make references to the counter using ^L and make arithmetic expressions with. For example:
    • The labelling expression $x_{%% ^L %%}$ produces an x with a subscript that contains the value of the counter, all surrounded by $. Since (by default) the counter starts at 1, the subscripts generated are the natural numbers: $x_1$, $x_2$, $x_3$, ...,
    • %% ^L*^L %% produces the squares of the natural numbers,
    • %% ^L^2 %% also produces the squares of the natural numbers,
    • %%^L%%/100 produces the typical "x out of 100": x/100,
    • and, similarly, in the expression This is object number %%^L%%. Its associated variable is $x_{%%^L%%}$ the %%^L%% are replaced by the value of the counter.

  1. Just add the labels now! Use the keyboard shortcut to add a label at the position where the mouse is currently located at. For the points in the figure in the question, use the labelling expression $p_{%%^L%%}$. It goes without saying that if you click several times you add several labels, producing the labels $p_{1}$, $p_{2}$, $p_{3}$, and so on which can then be rendered with pdflatex (the result of which can be seen in the editor).

Now, this does not end here. With autolabel.ipe you can also label many other objects (not only points), and several objects at the same time. For example, in the figure in the question one could have selected all the points, and then use the keyboard shortcut to label them at the same time. Needless to say that the labels' counter will still be incremented. The only catch of this feature is that the order in which the labels are added is the same in which the selected objects were inserted into the editor. I added gifs in the github repo showing this and a picture here so you can see what I mean.

The points in the figure to the left were added in counterclockwise order, and the the points in the figure to the right were added in a zig-zag fashion.

Answered by llualpu on February 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP