## Friday, January 4, 2008

### Tioga and text sizes

Tioga is powerful, as I undoubtedly mentioned here already. But, so far, it had a dreadful drawback: it was not possible to know the (TeX) text size other than by guesswork. This has now changed: starting from revision 453, it can find out and provide the information. All you need to do is to give a 'measure' => 'name' argument to show_text, and you can get information about the text size using get_text_size('name'). I used this new feature in figures.rb for a small demonstration:

    def text_size
t.stroke_rect(0,0,1,1)
t.rescale(0.5)

equation = '\int_{-\infty}^{\infty} \! e^{-x^{2}}\, \! dx = \sqrt{\pi}'
text = "\\fbox{$\\displaystyle #{equation}$}"

nb = 5
nb.times do |i|
scale = 0.5 + i * 0.2
angle = i * 37
x = (i+1)/(nb+1.0)
y = x
color = [1.0 - i * 0.2, i*0.2, 0]
t.show_text('text' => text, 'color' => color, 'x' => x,
'y' => x,
'alignment' => ALIGNED_AT_MIDHEIGHT,
'scale' => scale , 'measure' => "box#{i}",
'angle' => angle )
size = t.get_text_size("box#{i}")
w = size['width']
h = size['height']
t.stroke_color = color
t.stroke_rect(x - w/2, x - h/2, w, h)
end
end


This works really simply: Tioga uses a wrapper TeX function that displays the size of the text on pdflatex output. If Tioga detects that a size was requested, it fills in the information, gives it back to the program via get_text_size and runs pdflatex a second time use the information. For the first call, dummy values are given by get_text_size. It seems that the last showstopper of Tioga has finally fallen today !