# How can I break equations in smaller pieces?

Instead of writting very long lines to create complex equations it would be great to use variables to substitute smaller chunks...

A simple example:

$\frac{ \sqrt{ \mu(i)^{ \frac{3}{2}} (i^{2} -1) } } { \sqrt{\rho(i) - 2} + \sqrt{\rho(i) - 1} }$


It would be done something like this:

A = \sqrt{ \mu(i)^{ \frac{3}{2}} (i^{2} -1) }
B = \sqrt{\rho(i) - 2}
C = \sqrt{\rho(i) - 1}
$\frac{ A } { B + C }$


And the result would be the same but the code easier to read with more complex examples.

How can I define easily these substitutions or parameters? or using any specialized package?

PD: there are other questions at Tex.StackExchange asking how to split an equation in several lines, but this is not the same.

## 1 Answer

You sure can, because TeX is a macro expansion language:

$\newcommand\cA{\sqrt{ \mu(i)^{ \frac{3}{2}} (i^{2} -1) }} \newcommand\cB{\sqrt{\rho(i) - 2}} \newcommand\cC{\sqrt{\rho(i) - 1}} % \frac{ \cA } { \cB + \cC }$


I prefer using a prefix for the “chunks” in order not to clobber already defined macros (you'd be warned anyway, because of \newcommand).

Since $...$ forms a group, those macros will become undefined at the end of the display.

A different option, with math active characters (but more risky):

\documentclass{article}
\usepackage{amsmath}

\newcommand{\chunk}{%
% #1 is a letter, #2 the replacement text
\begingroup\lccode~=#1\lowercase{\endgroup\def~}{#2}%
\mathcode#1="8000
}

\newenvironment{abbrev}{}{}

\begin{document}

$\chunk{A}{\sqrt{ \mu(i)^{ \frac{3}{2}} (i^{2} -1) }} \chunk{B}{\sqrt{\rho(i) - 2}} \chunk{C}{\sqrt{\rho(i) - 1}} % \frac{ A } { B + C }$

\begin{abbrev}% defining \chunk in align wouldn't work
\chunk{A}{a+b}
\chunk{B}{c+d}
\begin{align}
x &= A\\
y &= B
\end{align}
\end{abbrev}

\end{document}
` • Thanks. I didn't thought "newcommand" was used here because I don't want to define a "new command". I'll try. Any other option? – skan Sep 25 '15 at 11:03
• @skan Do you like the addition? – egreg Sep 25 '15 at 11:13
• Yes, thanks, I won't even wait for other replies. I prefer the first answer, the second one makes it much more complex unnecessarily. When I said a different approach I meant different commands or maybe an specialized package. – skan Sep 25 '15 at 11:39