I have an annoying reoccurring problem. I often use user-defined macros with for example \newcommand in my LaTeX code. I also use LaTeX a lot in for example Jupyter Notebooks. Often Some things render fine locally, but don't render correctly anymore when hosted for example on Github. Or when I need to ask something on math.stackexchange, this becomes also quite annoying bringing over all macro definitions or manually expanding them.
I would therefore like to know if there is some way to produce a .tex file that has all user-defined macros expanded, so I can use the content of that document if I need cross-platform compatibility.
Example
\newcommand{\paren}[1]{\mathopen{}\left( {#1}_{{}_{}}\,\negthickspace\right)\mathclose{}}
\newcommand{\pda}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pdb}[2]{\frac{\partial}{\partial #2} #1}
\newcommand{\grad}[2]{\nabla_{#2}{#1}}
Let the output layer activation be the sigmoid function and let the loss function be the mean square error.\\
\begin{align}
\pda{l\paren{y, f(x)}}{A^{(L)}_i} ={}& \pda{l\paren{y, f(x)}}{f (x)_i}\\
& \text{by definition}\\
={}& \pdb{\frac{1}{2n} \sum_{j=1}^n \paren{y_j - f(x)_j}^2}{f(x)}\\
={}& \frac{1}{2n} \sum_{j=1}^n \pda{\paren{y_j - f(x)_j^2}}{f(x)_i}\\
={}& \frac{1}{2n} 2 \paren{y_i - f(x)_i}\\
={}& \frac{1}{n} \paren{y_i - f(x)_i}\\
\propto{}& y_i - f(x)_i\label{eq1}
\end{align}
\begin{equation*}
\implies \nabla_{A^{(L)}}{l\paren{y, f(x)}} \propto y - f(x)
\end{equation*}
where $f$ is the function computed by the network and $g^{(L)}$ is the activation function of layer $L$.
This render fine locally:
But it renders incorrectly due to missing macro interpretation on Github:


\letfor "copying" primitives. E.g,\let\MyRelax=\relax-\MyRelaxis user-defined but not a macro. How to handle situations where user-defined macros a) do not just expand but do define other macros? b), e.g., deliver character-tokens contained in their definition-text that deviate from the usual catcode-régime? – Ulrich Diez Oct 05 '19 at 21:09