MathGroup Archive 1998

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

Search the Archive

Re: Formatting and Style Sheet woes

  • To:
  • Subject: [mg11960] Re: Formatting and Style Sheet woes
  • From: "P.J. Hinton" <>
  • Date: Fri, 10 Apr 1998 01:03:48 -0400
  • Organization: Wolfram Research, Inc.

On 9 Apr 1998, Andrew J Fortune wrote:

> I am a Mathematica newbie, so please forgive me if the following seem
> like  elementary questions. I have looked through the Mathematica Book,
> but the  correct answers seem to elude me. They are mainly to do with
> formatting and  styles, and it seems that I can't come to grips with
> the basic philosophy  behind the formatting functionality. If you can
> answer these, if possible  could you please also incorporate references
> to the Mathematica Book ?
> The questions are as follows :
> (1) I am trying to create a text cell (as per the example in section
> 2.10.1  of the Mathematica Book). When I type in a sentence in a new
> notebook, and  then hit Ctrl-Shift-E to show the expression, I get the
> following :
> Cell[BoxData[
>     RowBox["This", " ", "is", " ", "a", " ", "text", "  ",
>       RowBox["cell", "."]]], "Input"]
> But I was expecting something like the expression quoted in that section
> (i.e. "Cell["This is a text cell", "Text"]).
> I have tried the following :
> (a) I noticed that  when I dropped down the Format/Style sub-menu, that 
> "Input" was ticked. So I ticked the "Text" option (I tried by selecting
> that row in the menu, and also by hitting Alt-7), and tried again. It
> came  out the same way as before, and I noticed that the style was set
> back to  Input. It seemed to ignore my request to change the style of
> the current  cell to Text.

This sounds as if you are trying to set the cell's style before the cell
is created.  Selecting a style from the Format -> Style menu or through
keystrokes should work fine as long as the very next action you take
after doing this is entering the first character that will be placed in
your cell.  If you hit other keystrokes or try to manipulate the text
insertion cursor, the new cell's style will be that of the
DefaultNewCellStyle option on the option inspector.

> (b) I tried the Format/Edit Style Sheet option, but I didn't know which
> is  the correct cell to update. So, I tried a few of them, but none of
> them  seemed to work. In other words, I make the changes and save
> Default.nb.  Then I open a new notebook, and the style persistently
> stays as "Input".  How can I change the style of the cell data (for the
> Default style sheet)  to Text ?

Where are you saving the Default.nb file?  It needs to be placed in one
of the directories on the front end's style sheet path.  The locations
the front end searches by default are:


These paths are arranged in the order that the front end searches.
> (2) It doesn't always seem to work the same way when I set the style to 
> Section. If I open up a new notebook, and straight away set the Section
> style, it behaves as expected (i.e. bold with a bullet). However, if I 
> start typing with the default Input style (as previously discussed),
> and  then change to Section style, the Font size increases but it
> doesnt become  Bold, neither do I get the square bullet on the left of
> the heading. In  fact when I do a Show Expression, it tells me that it
> has been formatted  using BoxData. The style of the RowBox is set to
> Section, but the overall  Cell style is still Input.

I will probably need a specific example to get a picture of what's going
on here.  I suspect that there may be something subtle here that is
causing a FormatType override.  If you can send me a copy of the Cell
expression before and after you set the cell style to Section, I would be
willing to take a look at it.
> (3) I find the Options Inspector confusing. I open it, and select the 
> Formatting options and then the Font options. When I click on the arrow
> on  the right, I expect to get a list of fonts, however I just get the
> one  entry "Automatic". What does this mean ?

The meaning depends on the scope that you have set the option inspector.
The option inspector can be an intimidating beast, but if you keep a
few simple principles in mind, you can avoid getting in over your head.

1) Each cell in a Mathematica notebook can be represented as a kernel
expression with one or two arguments and a set of options:

	1) without a style 	Cell[contents, options]

	2) with a style         Cell[contents, style, options]
2) Notebooks can be represented as kernel expressions that are lists of

	Notebook[{cells}, options]

3) Styles for cells are specified in notebooks of StyleData cells:

	Cell[StyleData[style], options]

which are stored in a style sheet notebook expression.  

4) If nothing is specified at any of the above levels, then the property
is inherited from the Global level, which is coded into the notebook
front end and can be adjusted by the user when the option inspector's
scope is set to Global.  This information is written out to the front
end's init.m file rather than in any notebook.

5) There is an inheritance mechanism that binds these pieces together.

o A cell which does not contain an explicit option setting in its in its
own cell expression, style sheet prototype, or parent notebook
expression will inherit its properties from a globally defined style. 
The front end has its own internal default values, and any user
adjustments made while the option inspector scope is set to Global will
be recorded in the front end init.m file.

A good example of this behavior is the "Text" cell style.

	Cell["Here is some text", "Text"]

It has no explicit font setting in its style sheet prototype, so it
inherits the Global font setting for the front end, which is Times. 

We can override this on a cell-by-cell basis with an explicit option

	Cell["Here is some text", "Text", FontFamily -> "Helvetica"]

o A cell which uses a style which does not contain explicit option
settings can inherit the option from the notebook expression or
"Notebook" prototype in the style sheet if so specified. 

The notebook expression:

Notebook[{Cell["Here is some text", "Text"]}, FontFamily -> "Helvetica"]

will use Helvetica instead of Times because the Notebook level option
overrides the global setting.

We could also make the default font for the notebook be Helvetica when
no option is explicitly mentioned by edting the StyleData expression
for "Notebook" in a style sheet.

  	  FontFamily -> "Helvetica",

o Any options set for a StyleData cell will be inherited by any cell
which uses that style, unless the cell expression contains an explicit
setting for that option.  For example, a cell like

	Cell["This is a title", "Title"]

uses the 36 pt. Helvetica-Bold font because the Default.nb style sheet
prototype for the Title Cell looks like: 


If we add an explicit option for the font family in the cell expression,
we can override the font used.  All other properties from the style
sheet prototype will be preserved.

	Cell["Here is some text", "Title",

o Beware the option setting


in a StyleData expression.  This means that a FormatType mix-in will
occur in that cell.  Consider the prototype for Input:


When you start typing text an Input cell, it will begin using whatever
DefaultInputFormatType resolves to.  The resolution occurs in an
aggregate option often set at the global level.

	CommonDefaultFormatTypes->{"Input"->StandardForm, ...}

This means that the settings for StandardForm will override options set
at the Cell level and higher.  So, if you want to change the font used
in "Input" style cells, you need to edit the prototype for
"StandardForm" rather than the prototype for "Input". This is probably
one of the most difficult aspects of the inheritance mechanism to

You can also check Deja News for other postings that I have made to this
group to clarify various facets of this subject.

P.J. Hinton
Mathematica Programming Group  Wolfram
Research, Inc.        
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: Interpolation ...
  • Next by Date: RE: List as variable
  • Prev by thread: Formatting and Style Sheet woes
  • Next by thread: FourierTransform rect function