4

This question already has an answer here:

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

\begin{equation}
\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]}
\end{equation}

marked as duplicate by egreg equations Nov 2 '15 at 14:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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
4

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}
\begin{equation}
\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{equation}
\end{document}

enter image description here

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

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\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{equation}
\end{document}

enter image description here

  • 3
    +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

Not the answer you're looking for? Browse other questions tagged or ask your own question.