# Write the code for large formula in terms of smaller chunks [duplicate]

I am wondering if it is possible that for large formulas in order to avoid confusion during code typing, we break it into variables. For example the formula below could be confusing during typing the code and sometimes it is a hassle to debug it. Is it possible that like all computer languages one writes the numerator into a variable and denominator into another one and at the end plugs those variables into the final formula and run it. thanks

$$\hbar \omega_c = I_p+\frac{0.5I_p^{3.5}\lambda^2}{\big[\text{ln}\big(\frac{0.86I_p3^{2n^*-1}G_{lm}C^2_{n^*l^*}}{-\text{ln}(1-p_s)}\tau_p\big)\big]}$$


## marked as duplicate by egreg equations StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 2 '15 at 14:58

• Doing this for your readers could help them just as much as doing it for yourself helps you. Why not display the pieces of your final equation in the document, with names you then use in that last equation? – Ethan Bolker Nov 2 '15 at 15:08

Yes, you can just use \def assignments for the smaller groupings of components. Nesting of these assignments is also permissible, as I show by nesting \subnum and \subdenom inside of \demominator. And I took Mico's proper suggestion to use \ln for the natural log, which will give proper horizontal spacing.

The only proviso in using \def instead of \newcommand is that you must be careful not to unintentionally overwrite an existing definition of the same name.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\def\numerator{0.5I_p^{3.5}\lambda^2} \def\subnum{0.86I_p3^{2n^*-1}G_{lm}C^2_{n^*l^*}} \def\subdenom{-\text{ln}(1-p_s)} \def\denominator{\big[\ln\big(\frac{\subnum}{\subdenom}\tau_p\big)\big]} \hbar \omega_c = I_p+\frac{\numerator}{\denominator}$$
\end{document}


Alternately, with display style and \bigg in \denominator:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\def\numerator{0.5I_p^{3.5}\lambda^2} \def\subnum{0.86I_p3^{2n^*-1}G_{lm}C^2_{n^*l^*}} \def\subdenom{-\text{ln}(1-p_s)} \def\denominator{\displaystyle\bigg[\ln\bigg(\frac{\subnum}{\subdenom}\tau_p\bigg)\bigg]} \hbar \omega_c = I_p+\frac{\numerator}{\denominator}$$
\end{document}


• +1. Instead of \text{ln}, I'd write \ln, though. I'd also be tempted to insert \displaystyle at the start the argument of \denominator. – Mico Nov 2 '15 at 14:14