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?

lockstep
  • 250,273
  • 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. – Willie Wong Nov 09 '10 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 Nov 09 '10 at 18:44
  • @Willie how would I fix it on a case-by-case basis instead? – wrongusername Nov 13 '10 at 02: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. – Willie Wong Nov 13 '10 at 02:53

4 Answers4

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

Stefan Kottwitz
  • 231,401
  • 1
    I had never heard of \DisplayMathSizes Is it part of "plain" LaTeX or another package? – Matthew Leingang Nov 09 '10 at 21:12
  • Thanks! But can you elaborate on what display/text/script/scriptscript sizes are? :P – wrongusername Nov 09 '10 at 21:33
  • 4
    @Matthew: \DeclareMathSizes is defined in latex.ltx and it is explained in source2e.pdf in section 25. – Stefan Kottwitz Nov 09 '10 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 Nov 09 '10 at 22:23
  • 2
    The clearer meta description should be \DeclareMathSizes{<surrounding text size>}{<math text size>}{<math script size>}{<math scriptscript size>}. – kiss my armpit Feb 17 '13 at 07: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.

    – john.abraham Jun 26 '15 at 10:54
  • I'd add @john.abraham note so that the answer is definitely clear. – Emiliano Poggi Feb 02 '17 at 15:54
  • That was awesome! I had to to write a formula in text path mode of tikz and this was the only way I found to be able to change the font size. Thank you very much. – MEDVIS Sep 07 '17 at 15:04
22

You can try \dfrac instead of \frac.

Werner
  • 603,163
Behrouz
  • 221
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.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • Note that code redefining \everymath will conflict with packages that redefine this, like the {mathdots} package. – Charles Stewart Nov 09 '10 at 17:59
  • What's the equals sign for? I've always just used \everymath{blah}... – Willie Wong Nov 09 '10 at 17:59
  • The equals sign is optional, both variants are correct and equivalent. – Philipp Nov 09 '10 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? – wrongusername Nov 09 '10 at 21:47
  • Also, would you be willing to explain what the code does? :) – wrongusername Nov 09 '10 at 21:48
  • 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." :-) – Matthew Leingang Nov 10 '10 at 13:22
  • @wrongusername: see edits. – Matthew Leingang Nov 12 '10 at 14:11
13

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

\begingroup
\everymath{\scriptstyle}
\scriptsize
%your equation
\endgroup
Hendrik Vogt
  • 37,935
  • 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). – Hendrik Vogt Feb 15 '11 at 19:22
  • 1
    What about other sizes? – ahorn Apr 10 '17 at 02:55
  • 1
    @ahorn: There is also \displaystyle, \textstyle, and \scriptscriptstyle. (see this answer: https://tex.stackexchange.com/questions/60453/reducing-font-size-in-equation) – nijoakim Apr 30 '19 at 13:43