TexAct: problem with indices

111 views
Skip to first unread message

Johannes

unread,
Nov 2, 2016, 11:59:45 AM11/2/16
to xAct Tensor Computer Algebra
Hi all,

I've encountered a bug/problem with the way TexAct handles indices defined via the PrintAs option of a tensor (i.e. not space-time indices!). Here is a minimal example:

DefTensor[Phi[], M4, PrintAs -> ToString[Subscript["\[Phi]", "(K)"], StandardForm]]
% // TexPrint,

where M4 is some manifold previously defined and (K) is a type of label index, which I would rather not always have to write via LI[(K)], but have defined together with the symbol. The code above produces a host of RecurssionLimit, StringJoin and StringExpression errors and produces no output in the end.The problem seems to be with the interplay between the Tex command and StandardForm strings. For example: 

DefTensor[AV[b], M4, PrintAs -> "A"]
AV[c]
ToString[%, StandardForm]
% // TexPrint

produces an analogous host of errors (b and c are previously defined indices for this manifold). Does anyone have a neat fix for this? What I'm looking for is (ideally) a modification to a few lines in the TexAct source code that fixes this. I can hack things by re-casting everything with the use of label indices, as mentioned above, but I'd rather not if at all possible.

Many thanks and best wishes,
  Johannes

Thomas Bäckdahl

unread,
Nov 2, 2016, 1:36:42 PM11/2/16
to xa...@googlegroups.com
Hi!

At the moment TexAct tries to Make sensible output from PrintAs, but for complicated PrintAs specifications this can fail.
It handles some standard things in the TexAct code, but if it encounters something which it does not know how to convert to Tex code it calls the internal Mathematica function TexForm. This is where your example fails.
For instance, try TeXForm[PrintAs[Phi]]

I can try to implement more advanced interpretations of things like "\!\(\*SubscriptBox[\"\\\"\[Phi]\\\"\", \"\\\"(K)\\\"\"]\)" etc, but for the moment I would suggest that you specify the Tex output for your tensors. For instance

Tex[Phi] ^= "\\phi_{(K)}";

Then this is used instead of converting the PrintAs to tex code.

If you do this for a tensor with indices I would suggest to add an extra pair of empty brackets like

Tex[Phi] ^= "\\phi_{(K)}{}";
This would remove problematic tex code like \phi_{(K)}_{a} which has double subscripts.

I hope this helps a bit.

Regards
Thomas
--
You received this message because you are subscribed to the Google Groups "xAct Tensor Computer Algebra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xact+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Bäckdahl

unread,
Nov 2, 2016, 3:46:08 PM11/2/16
to xa...@googlegroups.com
Hi again!

I made some experiments by re-designing xAct`TexAct`Private`TexOrnament which is supposed to interpret some special typesetting code and produce the corresponding tex code. I have not tested this properly so it might break something.

If you add the following code to your notebook, then I hope many more typesetting cases should work better.

TexOrnamentExpr[Subscript[a_,b_]]:=StringJoin[Tex@a,"_{",Tex@b,"}{}"]
TexOrnamentExpr[Superscript[a_,b_]]:=StringJoin[Tex@a,"^{",Tex@b,"}{}"]
TexOrnamentExpr[OverBar[a_]]:=TexOverline[Tex@a]
TexOrnamentExpr[OverTilde[a_]]:=TexTilde[Tex@a]
TexOrnamentExpr[OverHat[a_]]:=TexHat[Tex@a]
TexOrnamentExpr[expr___]:=StringJoin@@(Tex/@{expr});

Clear@xAct`TexAct`Private`TexOrnament
xAct`TexAct`Private`TexOrnament[str_String]:=TexOrnamentExpr@ToExpression[str,StandardForm]/;StringMatchQ[str,StringExpression["\!\(",x___,"\)"]];
xAct`TexAct`Private`TexOrnament[str_String]:=xAct`TexAct`Private`Removetext@ToString@TeXForm@xAct`TexAct`Private`RemoveStyleBoxes@str;

Please tell me if this helped and if it broke something else.

Regards
Thomas

Johannes

unread,
Nov 3, 2016, 2:48:15 PM11/3/16
to xAct Tensor Computer Algebra
Hi Thomas,

thanks a lot for your very quick reply! Specifying the Tex output directly as in your example works very well (especially after adding the extra pair of empty brackets to avoid further hiccups, like you said). It's certainly much more elegant than my label index hack using LI[(K)]. I also tried your TexOrnament typesetting modifications and they work very smoothly as well - didn't spot anything that broke as a result of the new code! 

Many thanks for your help again and best wishes!
  Johannes
Reply all
Reply to author
Forward
0 new messages