# Rational mathematical expression too long for overleaf?

first of all, I don't know why this isn't going into LaTeX formatting.. I assumed on this stack exchange that would be easy to do. But yeah, I have this function, and it turns out it evaluates to a pretty nasty rational function of two variables, here t and v. When I put this on my overleaf document, it goes off the page. What can I do?? Can I make the text smaller somehow? How do I do that? Are there any other options? Thanks!!

$$W_{(2)}(t,v)=\frac{t^{2-k}\,v^{k-2}\,\left(t\,v-1\right)\,\left(v-1\right)\, \left(t-v+t^2\,v^2+t^3\,v^2+t^4\,v^2-t^5\,v^2-t\,v-t^4\,v-t^5\,v-t^{3\,k}\, t^2-t^{3\,k}\,t^4+t^2+t^3-t\,t^{3\,k}\,v^2+t^{3\,k}\,t^2\,v+t^{3\,k}\, t^3\,v+t^{3\,k}\,t^4\,v-t^{3\,k}\,t^3\,v^2+t\,t^{3\,k}\,v-1\right)}% {{\left(t-1\right)}^4\,{\left(t+1\right)}^2\,\left(t^4+t^3+2\,t^2+t+1\right)}$$

• What are all these commas in the numerator and denominator? Sep 18 '20 at 0:25
• It's not clear what you mean by "too long for overleaf". Please clarify.
– Mico
Sep 18 '20 at 0:30
• @Bernard I'm not sure. This code was generated by matlab. Sep 18 '20 at 0:52
• @Mico When i copy this code into overleaf, the expression goes off the page. Like, in microsoft word the expression would just start a new line, but with overleaf it is not so. I tied switching it to landscape mode, but it still goes off the page. Sep 18 '20 at 0:52
• @HaKuNaMaTaTa - Please see the answer I just posted, in which I show two possibilities for displaying W_{(2)}(t,v).
– Mico
Sep 18 '20 at 0:53

I suppose it's possible, though not really recommended, to line-break the very long numerator twice and to display W_{(2)}(t,v) as one big fraction.

You would do your readers a big favor if you display the numerator and denominator terms separately.

Either way, I'd get rid of the many \, spacers, and I'd eliminate the many \left and \right directives as they don't actually do anything (except create code clutter).

\documentclass{article}
\usepackage{amsmath} % for 'align*' env.
\begin{document}

$W_{(2)}(t,v)=\frac{\left( \parbox{0.7\textwidth}{\raggedright t^{2-k} v^{k-2} (tv-1) (v-1) [t-v+t^2 v^2+t^3 v^2+t^4 v^2-t^5 v^2-t v-t^4 v-t^5 v-t^{3k} t^2-t^{3k} t^4+t^2+t^3-t t^{3k} v^2+t^{3k} t^2 v+t^{3k} t^3 v+t^{3k} t^4 v-t^{3k} t^3 v^2+t t^{3k} v-1]}\right)}{% (t-1)^4 (t+1)^2 (t^4+t^3+2 t^2+t+1)}$

\bigskip
\noindent
$W_{(2)}(t,v)\equiv A(t,v)/B(t)$, where
\begin{align*}
A(t,v) &= t^{2-k} v^{k-2} (tv-1) (v-1) [t-v+t^2 v^2+t^3
v^2+t^4 v^2-t^5 v^2\\
&\qquad -t v-t^4 v-t^5 v-t^{3k} t^2-t^{3k}
t^4+t^2+t^3-t t^{3k} v^2\\
&\qquad +t^{3k} t^2 v+t^{3k} t^3 v+t^{3k}
t^4 v-t^{3k} t^3 v^2+t t^{3k} v-1]
\end{align*}
and
$B(t)=(t-1)^4 (t+1)^2 (t^4+t^3+2 t^2+t+1)$.
\end{document}

• Wow, good job cleaning up the code. Did oyu do that by hand? IDK what all these /left and /right and comma's are doing in the code. Like i said, the code was generated by MatLab. Your code is much cleaner though. Sep 18 '20 at 0:54
• @HaKuNaMaTaTa - I deleted all \, spacers and the \left and \right modifiers by hand. Encasing the numerator in a \parbox, it became reasonably straightforward to choose some line breaks. It was at that point, though, that I decided it would be much nicer to display the numerator and denominator separately...
– Mico
Sep 18 '20 at 0:58
• @HaKuNaMaTaTa - The \, spacers, well, insert "thinspace". It's just not typographically appropriate, let alone necessary, to insert all those thinspaces.
– Mico
Sep 18 '20 at 1:00
• @HaKuNaMaTaTa - You may want to go through the code and straighten out the way some of the powers of t are displayed. E.g., replace t t^{3k} witht^{3k+1}, etc.
– Mico
Sep 18 '20 at 1:04
• Thanks. I'm going to learn about all the formatting techniques you used here, but it's exactly what I was looking for. U da bomb!! Sep 18 '20 at 1:19

Ì propose this variant layout, with gather* and multlined:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{gather*}
W_{(2)}(t,v) =\frac{t^{2-k} v^{k-2} (tv-1) (v-1)A(t, v)}{(t-1)^4 (t+1)^2 (t^4+t^3+2 t^2+t+1)}, \\
\shortintertext{where}
\begin{multlined}
A(t, v) = t-v+t^2 v^2+t^3v^2+t^4 v^2-t^5 v^2 -t v-t^4 v-t^5 v -t^{3k} t^2-t^{3k}t^4\\
+t^2+t^3-t\, t^{3k} v^2+t^{3k} t^2 v+t^{3k} t^3 v+t^{3k}t^4 v-t^{3k} t^3 v^2+t\, t^{3k} v-1.
\end{multlined}
\end{gather*}

\end{document}


• So many interesting environments I need to learn about.. Thanks man!! Sep 18 '20 at 14:21
• I think the mathtools package, which extends amsmath, should be systematically loaded. B.t.w., I forgot to mention you should not use $$...$$ for displayed equetions, as it is plain TeX syntax, and it can lead to inconsistent vertical spacing with LaTeX. Use the $...$ syntax instead. Sep 18 '20 at 14:35