TransWikia.com

Issue using resizebox within equation and split environments

TeX - LaTeX Asked by Adam_G on June 14, 2021

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+ttstextnormal{-}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?

3 Answers

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+ttstextnormal{-}experience(subject)) + 
        quality(w_{i-1}) + mathcal{A}% 
    end{split} 
    $
}
end{equation}

end{document}

enter image description here

Correct answer by Vladimir on June 14, 2021

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.

Answered by egreg on June 14, 2021

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}

Answered by David Carlisle on June 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP