Label group syntax in title formatter collides with LaTeX

Hi,

I have the following code snippet

import holoviews as hv
hv.notebook_extension('matplotlib')

hv.Curve([1,2,3,4,5]).opts(title=r"$e^{-2}$")

The key thing is that the title should be printed in LaTeX as e raised to -2 power. But I got

KeyError: '-2'

The issue seems to be that titles specified through title attribute are first parsed for occurrences of {} which are interpreted as label or group placeholders.

I think the solution might be to keep it as is if the part inside {} doesn’t match any of the labels, instead of raising errors.

Thanks,
Rui

OK. Two solutions. The workaround one is always write {{ for { and }} for }. In this case, title=r"e^{{-2}}" works. The more permanent one is add

# protect all { and } by doubling
title_str=title_str.replace('{',"{{").replace('}',"}}")
# except for the following
for s in ["label","group","dimensions"]:
    title_str=title_str.replace("{{"+s+"}}","{"+s+"}")

immediately above the following lines

title = util.bytes_to_unicode(title_str).format(
    label=util.bytes_to_unicode(label),
    group=util.bytes_to_unicode(group),
    type=type_name,
    dimensions=dim_title 
)

in _format_title function of class DimensionedPlot in file holoviews/plotting/plot.py.

2 Likes