6
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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? $\endgroup$
    – Jason B.
    Commented May 3, 2016 at 14:13
  • $\begingroup$ 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[]) $\endgroup$
    – marRrR
    Commented May 3, 2016 at 14:57

1 Answer 1

8
$\begingroup$

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[])

enter image description here

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

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

enter image description here

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) $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.