3

I have an equation below that is wrapped in an equation and split environment. Because the equation is long, it will run over the margins, so I used resizebox. According to this SO question I need to explicitly enter math mode when in the resizebox environment. However, I still get an error. The document compiles (on Overleaf, at least), but I would like to get rid of the error so I can share the tex file.

The code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{parskip}
\usepackage[numbers]{natbib}
\bibliographystyle{plainnat}
\usepackage{graphicx}

\begin{document}

\begin{equation} \label{eq:word} \resizebox{\textwidth}{!}{% \begin{split} $quality(w_{i}) = & \log(1 + \operatorname{similarity}(a,b)) + \log(1 + familiarity(w_{i})) \ & + \log(1+familiarity(\min{(e,3)})) + \log(1 + expectedness(w_i|w_{i-1})) \ & - \log(1+tts\textnormal{-}experience(subject)) + quality(w_{i-1}) + \mathcal{A}$% \end{split} } \end{equation}

\end{document}

Throws the error:

Pakage amsmath Error: \begin{aligned} allowed only in math mode
Missing $ inserted
Missing { inserted
Missing } inserted

How can this error be resolved?

Adam_G
  • 816
  • note quality should be in \mathrm as the math italic font intentionally makes adjacent letters look like a product of variables not a word. scaling of equations (or text generally) should only be a last resort and even then avoided, it produces inconsistent ad potentially unreadable font sizes) – David Carlisle Sep 25 '20 at 15:49

3 Answers3

4

The environment split requires a math mode:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{parskip}
\usepackage[numbers]{natbib}
\bibliographystyle{plainnat}
\usepackage{graphicx}

\begin{document}

\begin{equation} \label{eq:word} \resizebox{\textwidth}{!}{% $ \begin{split} quality(w_{i}) = & \log(1 + \operatorname{similarity}(a,b)) + \log(1 + familiarity(w_{i})) \ & + \log(1+familiarity(\min{(e,3)})) + \log(1 + expectedness(w_i|w_{i-1})) \ & - \log(1+tts\textnormal{-}experience(subject)) + quality(w_{i-1}) + \mathcal{A}% \end{split} $ } \end{equation}

\end{document}

enter image description here

Vladimir
  • 436
  • Interesting! Thanks! Just out of curiosity how does it work with the first % outside split and the second one inside it? – Adam_G Sep 25 '20 at 15:38
  • @Adam_G, % - this is the symbol to comment out the line. In this context, it is used in TeX to remove extra spaces in text mode. But the last % is not needed in the specified place, since it is still math mode. – Vladimir Sep 25 '20 at 15:42
  • Ah, I never connected the commenting use with this use. Thanks! – Adam_G Sep 25 '20 at 15:49
3

Why resizing? One line more is sufficient.

\documentclass{article}
\usepackage{amsmath,amssymb}

\makeatletter \newcommand{\tf}[1]{\operatorname{#1}} % text function \newcommand{\tv}[1]{\mathit{\newmcodes@ #1}} % text variable \makeatother

\begin{document}

\begin{equation}\label{eq:word} \begin{split} \tf{quality}(w_{i}) &= \log(1 + \tf{similarity}(a,b)) + \log(1 + \tf{familiarity}(w_{i})) \ &\quad + \log(1+\tf{familiarity}(\min{(e,3)})) \ &\quad + \log(1 + \tf{expectedness}(w_i|w_{i-1})) \ &\quad - \log(1+\tf{tts-experience}(\tv{subject})) + \tf{quality}(w_{i-1}) + \mathcal{A} \end{split} \end{equation}

\end{document}

I chose to represent function names with \operatorname, so upright, and variables in italics (but text italic, rather than math italic). The \newmcodes@ trick is to make hyphens also in variables to be normal and not minus signs.

enter image description here

I wouldn't align the operation signs under the equals. In case you like it better, here's the correct code.

\documentclass{article}
\usepackage{amsmath,amssymb}

\makeatletter \newcommand{\tf}[1]{\operatorname{#1}} % text function \newcommand{\tv}[1]{\mathit{\newmcodes@ #1}} % text variable \makeatother

\begin{document}

\begin{equation}\label{eq:word} \begin{split} \tf{quality}(w_{i}) ={} & !\log(1 + \tf{similarity}(a,b)) + \log(1 + \tf{familiarity}(w_{i})) \ {}+{} & !\log(1+\tf{familiarity}(\min{(e,3)})) \ {}+{} & !\log(1 + \tf{expectedness}(w_i|w_{i-1})) \ {}-{} & !\log(1+\tf{tts-experience}(\tv{subject})) + \tf{quality}(w_{i-1}) + \mathcal{A} \end{split} \end{equation}

\end{document}

enter image description here

The \! bits are necessary because of the “empty atom” that split inserts after &, which causes a following operator to be preceded by a thin space that we need to remove.

egreg
  • 1,121,712
2

Scaling equations makes incompatible font sizes and is usually best avoided.

Here the equation is wider than it need be as math italic spaces out the letters to make them a product of variables, not a word, with that change it already fits on the page, but the equation number is moved down, here I add an additional line break so that the equation number can stay centred.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{parskip}
\usepackage[numbers]{natbib}
\bibliographystyle{plainnat}
\usepackage{graphicx}

\begin{document}

\begin{gather} \label{eq:word} \begin{split} \operatorname{quality}(w_{i}) ={}\hspace{-50pt}&\ &\log(1 + \operatorname{similarity}(a,b)) + \log(1 + \operatorname{familiarity}(w_{i})) \ & + \log(1+\operatorname{familiarity}(\min{(e,3)})) + \log(1 + \operatorname{expectedness}(w_i|w_{i-1})) \ & - \log(1+\operatorname{tts-experience}(\mathrm{subject})) + \operatorname{quality}(w_{i-1}) + \mathcal{A} \end{split} \end{gather}

\end{document}

David Carlisle
  • 757,742