You can't do this with a straightforward eval
, because that function does not pre-parse the Cadabra input into Python input. But if you realise that the ::
notation gets translated into a simple function call, then it's a relatively simple thing to do yourself:
for i in range(20):
LaTeXForm(Ex(r'\a'+str(i)+r'{#}'), Ex(r'"\alpha_{'+str(i)+r'}"') )
The only tricky thing here is the quotes in the 2nd Ex
: oyu need the single quote to generate a string, and then the double quote inside that so that Cadabra's LaTeXForm
property gets fed a string too, not a maths expression.
Granted, this would be nice to have in a cleaner notation, but it gets the job done.