 
 
 
 
 
 
Re: PageWidth mystery
- To: mathgroup at smc.vnet.net
- Subject: [mg26116] Re: PageWidth mystery
- From: Timo Felbinger <timof at uranos.quantum.physik.uni-potsdam.de>
- Date: Tue, 28 Nov 2000 01:56:02 -0500 (EST)
- Organization: University of Potsdam
- References: <8v7kk9$b1t@smc.vnet.net> <8vfr9p$jj9@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 22 Nov 2000, Jens-Peer Kuska wrote:
> 
> remember how a typical Mathematica function look like.
> 
> At the *end* of the formating it finds your PageWidth option, but the
> actual page width must be evaluated before any of the expressions
> is formated. The formating goes top down and look for the
> PageWidth. Something like
> 
> MakeTheOutput[expr_,opts___]:=
>   Module[{pw},
>     ...
>     pw=PageWidth /. {opts} /. Options[$Output];
>     ...
>     Format[expr]
>    ] 
This is about what I feared is happening.  I had hoped that it would
more run along
MakeOutput[expr_]:=Module[{formatted,outstring},
    formatted=Format[expr];
    (* formatted is still an expression in tree-form, so we *)
    (* can still find good line breaks while converting it  *)
    (* into a string:                                       *)
    outstring=ToStringWithProperNewlines[formatted];
    SendToFrontEnd[outstring];
  ]
> Narrow /: MakeBoxes[Narrow[expr_], fmt_:StandardForm] :=
>
>   Module[{theboxes},
>       Print["hu"];
>        theboxes = MakeBoxes @@ {expr};
>       theboxes /. RowBox[bb_] /; Length[bb] > 16 :> RowBox[Flatten[
>             Append[#, "\[" <> "NewLine" <> "]"] & /@ 
>               Partition[bb, 16, 16, {1, 1}, {}]]]]
>
Thanks for this suggestion; it does something but not quite what
I wanted:
Running
  #!/bin/sh
  {
  cat <<EOF
  narrow /: MakeBoxes[narrow[expr___], fmt_:StandardForm] := (
    Module[{theboxes},
      Print["hu"];
      theboxes = MakeBoxes @@ {expr};
      theboxes /. RowBox[bb_] /; Length[bb] > 32 :> RowBox[
        Flatten[
          Append[#, "\[" <> "NewLine" <> "]"] & /@
            Partition[bb, 32 ]
        ]
      ]
    ]
  )
  narrow[ Range[40] ] 
  MakeBoxes[ narrow[ Range[40] ] ]
  EOF
  } | math
gives (some empty lines deleted for readability):
  Mathematica 3.0 for Linux
  Copyright 1988-97 Wolfram Research, Inc.
   -- Motif graphics initialized -- 
  
  In[1]:= 
  In[2]:= 
  Out[2]= narrow[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
  >     18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
  >     36, 37, 38, 39, 40}]
  In[3]:= hu
  Out[3]= RowBox[{{, RowBox[{1, ,, 2, ,, 3, ,, 4, ,, 5, ,, 6, ,, 7, ,, 8, ,, 9, 
  >       ,, 10, ,, 11, ,, 12, ,, 13, ,, 14, ,, 15, ,, 16, ,, \[NewLine], 17, 
  >       ,, 18, ,, 19, ,, 20, ,, 21, ,, 22, ,, 23, ,, 24, ,, 25, ,, 26, ,, 27, 
  >       ,, 28, ,, 29, ,, 30, ,, 31, ,, 32, ,, \[NewLine]}], }}]
IE, MakeBoxes works only as an explicit wrapper, it is not called
automatically like Format[], and I still cannot see how I could cause
it to actually break lines, instead of just inserting \[NewLine] where
a line break should be.
Replacing "\[NewLine]" by "\00n" gives a different, funny but still
wrong result.
With the above script I could of course use sed, but in an interactive
front end?
Regards,
Timo Felbinger
-- 
Timo Felbinger           <Timo.Felbinger at quantum.physik.uni-potsdam.de>
Quantum Physics Group    http://www.quantum.physik.uni-potsdam.de
Institut fuer Physik     Tel: +49 331 977 1793      Fax: -1767
Universitaet Potsdam, Germany

