67

I find that whenever I'm typing some equations into a document, and the equation gets a bit complex (let's say a fraction in a parentheses, squared, inside a square root, inside a fraction), the variables and whatnot that I put inside the "inner" parts of the equation get really, really, tiny. But if I set the font size to something a lot larger, the stuff on the "inside" gets tolerable, but the stuff on the "outside" (e.g., "x = lots of junk", x would be in the "outside") become gigantic!

How can I make it more pretty like my textbooks, where all variables are at the same size regardless of whatever parentheses/fractions/radicals they're under?

4
  • 2
    Matthew Leingang provided you with a good solution, but personally I would recommend fixing this on a case by case. Setting \everymath will also make all in-line math "big", which can make interline spacing very large to accomodate all the large expression. I think that doesn't look very good. Commented Nov 9, 2010 at 17:58
  • 1
    You can also consider rewording your equations. For example if you have x = \sqrt{ complicated stuff + complicated stuff } you can say x = \sqrt {A + B} where A = complicated stuff and B = complicated stuff.
    – Aditya
    Commented Nov 9, 2010 at 18:44
  • @Willie how would I fix it on a case-by-case basis instead? Commented Nov 13, 2010 at 2:06
  • 3
    Put \displaystyle inside the "group" with the thing you want big. For example, compare the in-line expressions $\frac{1}{x + \frac1x}$ and $\displaystyle \frac{1}{x - \frac1x}$ and $\displaystyle \frac{1}{x - {\displaystyle \frac1x}}$ to see how the scope of the \displaystyle command works. Commented Nov 13, 2010 at 2:53

4 Answers 4

46

To get equal sizes, you could use \DeclareMathSizes in your preamble. The syntax is

\DeclareMathSizes{display size}{text size}{script size}{scriptscript size}.

You could simply set all to your default font size. In this example:

\documentclass[10pt]{article}
\begin{document}
\[
  x = \frac{1}{x + \frac{1}{x + \frac{1}{x}}}
\]
\end{document}

where you firstly get different sizes:

alt text

inserting this line

\DeclareMathSizes{10}{10}{10}{10}

changes the output to:

alt text

8
  • 1
    I had never heard of \DisplayMathSizes Is it part of "plain" LaTeX or another package? Commented Nov 9, 2010 at 21:12
  • 4
    @Matthew: \DeclareMathSizes is defined in latex.ltx and it is explained in source2e.pdf in section 25.
    – Stefan Kottwitz
    Commented Nov 9, 2010 at 22:20
  • 2
    @wrongusername: those sizes are used in the style with the same corresponding name. Thus display size is used for displayed equations, text size for in-line math, script size for subscripts and superscripts (indexes, exponents), scriptscript size for subscripts of subscripts etc.
    – Stefan Kottwitz
    Commented Nov 9, 2010 at 22:23
  • 2
    The clearer meta description should be \DeclareMathSizes{<surrounding text size>}{<math text size>}{<math script size>}{<math scriptscript size>}. Commented Feb 17, 2013 at 7:17
  • 12
    To anyone who tries using \DeclareMathSizes and finds that "it doesn't work": The first bracket has to coincide with the font size of your document. That is \DeclareMathSizes{font size of your document}{math font size}{script size}{scriptscript size}. If the first bracket doesn't match your document font size, \DeclareMathSizes doesn't do anything. Commented Jun 26, 2015 at 10:54
22

You can try \dfrac instead of \frac.

2
  • 3
    Note that \dfrac is not defined by default in the standard document classes. You would require a package like amsmath.
    – Werner
    Commented Feb 16, 2012 at 6:56
  • 3
    Exactly what I was looking for!
    – Vivi
    Commented Mar 2, 2012 at 22:24
19

Put this in your preamble, but after all \usepackage commands:

\everymath=\expandafter{\the\everymath\displaystyle}

This will effectively add \displaystyle to every (inline) math made environment, making all math look like the math that's displayed.

Edits: Thanks to Charles for pointing out that this can/should be done in a way which doesn't clobber the existing \everymath token list, in case it's already nonempty. And as Willie says the = is optional. I like using it; it just reminds me that there is some assignment going on.

Edit 2: The OP asked for a detailed explanation. I'll try.

First, remember that \everymath is a token list that is inserted in front of every math mode material. So if you type \everymath={\text{Here comes the math: }} you will get that in front of every equation. \everymath={\displaystyle} does something a little more productive by inserting \displaystyle in front of each math mode.

The trouble arises when you or some other package has already modified \everymath. So we need to append \displaystyle to the \everymath token list. In pseudo-TeX you want to say:

\everymath={\currentcontentsof{\everymath}\displaystyle}

The TeX implementation of the pseudo-macro \currentcontentsof is \the. So a closer approximation is this:

\everymath={\the\everymath\displaystyle}

But this is going to be trouble, When TeX reads a token list declaration it just reads the tokens without expanding. That is, the \the will be expanded not here but at the the first encountered math mode. That will cause TeX to try to expand \everymath, which will need an expansion of \everymath inside it. Oops! Infinite loop.

So you need the \the expanded before you save the token list. Hence \expandafter:

\everymath=\expandafter{\the\everymath\displaystyle}

When TeX reads \everymath=, it expects a token list. But instead, it gets \expandafter, which says "hold on to the next token, expand the following token, then put the held token back in place and expand normally." So the { token is deferred while \the is expanded. \the needs another token to work, so the next token \everymath is read. This replaces the two tokens \the\everymath with the tokens currently in \everymath. Now that { is put back in place, and TeX can read a normal token list declaration.

Other TeXnicians may correct that answer, but it's how I understand things.

7
  • Note that code redefining \everymath will conflict with packages that redefine this, like the {mathdots} package. Commented Nov 9, 2010 at 17:59
  • What's the equals sign for? I've always just used \everymath{blah}... Commented Nov 9, 2010 at 17:59
  • The equals sign is optional, both variants are correct and equivalent.
    – Philipp
    Commented Nov 9, 2010 at 19:37
  • Interestingly, adding this made a horizontal line I had placed at the beginning of the document, along with a big skip, make the rest of the page go to the second page. Cutting out both the horizontal line and the big skip returned all text back the way it was. Anyway to fix this? Commented Nov 9, 2010 at 21:47
  • 1
    @wrongusername: Not sure what would cause that, but of course making all math display math will obviously change line heights. TeX has a complicated algorithm for breaking lines into pages, and this could conceivably confuse it. As for explaining the code, I will try with a future edit. \expandafter and other expansion tweaks are in the double-dangerous-bend category (referring to the icons in the TeXBook which indicate stuff to be skipped until one is really ready). This answer I adapted from something in Appendix D, "Dirty Tricks." :-) Commented Nov 10, 2010 at 13:22
13

You can use \everymath locally by inserting \begingroup and \endgroup as this

\begingroup
\everymath{\scriptstyle}
\scriptsize
%your equation
\endgroup
3
  • 2
    Welcome to tex.sx! A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). Commented Feb 15, 2011 at 19:22
  • 1
    What about other sizes?
    – ahorn
    Commented Apr 10, 2017 at 2:55
  • 1
    @ahorn: There is also \displaystyle, \textstyle, and \scriptscriptstyle. (see this answer: tex.stackexchange.com/questions/60453/…)
    – nijoakim
    Commented Apr 30, 2019 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .