# How to simplify typesetting of repeated material in math formulae

Is there a way to create something like a reference tag to avoid copy-pasting in math equations. E.g. if I have something like

$Eq=\prod_{k=1}^{K}(some-very-long-expression)^{z_{k}}$


and in the next step I take log of this, I get this

$log(Eq)=\sum_{k=1}^{K}{z_{k}log(some-very-long-expression)}$


In that case I would like to create a tag for some-very-long-expression part in the first equation and use tag in the second one, so that if there was a mistake in the first line I need to fix it just there.

• I tend to use some “original name” for this, like \def\**{some-very-long-expression} (locally defined) and use \** in the equation. You can use whatever name you want, but for me that stands out more, or a number like \0 or \1. – Manuel Sep 23 '17 at 12:18
• @DavidCarlisle To be honest it's been some time since I used that, but yes, I used it. Why is it a problem? For me it looks “understandable” \prod_{k=1}^{K} (\**)^{z_{k}} \qquad \log(Eq) = \sum_{k=1}^{K} z_{k} (\**). What is the bravery there? In case \* has a definition by default, I did not know that (or not remember that). In any case, as an alternative, one can use \tmp or \0 or \1 or something like that. – Manuel Sep 23 '17 at 12:34
• @Manuel \* does have a default definition, and if you do suggest \** to people you should stress that you are re-defining \* and defining it in a way that produces an error if not followed by *, you are not defining a command with name ** (you probably know that but your comment is there to be read by anyone....) If you use \newcommand you would get warned about over-writing a standard latex command and you wouldn't be able to define commands taking null delimited arguments delimited by * – David Carlisle Sep 23 '17 at 12:38
• @DavidCarlisle I've seen it does have a definition, but I can't understand what it does! (The \discretionary outputs a \times symbol?). In any case, yes, I wasn't talking about defining in general but about defining locally, e.g., $\def\** ..$, $\def\** ..$. But in case it might create great confusion I can remove the comment. – Manuel Sep 23 '17 at 12:42
• @Manuel a local definition would not serve the requested use case of using the same term in two equations (discretionary times is so you can use conjunction for implied multiplication abc but add explicit operator at line breaks (it comes from plain tex) – David Carlisle Sep 23 '17 at 12:46

## 1 Answer

In LaTeX, one may use \newcommand to define a new command or, to use the jargon term, macro. Here's a compilable example:

\documentclass{article}
\newcommand\mymacro{\mbox{(some-very-long-expression)}} % just for this example
\begin{document}

\begin{equation}
Eq = \prod_{k=1}^{K} \mymacro^{z_{k}}
\end{equation}
followed by
\begin{equation}
\log(Eq) = \sum_{k=1}^{K} z_{k} \log \mymacro
\end{equation}

\end{document}