Spacing and brackets
Cadabra is reasonably flexible as far as spacing and brackets are concerned, but the fact that objects do not have to be declared before they can be used means that spaces have to be introduced in some cases to avoid ambiguity. As a general rule, all terms in a product have to be separated by at least one whitespace character. Thus,ex:= A(B+C);
\(\displaystyle{}A\left(B +C\right)\)
A(B + C)
is interpreted as a function $A$ with argument $B+C$, while
ex:= A (B+C);
\(\displaystyle{}A \left(B +C\right)\)
A (B + C)
(with a space inbetween the $A$ and the opening bracket) is interpreted as
$A$ multiplying $B+C$. In a similar spirit, two consecutive characters without
a space are interpreted as a single symbol, so that
ex:= AB;
\(\displaystyle{}AB\)
AB
is not the product of $A$ times $B$, but rather a single, two-character
symbol. Put a space inbetween if you want it to be a product, or an
explicit multiplication sign,
ex:= A*B + A B;
\(\displaystyle{}2A B\)
2A B
If a whitespace character is absent, all brackets are interpreted as
enclosing argument groups. However, spaces will automatically be
inserted after numbers, between a closing bracket and a name or
number, and between two names if the second name starts with a
backslash. The following expressions are therefore interpreted as one
would expect:
ex1:= 3A;
ex2:= (A+B)C;
ex3:= (A+B)3;
ex4:= A\Gamma;
\(\displaystyle{}3A\)
3A
\(\displaystyle{}\left(A +B\right) C\)
(A + B) C
\(\displaystyle{}3A +3B\)
3A + 3B
\(\displaystyle{}A \Gamma\)
A \Gamma
Finally, note that
brackets in the input must be balanced (a decision made to
simplify the parser; it means that cadabra uses a different way to
indicate groups of symmetric or anti-symmetric indices than one often
encounters in the general relativity literature.