Within a larger document with lots of formulas, I use a self-defined "Example" environement for illustrational purposes from time to time. In order to better set it apart from the rest of the text, I have decided to use another font family within those example surroundings.

But - and here's my problem - the code I use only changes the text font. How can I use another math font for the formulas within the defined enviromenent?

\newenvironment{Ex}{\fontfamily{ppl}\selectfont\par\vspace{1ex}\begin{quote}\textbf{Example: }}{\end{quote}\par}

Thanks in advance for any help!

Edit: More details regarding my question. Let me illustrate it with an example:

[Here's some default-formatted text]
     [some example text I want in another font family]
      and now I need a formula within the example-environement set in a different style than the standard layout to underline it's still part of the example-surrounding
     [maybe some more text within the example]
    [And now back to the main body of the text set once again in the default layout]

I hope this clarifies (rather than confuses) my question.

  • @Verena: Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting.
    – lockstep
    Commented Mar 30, 2011 at 12:28
  • It is possible to define math versions (like \boldmath). But if you want a more specific answer you will have to give much more detailed informations about your actual setup. Btw: I don't think that is a good idea to use too much font families in a document. Commented Mar 30, 2011 at 12:44
  • You already wrote that you want another font in the example. The question is how exactly should the math look. Which fonts should the letters, the numbers and the various symbols use? Make a small complete document which shows equation in the look you want for your example environment. Commented Mar 30, 2011 at 13:03
  • @Ulrike: Right, sorry. Now I get it. Basically, I'm not picky as to the exact font type I want to use. Ideally, I'll just go for one that is easily accessible, already present in my MikTeX distribution (if such a thing is possible?) and works well with some font type I can choose via the \fontfamily command. Does an answer to my question depend on which mathfont I want to use? I was hoping for a general solution that does not depend on the precise choice of a certain mathfont. I've prepared an example as pdf now as you asked me to but... how do I share it with you?
    – user4544
    Commented Mar 30, 2011 at 13:22
  • A pdf example is not useful. Make a small complete latex document. And no: it is not easy and there is no general solution. You mentioned the family ppl so I suggest that you search for mathpazo.sty on your machine, open it in your editor and look what it does to setup the math. Commented Mar 30, 2011 at 13:32

2 Answers 2


You can do this using the unicode math package. You need to use xelatex or lualatex for this to work (rather than just pdflatex). As a rather simple example, the following switches from italic to upright font within the example environment.





  E = m c^2

A famous equation is
  E = m c^2

  E = m c^2


(You need to have the STIX fonts for this particular example to work.) This produces:

changing maths font

For more on the syntax, I recommend that you read the unicode-math documentation. I should also warn you that changing the font several times in a document can slow down the compilation time considerably. It might not, I'm not sure exactly what it is that causes the slow-down, but on some documents where I change maths font a lot then I find that I have to disable the font changing when writing the document and only enable it for the final run.


With the instructions below, only in Example environment the main font (of text and math formulas) will be changed into computer modern sans one.









However, dots and commas are not correct: their output is colon and semicolon because of the position of these digits into the computer modern sans font table. You may correct this error with


although, in my opinion, it still sounds like an "error".

You must log in to answer this question.