Problem with TexPrint

174 views
Skip to first unread message

Adam

unread,
Apr 18, 2012, 5:35:49 AM4/18/12
to xAct Tensor Computer Algebra
I've been unable to convert xTensor expressions into LaTeX when the
expression involves a parametric derivative. For example, these
commands

DefParameter[s]
DefTensor[T[a, b], s]
TexPrint[ParamD[s][T[a, b]]]

result in an error message starting with this:

Sort::normal: Nonatomic expression expected at position 1 in Sort[s].

Is there a simple fix for this?

Thanks for any suggestions.

Adam

Edu Serna

unread,
Apr 18, 2012, 7:09:24 AM4/18/12
to xa...@googlegroups.com
HI TexPrint has given me some chagrin, for a while. In particular it splits denominators into every the product of of the inverse of all the factors.
 I have found a workaround: not use it:

I first substitute the tensors so that what you see is what you get
i.e.
% /. \[Alpha]2[] -> Subscript[\[Alpha], 2]
with indices you'll have to pattern match
then use texform
% // TeXForm

Hope it helps

Thomas Bäckdahl

unread,
Apr 18, 2012, 7:30:30 AM4/18/12
to xa...@googlegroups.com
Hi!

Yes, this is a bug -- a missing pair of brackets. Run the following
before using TexPrint:

Tex[ParamD[xAct`xTensor`Private`ps__][xAct`xTensor`Private`expr_]] :=
Apply[StringJoin,
xAct`xTensor`Private`TexParamD /@
Split@Sort[{xAct`xTensor`Private`ps}]] <>
xAct`xTensor`Private`TexOpen["["] <>
Tex[xAct`xTensor`Private`expr] <> xAct`xTensor`Private`TexClose["]"]

Regards
Thomas

Adam

unread,
Apr 18, 2012, 7:51:17 AM4/18/12
to xAct Tensor Computer Algebra
Thanks for the replies. Thomas, is there a way to put the derivative
in postfix format? $CovDFormat = "Postfix" makes TexPrint output
covariant derivatives in postfix format, but $ParamDFormat = "Postfix"
doesn't do the same for parametric derivatives.

Thomas Bäckdahl

unread,
Apr 18, 2012, 8:17:03 AM4/18/12
to xa...@googlegroups.com
Hi!

I made an experiment to improve the way TexPrint works with fractions. I have not tested it much but it should work.

Usually
TexPrint[s/t/(s + t)/(2 s + t/(1 + t))]
produces
s \frac{1}{t} \frac{1}{s + t} (2 s + t \frac{1}{1 + t})^{-1}

But if you first run the lines:

Tex[xAct`xTensor`Private`expr_Times] =.
Tex[expr : (Times[Power[a_, -1], b___])] :=
 StringJoin[xAct`xTensor`Private`$TexFraction, "{",
  Tex@Numerator[expr], "}{", Tex@Denominator[expr], "}"]
Tex[xAct`xTensor`Private`expr_Times] :=
 StringJoin @@
  Riffle[xAct`xTensor`Private`TexFactor /@
    List @@ xAct`xTensor`Private`expr,
   xAct`xTensor`Private`TexOperator[Times]]

TexPrint[s/t/(s + t)/(2 s + t/(1 + t))]
should produce
\frac{s}{t (s + t) (2 s + \frac{t}{1 + t})}

Regards
Thomas

Thomas Bäckdahl

unread,
Apr 18, 2012, 8:49:42 AM4/18/12
to xa...@googlegroups.com
Hi!
This was not implemented for TexPrint.
I made a simple implementation of this.
This code replaces the one in the last e-mail. I also removed the
annoying brackets in the prefix notation.

Tex[ParamD[xAct`xTensor`Private`ps__][xAct`xTensor`Private`expr_]] :=

If[$ParamDFormat == "Postfix",
StringJoin[Tex[xAct`xTensor`Private`expr], "{}_{,",
Sequence @@ (Tex /@ {xAct`xTensor`Private`ps}), "}"],


Apply[StringJoin,
xAct`xTensor`Private`TexParamD /@
Split@Sort[{xAct`xTensor`Private`ps}]] <>

Tex[xAct`xTensor`Private`expr]]

Now, TexPrint should respect the $ParamDFormat setting.

Observe that in postfix notation the parameters are listed as they are,
but in prefix notation, they are sorted and grouped into powers.
For instance
ParamD[s, t, s][T[a, b]]
is printed as
\partial_s^{2} \partial_t T^{ab}
in prefix notation, but as
T^{ab}{}_{,sts}
in postfix notation.

I hope it works for you.

Regards
Thomas

Adam

unread,
Apr 18, 2012, 8:53:14 AM4/18/12
to xAct Tensor Computer Algebra
Thanks again. It's working perfectly.
Reply all
Reply to author
Forward
0 new messages