# Copy xAct expression to LaTeX

How can I copy an xAct expression to LaTex? Using the usual command TeXForm[] gives the xAct structure, I would like to get the printed form. For example

$$\text{TeXForm}[\nabla_a\phi\nabla^a\phi]$$

gives

\text{CD}(-a)(p()) \text{CD}(-a)(p())

which is how I defined my tensors.

• Thanks 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. May 3 '16 at 14:13
• The basic commands you need to defined this expression are: $\\$ << xActxTensor 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 May 3 '16 at 14:57 ## 1 Answer This imports the package and defines the variables, << xActxTensor; 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)$$