How to make numbers/texts appear as one single text object in Makie?

When I generate vector graphics using CairoMakie, very often in the output figure (in .pdf) the axis numbers, labels and text (using text!() or Label()) consists of numbers and words which are ‘disconnected’ when I inspect the figure in Illustrator or Inkscape. By ‘disconnected’, I mean I can’t select the whole number or text as one single text object. Instead, they appear as separate text object. For example, when I create the following figure:

using CairoMakie, Pkg

Pkg.status(["CairoMakie"])  #v0.10.7

function create_demo(savename; font="Arial")

    set_theme!()
    update_theme!(Theme(fonts = (; regular = font)))

    fig = Figure(resolution=(1000,400))
    ax1 = Axis(fig[1,1])

    x1 = range(0, 1, length=101)
    y1 = sin.(x1)

    lines!(ax1, x1, y1)
    text!(ax1, 0.05, 0.95, text="label for testing", space=:relative)

    save(savename*".pdf", fig, pt_per_unit=1)
    
    return fig
end

@time create_demo("testing")

When I open it in Illustrator, I can’t highlight the whole ‘0.0’ in the x-axis label. ‘0.’ appear as one object, and the decimal ‘0’ appear as a separate object. Same when I just to select the text ‘label for testing’. The five alphabets in ‘label’ appear as five separate text, then ‘for’ as one text, ‘sting’ as one text. Sometimes it does output the whole thing as one text, e.g. ‘1.0’.

My question is are there ways to make it output each set of words or numbers as one text object? How does the program determine this?

1 Like

I think we’d need to refactor CairoMakie to use cairo-show-text-glyphs with text clusters.

So basically if I want the words to appear as one single cluster, right now there is no way to control it unless I change them manually through third party software like Illustrators. Is this correct (at least in the immediate future)?

Right. In principle Makie should be using established text layouting tools like Pango and Harfbuzz, this would automatically do the clustering right in Cairo as well. Not sure when I’ll have the time to take a look at this though, and it hasn’t mattered much for my own projects. Although to be fair, neither do I use right-to-left scripts, complex ligatures, or emojis :slight_smile: