MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Tentative conclusion: Mathematica cannot outputplain text

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39802] RE: [mg39762] Tentative conclusion: Mathematica cannot outputplain text
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 7 Mar 2003 03:41:14 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Carlos,

I'm not certain about this because I never use TeX or LaTeX. But there is a
TexForm in Mathematica. Instead of using a Print statement, use a plain
TableForm output. Then use TexForm to obtain output which I presume can be
pasted into a Tex document.

PrintNodeCoordinates[xyzcoor_] := Module[
  {numnod = Length[xyzcoor], t, n, c},
   t = Table["   ", {numnod + 1}, {4}];
   For [n = 1, n <= numnod, n++, c = xyzcoor[[n]];
       If [Length[c] <= 2, AppendTo[c, 0]];
       If [Length[c] == 1, AppendTo[c, 0]];
       t[[n + 1, 1]] = ToString[n];
       t[[n + 1, 2]] = PaddedForm[c[[1]]];
       t[[n + 1, 3]] = PaddedForm[c[[2]]];
       t[[n + 1, 4]] = PaddedForm[c[[3]]];
   ];
   t[[1]] = {"node", "x", "y", "z"};
  TableForm[t, TableAlignments -> {Right},
           TableDirections -> {Column, Row}, TableSpacing -> {0.5, 1},
      TableAlignments -> {Center, Left}]]

The following gives Mathematica table output.

PrintNodeCoordinates[
  {{2, 3, 2000}, {5, a + b, 168.09}, {x_dir, y_dir, z_dir}}]

The following gives TeX output.

PrintNodeCoordinates[
  {{2, 3, 2000}, {5, a + b, 168.09}, {x_dir, y_dir, z_dir}}] // TeXForm

\matrix{ node & x & y & z \cr 1 & \Mfunction{PaddedForm}(
   2) & \Mfunction{PaddedForm}(3) & \Mfunction{PaddedForm
    }(2000) \cr \Mfunction{2} & \Mfunction{PaddedForm}(
   5) & \Mfunction{PaddedForm}(a + b) & \Mfunction{Padded
    Form}(168.09) \cr \Mfunction{3} & \Mfunction{PaddedFo
    rm}(\Mfunction{Pattern}(x,
    \Mfunction{Blank}(\Mvariable{dir}))) & \Mfunction{Pad
    dedForm}(\Mfunction{Pattern}(y,
    \Mfunction{Blank}(\Mvariable{dir}))) & \Mfunction{Pad
    dedForm}(\Mfunction{Pattern}(z,
    \Mfunction{Blank}(\Mvariable{dir}))) \cr  }

Is that of any use? There should be people in MathGroup who know a great
deal more about this.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Carlos Felippa [mailto:carlos at titan.Colorado.EDU]
To: mathgroup at smc.vnet.net


Dear David:   Many thanks for your answer.  I know the 4 "Forms" you
mentioned, but they all produce formatting characters.
The original question is posted below.  I guess what is needed
is a //PlainForm.

================   The original posting  =========================
I am converting an old code written 8 yrs ago in Mathematica 2.2 to
4.2, and would like to keep the same plain text tabular output.
To see what I mean, consider the 2.2 fragment

PrintNodeCoordinates[xyzcoor_]:= Module[
  {numnod=Length[xyzcoor],t,n,c},
   t=Table["   ",{numnod+1},{4}];
   For [n=1,n<=numnod,n++,c=xyzcoor[[n]];
       If [Length[c]<=2, AppendTo[c,0]];
       If [Length[c]==1, AppendTo[c,0]];
       t[[n+1,1]]=ToString[n];
       t[[n+1,2]]=PaddedForm[c[[1]]];
       t[[n+1,3]]=PaddedForm[c[[2]]];
       t[[n+1,4]]=PaddedForm[c[[3]]];
   ];
   t[[1]] = {"node","x","y","z"};
   Print[TableForm[t,TableAlignments->{Right},
           TableDirections->{Column,Row},TableSpacing->{0,1}]];
   ];
PrintNodeCoordinates[
  {{2,3,2000},{5,a+b,168.09},{x_dir,y_dir,z_dir}}];

The output from 2.2 is

 node  x     y     z
 1     2     3     2000
 2     5    a + b  168.09
 3    x_dir y_dir z_dir

What you see is exactly what you get if you move the output cell
to another program like TeX, e.g. for verbatim display.
Running this under 4.2 gives a messy output.  Saving the output
cell with Save Selection As  -> Plain Text I see

\!\(\*
  TagBox[GridBox[{
        {"\<\"node\"\>", "\<\"x\"\>", "\<\"y\"\>", "\<\"z\"\>"},
        {"\<\"1\"\>",
          TagBox[
            InterpretationBox["\<\" 2\"\>",
              2,
              Editable->False],
            PaddedForm],

<30+ more lines snipped, you get the idea>

How can I get exact plain text output?   I looked for something
like a TextForm or PlainTextForm filter, so I could say

  Print[PlainTextForm[TableForm[t,TableAlignments->{Right},
           TableDirections->{Column,Row},TableSpacing->{0,1}]]];

but found nothing in the 4.2 help file. Is there a way?



  • Prev by Date: Re: RE: Re: Is Sort stable?
  • Next by Date: Re: RE: Re: Is Sort stable?
  • Previous by thread: Re: pattern matching with repeated named patterns
  • Next by thread: Re: Tentative conclusion: Mathematica cannot outputplain text