This imports the package and defines the variables,

```
<< xAct`xTensor`;
DefManifold[M4, 4, {a, b, c, d, e, f, g, h, i, j, k, l}] ;
DefMetric[-1, metric[-a, -b], CD, PrintAs -> "g"];
DefTensor[p[], M4, PrintAs -> "ϕ"];
```

This is your expression,

```
test = (CD[-a]@p[] CD[a]@p[])
```

Let's look at all the various forms there are of this expression,

```
Through[{TraditionalForm, TeXForm, InputForm, FullForm, StandardForm}[test]]
```

It seems that all forms except `StandardForm`

see `test`

as `CD[-a][p[]]CD[a][p[]]`

So we need to apply `StandardForm`

and **then** `TeXForm`

:

```
TeXForm@StandardForm@test
(* \left(\triangledown _a\phi
\right) \left(\triangledown
^a\phi \right) *)
```

Or, evaluated in $\TeX$,

$$\left(\triangledown _a\phi
\right) \left(\triangledown
^a\phi \right) $$

1Thanks for the example, I've never used xAct before, but I have it installed, how would I go about having $\nabla_a\phi\nabla^a\phi$ defined in the first place? Which subpackage(s) do I need to load, and what commands do I need to enter in order to have it as an object I can try to act on? – Jason B. – 2016-05-03T14:13:51.627

The basic commands you need to defined this expression are: $\$ << xAct

`xTensor`

DefManifold[M4, 4, {a, b, c, d, e, f, g, h, i, j, k, l}] DefMetric[-1, metric[-a, -b], CD, PrintAs -> "g"] %CD here refers to the covariant derivative% DefTensor[p[], M4, PrintAs -> "[phi]"] $p is the scalar field% and the expression above will be (CD[-a]@p[] CD[a]@p[]) – marRrR – 2016-05-03T14:57:05.630