0

I would like to display all inline maths expressions in displaystyle, but without typing \displaystyle{...} everytime I insert a math expression into a block of text. How can we do that at the preamble level?

I would also need a command to temporarily turn off the automatic displaystyle in some cases, if a math expression is a bit to big for the text.

Here's a MWE to try:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\begin{document}

This is a simple test; $\sqrt{y(x)} = x_1^3 - a , x^2$ or $\displaystyle{\sqrt{y(x)} = x_1^3 - a , x^2}$. Or again this is a test: $c^{-2}$ is of order $\displaystyle{c^{-2}}$. This is a tensor: $\tensor{T}{{\mu \nu}^{\lambda}}$ or $\displaystyle{\tensor{T}{{\mu \nu}^{\lambda}}}$.

\end{document}

Cham
  • 2,304
  • 1
    \displaystyle does not take an argument, so you can already dispense with the braces { }. If you really wanted that, \everymath{\displaystyle} in the preamble. – Steven B. Segletes Feb 18 '21 at 15:22
  • 1
    I would add that any time a displaystyle equation looks different than the textstyle equivalent, it is because the displaystyle version is too big to fit in a normal line of text-height. – Steven B. Segletes Feb 18 '21 at 15:25
  • @StevenB.Segletes, yes, I know that. But if the equation is really that big, I would display it in a normal math way, not inline. Also, what to do if you want to revert to the default way, for a given inline math expression? – Cham Feb 18 '21 at 15:30
  • My answer addresses this question. – Steven B. Segletes Feb 18 '21 at 15:31
  • If you do do this then you definitely want $\displaystyle...$ not $\displaystyle{....} otherwise white space will be wrong for inline math. This is a duplicate though see https://tex.stackexchange.com/a/323375/1090 – David Carlisle Feb 18 '21 at 17:42

1 Answers1

4

\everymath{\displaystyle} will force math mode into display style all the time. To temporarily overcome it, you can reset that in the scope of a group, as in {\everymath{}...}.

As I noted in a comment, the reason displaystyle is typically only used for display math is that, when it differs from textstyle, it is because it is too big to fit in one vertical line height. As a point of additional note, \displaystyle does not take an argument, but is a declaration that persists through the scope.

EDITED to provide toggling macros.

\documentclass{article}
\newcommand\defaultstyle{\everymath{}}
\newcommand\mystyle{\everymath{\displaystyle}}
\mystyle
\begin{document}
Hi $\frac{x}{y}$

\defaultstyle$\frac{x}{y}$ is back to textstyle

\mystyle$\frac{x}{y}$ am now back to displaystyle \end{document}

enter image description here

  • I suspect there's a simpler way in reverting to the default, instead of typing a group for a whole text sentence. – Cham Feb 18 '21 at 15:33
  • 1
    @Cham You can type \everymath{} without a group; however, then you will have to reactivate it later with \everymath{\displaystyle}. If you expect your groups to be large in scope, another alternative for better source-code visuals is to use \begingroup...\endgroup instead of {...}. – Steven B. Segletes Feb 18 '21 at 16:07
  • I would like to prevent this. Is there a command (or a custom macro) that revert to the default text style? For example, something like this: "Text string $\defaultstyle x^2 - x_3$ text string". – Cham Feb 18 '21 at 16:10
  • 1
    @Cham \newcommand\defaultstyle{\everymath{\displaystyle}} in the preamble. Then, \defaultstyle in the document. – Steven B. Segletes Feb 18 '21 at 16:14
  • I'm not convinced. I suggest that you edit your answer to show how this works. – Cham Feb 18 '21 at 16:16
  • 1
    @Cham Perhaps I misunderstood your desired syntax. I have provided the edit you requested, giving you two toggles: \mystyle and \defaultstyle. Of course, you can name them whatever you want. – Steven B. Segletes Feb 18 '21 at 16:52
  • Ok, this works. But you then need to invoke the "mystyle" after each time you used "defaultstyle". I would like to prevent that. Maybe this isn't possible? – Cham Feb 18 '21 at 16:55
  • 1
    @Cham The way to avoid it is to put it in a group {\defaultstyle...}. Otherwise, LaTeX has no way of knowing when to stop. – Steven B. Segletes Feb 18 '21 at 17:05