9
$\begingroup$

I'd like to change the font that Mathematica uses for output by setting the font of the corresponding style in my stylesheet, but simply overriding the default Output style with

Cell[StyleData["Output"],FontFamily->"Open Sans",FontSize->12]

seems to have no effect.

Is there a way to do this that I'm missing? Is the style used for output something different?


Note that this is not a duplicate of "Set default font for Output", despite the title.

$\endgroup$
6
  • $\begingroup$ @Mr.Wizard: If I understand that, I've got to change StandardForm, but that changes both Input and Output. Is there no way to change just Output? (And what's the Output style for if it has no effect on output?) $\endgroup$
    – orome
    Nov 13, 2012 at 22:24
  • 1
    $\begingroup$ I just read those answers and I too am dissatisfied with them. There are some surprising limitations of the system ("Undo" cough) but this doesn't appear to be one of them as you can select an Output cell and change the font family. I don't know why it is set up this way. $\endgroup$
    – Mr.Wizard
    Nov 13, 2012 at 22:30
  • 1
    $\begingroup$ The earlier question did not concern output styles. The reason you can't do this easily is because Core.nb defines DefaultFormatType -> DefaultOutputFormatType for the output style and this is the StandardForm. You can set DefaultFormatType to some other *Form and change that instead, because modifying StandardForm will also change the input sytle. $\endgroup$
    – rm -rf
    Nov 13, 2012 at 23:18
  • $\begingroup$ @rm-rf I'm sorry, I now realize that is true. I know I have seen the recommendation/instruction to change StandardForm to effect change in "Output" (and "Input") before; that is what I am dissatisfied with. Sorry for unintentionally disparaging your answer! $\endgroup$
    – Mr.Wizard
    Nov 14, 2012 at 0:05
  • $\begingroup$ @rax I notice that you did not Accept an answer to this question. Did you find that the method I suggested has problems or limitations? Is there an issue I can attempt to address to improve my answer? $\endgroup$
    – Mr.Wizard
    Aug 14, 2014 at 16:36

2 Answers 2

8
$\begingroup$

After a bit of style sheet spelunking I believe I have a solution.

One reads in Core.nb under the FormatType Styles section:

The cells below define styles that are mixed in with the styles of most cells. If a cell's FormatType matches the name of one of the styles defined below, then that style is applied between the cell's style and its own options. This is particularly true of Input and Output.

From this it becomes clear why the styles one creates for Input and Output are not respected. That leads me to my proposed method. The template for the private style sheet is as follows:

Mathematica graphics

Key in the options for the top cell, placed above the base definitions cell, is:

FontFamily -> Inherited

However one should start with the original definition from Core.nb and add/change FontFamily -> Inherited or important settings such as InputAutoReplacements will be lost. You can use this code to generate the complete Cell needed:

CellPrint @ Cell[StyleData["StandardForm"], ##] & @@
  (CurrentValue[{"StyleDefinitions", "StandardForm"}] /.
     (FontFamily -> _) :> (FontFamily -> Inherited))

(Evaluate this in a standard Notebook, then copy and paste the result at the very top of the Style Sheet.)

This changes the way that the "Input" and "Output" styles work. Now you create font style cells for both, e.g.:

Cell[StyleData["Input"],
 FontFamily -> "Courier"
]

Cell[StyleData["Output"],
 FontFamily -> "Trajan Pro"
]

And prestidigitonium!

Mathematica graphics

$\endgroup$
8
  • $\begingroup$ To make this robust it will at least be necessary to consider any other styles that rely on StandardForm and also the different Screen and Printing Environments. $\endgroup$
    – Mr.Wizard
    Nov 14, 2012 at 0:01
  • $\begingroup$ +1 brilliant. Had forgotten about the ordering of cells in stylesheets. $\endgroup$ Nov 14, 2012 at 0:11
  • $\begingroup$ Addendum: this doesn't operate with quite the mechanism that I first thought, but I believe it still works. However, the content of the first cell should be the entire definition for "StandardForm" from Core.nb except for the FontFamily line, rather than the stub shown in this answer. I'll revisit this tomorrow and do some more testing, then update the post. $\endgroup$
    – Mr.Wizard
    Nov 14, 2012 at 1:58
  • $\begingroup$ I had only done some toy testing and didn't notice any issues with it. What led you to write the addendum? $\endgroup$ Nov 14, 2012 at 2:10
  • $\begingroup$ @Mike on my system I'm losing some of the proper formatting of e.g. Input cells with the simple code shown in the post. (Put another way, not only is the font reset but so is everything else.) I can't rule out that I've just made a mistake but I'm too sleepy to work through it now. $\endgroup$
    – Mr.Wizard
    Nov 14, 2012 at 2:13
7
$\begingroup$

Not sure if there is a straight forward way but here is one way that works.

Edit the private styles of your notebook as per these grabs:

enter image description here

enter image description here

And now your output is Comic Sans :)

enter image description here

You can also:

SetOptions[EvaluationNotebook[], 
 CommonDefaultFormatTypes -> {"Output" -> OutputForm}]

but you still need to make your changes to the OutputForm style.

$\endgroup$
12
  • $\begingroup$ +1 for CommonDefaultFormatTypes which I either haven't learned or forgot, but I recommend you use a custom style e.g. "MyOutput" instead of OutputForm or you get the ugly 2D text formatting. $\endgroup$
    – Mr.Wizard
    Nov 13, 2012 at 23:16
  • $\begingroup$ -1 for Comic Sans, +2 for a good solution. :) $\endgroup$
    – rcollyer
    Nov 13, 2012 at 23:23
  • $\begingroup$ Hm... I see that my recommendation is not valid. That makes this answer significantly less useful IMHO unless there is another work-around to avoid the text-terminal 2D output. $\endgroup$
    – Mr.Wizard
    Nov 13, 2012 at 23:23
  • $\begingroup$ @rcollyer I'm not sure it's really a solution (yet?); I don't think people want to have to use OutputForm -- at least I don't. $\endgroup$
    – Mr.Wizard
    Nov 13, 2012 at 23:24
  • $\begingroup$ @Mr.Wizard correct me if I'm wrong, isn't OutputForm the default for output cells? $\endgroup$
    – rcollyer
    Nov 13, 2012 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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