Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am using Grid to document a demo I have. i.e. I am writing the documentation of the demo as a help option, which will display information when clicked on.

Everything is working well. I am using the following pattern to do that:

help=Block[{a,b,c,.....}, (*Block is needed to prevent $nnn in symbols showing*)

  Style[TraditionalForm[Grid[{

    {"some text here, all in string"},
    {equation here using symbols a,b,c, as in  a=b+c},
     ...
  ]], FontFamily -> "Times"]

 ]

Then later on, when I want to display information, I simply display the help symbol. The nice thing also about this, is that I typeset these all once, in the initialization section. So that it is fast to display before as the help is typeset once and stored in the symbol.

The final result is really nice. The same as Latex. I see no difference at all.

The only glitch, is when I have long text, I'd like it to be full justified. Using normal Grid Alignments does not help here, and so I have to use TextCell, with the TextJustification->1 for it to work.

But the only problem is that some of the text I have might include subscript, like this one example:

enter image description here

And you can see that the TextCell does not like that one part (I understand also why it is not happy). I am trying to see if I can use TextCell (as it seems the only way to have text justified in a grid) and at the same time use little bit of subscript and such in the string. If there is such a trick.

For the actual math part of the documentation, I can split the math from the text like I show above in the rest of the grid. But there are some parts, where I need to write all the text in one place, and use little bit of subscript and such in there. But also be able to text justify everything so it looks nice.

In a way, this is like I do in Latex, where the main equations go as centered form, and the description around them has very little math. I am trying to emulate this with the help of Grid.

If I do not use textCell, this is the result:

enter image description here

So it works now, but text is not justified inside the grid. It does not look as nice.

Here is the code, if someone wants to try something. I tried many things, but so far, no luck. below is small example, left many things out. I have to keep the ContentSize fixed there since the overall size is fixed for display.

Manipulate[
 Style[TraditionalForm[Grid[{
     {"let \!\(\*SubscriptBox[\(u\), \(n\)]\) be the outward normal \
derivative on the boundary"}
     }, Frame -> All]
   ], FontFamily -> "Times"],
 ContentSize -> {300, 475}
 ]

I do not want to use GraphisGrid and rasterize things and such.

And this will be used for a demo that runs in CDF plugin, so the following symbols can't be used :

SetOptions, ToExpression, Symbol , $Context, SetAttributes, Clear, Unprotect, DownValues, UpValues, OwnValues and packages not allowed to be used or created also. Also, Manipulate[] has to be the most outside construct.

Thank you,

Note: TextJustification -> 1 does alignment on BOTH ends. Using LineIndent->0 only does it on one side. Below is an example of the difference.

enter image description here

share|improve this question
    
see below. You just need to fix the line indenting. For some reason the default is not zero within Grid. –  Mike Honeychurch Jan 31 '12 at 7:04
add comment

2 Answers 2

up vote 7 down vote accepted

You can also supply a Row to the TextCell where the elements in the row can be a mix of strings and other expressions, so you could split the whole text into string fragments and bits of maths like this

TextCell[Row[{"This is some text ",
  HoldForm[Subscript[a, b]], 
  ". This is more text"}], TextJustification -> 1]

To show that it works:

Panel[Style[TraditionalForm[Grid[{
    {"Boundary Conditions", SpanFromLeft},
    {TextCell[
       Row[{"This is some text, this is some text, this is some text ", 
       HoldForm[Subscript[a, b]], " this is more text."}], 
      TextJustification -> 1], SpanFromLeft},
    {"West", HoldForm[u = \[Alpha][y]], HoldForm[Subscript[u, n] = \[Alpha][y]]}},
   Frame -> All]],
  15, FontFamily -> "Times"], 
 ImageSize -> 250]

Mathematica graphics

share|improve this answer
    
Nice. +1 I have overlooked that use of TextCell even though it is in More information... –  Mr.Wizard Feb 1 '12 at 1:48
add comment

Add the following to your Style options:

Manipulate[
 Style[
 TraditionalForm[
 Grid[{
...
     }, Frame -> All]
   ], 
FontFamily -> "Times",
LineIndent->0,
TextJustification -> 1,
LinebreakAdjustments -> {1, 12, 12, 1, 1}],

ContentSize -> {300, 475}]

LineIndent->0 fixes the left indenting of the 2nd and subsequent lines which is due to the default indenting being set to 1. To get everything else exactly how you want it you will probably have to play around with LinebreakAdjustments.

share|improve this answer
    
you can add TextJustification to your Style options but I suspect you will also need to play around with LinebreakAdjustments –  Mike Honeychurch Jan 31 '12 at 7:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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