# Tex capacity error when using combine class

Using the combine class and the following mock example of the master file:

\documentclass[11pt,a4paper]{combine}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsthm,amsmath,mathrsfs}
\usepackage{amssymb,amsthm,amsmath}
\usepackage{tikz-cd}

\title{ABC-116 Journal}
\author{A. M. Editor}
\date{2016.2}
\begin{document}
\pagestyle{combine} % use the combine page style
\maketitle % main title
\tableofcontents % main ToC
\clearpage
\section{Editor’s introduction} \label{intro} % into main ToC (section 1)
In the article by A.~N.~Author on page ...
\begin{papers} % start of individual articles/papers
\coltoctitle{An article} % first article title into main ToC
\coltocauthor{A.~N.~Author} % first authors into main ToC
\import{paper1}
\clearpage

\end{papers}

\end{document}


together with paper1:

\documentclass{amsart}

\usepackage[utf8]{inputenc}
\usepackage{amsthm,amsmath,mathrsfs}
\usepackage{amssymb,amsthm,amsmath}
\usepackage{tikz-cd}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{xca}[theorem]{Exercise}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\numberwithin{equation}{section}

\title{Different Ways to Differentiate $x^n$}
\author{A}

\begin{document}

\maketitle

\begin{abstract}
We present distinct ways of proving that $(x^n)'=nx^{n-1}$.
\end{abstract}

The identity $(x^n)'=nx^{n-1}$ is one of the most used in a Calculus course.  It immediately allows the differentiation of any polynomial by a simple formula. Being an equation of utmost importance, it is desirable to have different proofs of the fact (this is a recurrent trend in mathematics; take the Pythagorean Theorem as a prime example, \cite{pyth} alone being a webpage having 118 proofs of it).

\end{document}


makes me reach the following error: "!Tex capacity exceeded, sorry [input stack size=5000]. t \end{document}"

Why is this happening? How can I fix this? As a maybe important note, there is no error when I try to load paper1 individually.

EDIT: Thanks to David Carlisle, the error was corrected in the case above. However, using the full code, the error comes back. Below is the code in its entirety. I think it should be noted that if I delete everything below the "First proof" subsection, no error pops up.

\section{The Formula.}

\begin{theorem}
Let $f:\mathbb{R} \to \mathbb{R}$ be given by $f(x)=x^n$, where $n \in \mathbb{N}$. Then
$$f'(x)=nx^{n-1}$$
for all $x$.
\end{theorem}

\subsection{First proof.}

\begin{proof} This is an application of the binomial theorem. Indeed, we have
\begin{align*}
f'(x)&=\lim_{h \to 0}\frac{f(x+h)-f(x)}{h} \\
&=\lim_{h \to 0}\frac{(x+h)^n-x^n}{h} \\
&=\lim_{h \to 0}\frac{\sum\limits_{i=0}^n \binom{n}{i} x^{n-i}h^i - x^n}{h}  \\
&=\lim_{h \to 0}\frac{\sum\limits_{i=1}^n \binom{n}{i} x^{n-i}h^i}{h} \\
&=\lim_{h \to 0} \sum\limits_{i=1}^n \binom{n}{i} x^{n-i}h^{i-1}  \\
&=\binom{n}{1} x^{n-1}=n x^{n-1}.
\end{align*}
\end{proof}

\subsection{Second proof.}

\begin{proof} This is an application of the well-known equality $t^n-x^n=(t-x)(t^{n-1}+xt^{n-2}+\cdots+x^{n-2}t+x^{n-1})$.
\begin{align*}
f'(x)&=\lim_{t \to x}\frac{f(t)-f(x)}{t-x} \\
&=\lim_{t \to x}\frac{t^n-x^n}{t-x} \\
&=\lim_{t \to x}\frac{(t-x)(t^{n-1}+xt^{n-2}+\cdots+x^{n-2}t+x^{n-1})}{t-x}  \\
&=\lim_{t \to x} t^{n-1}+xt^{n-2}+\cdots+x^{n-2}t+x^{n-1} \\
&=\lim_{t \to x} x^{n-1}+\cdots+x^{n-1}  \\
&=n x^{n-1}.
\end{align*}

\end{proof}

\subsection{Third proof.}

\begin{proof} This proof follows induction and Leibniz's Rule. First, the theorem is trivial for $n=1$. For $n+1$, we have
$$f(x)=x \cdot x^n$$
\begin{align*}
\implies f'(x)&=1 \cdot x^n+ x \cdot n x^{n-1} \\
&=x^n+nx^n \\
&=(n+1)x^n.
\end{align*}

\end{proof}

\subsection{Fourth proof.}

\begin{proof} We have
$$x^n=e^{\log(x^n)}=e^{n \log x}.$$
Therefore, the chain rule implies
\begin{align*}
f'(x)&=e^{n \log{x}}\frac{1}{x} \\
&=x^n  \cdot \frac{n}{x} \\
&=n x^{n-1}.
\end{align*}

\end{proof}

The attentive reader may have noticed some issues on this last proof. Firstly, the proof assumes $x>0$. That is really a non-issue, as one can take $(-x)^n$ and use the chain rule for this case. For $x=0$, one could use the fact that if $\lim\limits_{x \to 0} f'(x)=L$ and $f$ is continuous at $0$, then $f'(0)=L$ (this is a nice Real Analysis exercise. Maybe one of the most important parts of this exercise is realizing why it is not trivial).

However, one glaring issue is the apparent circularity. How can one use $\exp$ and $\log$ and not have passed through the derivative of $x^n$ before? Of course, if one defines $\exp$ by its well-known series, then the proof is obviously circular. However, if one defines $\exp$ as the unique solution of $f'=f; \quad f(0)=1$, then the proof is not circular, as we will show.

\subsection{Non-circularity.}

First, the existence and uniqueness of a solution to $f'=f; \quad f(0)=1$ can be seen to follow from Picard-Lindelof. However, this ODE is so particular that a more elementary way to the solution is available. For that, define $\log: \mathbb{R}^+ \to \mathbb{R}$ by
$$\log(x):=\int_1^x \frac{1}{t} dt.$$
Since $\log'(x)=\frac{1}{x}$ by the Fundamental Theorem of Calculus, we have that $\log$ is strictly increasing. We also have that, fixing $y>0$, $f(x)=\log(xy)$ and $g(x)=\log(x)+\log(y)$ are such that $f'(x)=\frac{1}{x}=g'(x)$. Since $f(1)=g(1)$, we have that $f(x)=g(x)$ for all $x$, and it follows that
$$\label{eq1} \log(xy)=\log(x)+\log(y)$$
for all $x,y>0$. It follows now that
$$\log(2^n)=n\log(2),$$
and we have that $\log(x) \to \infty$ as $x \to \infty$ (since obviously $\log(2)>0$, and $\log$ is strictly increasing as we have seen). Equation (\ref{eq1}) also implies
$$\log(1)=\log(x)+\log(1/x),$$
from which we have that $\log(x) \to -\infty$ as $x \to 0^+$. Putting together all this, we have that $\log: \mathbb{R}^+ \to \mathbb{R}$ is a bijection. We define $\exp:=\log^{-1}$. It now follows from the chain rule that $\exp'=\exp$, since
$$\log(\exp(x))=x \implies \frac{1}{\exp(x)} \cdot \exp'(x)=1 \implies \exp'(x)=\exp(x).$$
It is also trivial that $\exp(0)=1$, so we have arrived at our solution for $f'=f; \quad f(0)=1$ (Note that nowhere did we need $(x^n)'$). Now, induction on equation (\ref{eq1}) also implies
$$\log(x^n)=n \log(x)$$
for $n$ a natural number. Therefore,
$$x^n=\exp(\log(x^n))=\exp(n \log(x)),$$
and this is what we used in the fourth proof, together with the chain rule and the derivatives of $\exp$ and $\log$.

Note that we did not justify (nor did we need) the fact that $\exp$ is the unique solution to our differential equation. For the sake of completeness, the proof of such fact is immediate by assuming the existence of another solution $g$ and analysing $h:=\frac{g}{\exp}$ (that is, showing it is constant and equal to $1$). We leave this as an exercise.

\subsection{More on the fourth proof.}

The fourth proof may be (unfairly) taken as an \emph{ad hoc} proof. However, this isn't the case. Logarithms take products and convert them into sums. Derivatives of sums are trivial. It is only natural to try to convert a problem to something trivial. The price we pay, of course, is the development of the theory (existence of $\log$, chain rule etc).

In fact, this property of logarithms is quite useful. Consider the following commutative diagram, which is a rewording of equation (\ref{eq1}).
\begin{center}
\begin{tikzcd}
\mathbb{R}^+ \oplus \mathbb{R}^+ \arrow[d, "\times"] \arrow[r,"\log \oplus \log"] & \mathbb{R} \oplus \mathbb{R}  \arrow[d,"+"]\\
\mathbb{R}^+  \arrow[r, "\log"] &  \mathbb{R}.
\end{tikzcd}
\end{center}
Since $\exp=\log^{-1}$, we have the equivalent diagram
\begin{center}
\begin{tikzcd}
\mathbb{R}^+ \oplus \mathbb{R}^+ \arrow[d, "\times"] \arrow[r,"\log \oplus \log"] & \mathbb{R} \oplus \mathbb{R}  \arrow[d,"+"]\\
\mathbb{R}^+   &  \arrow[l, "\exp"] \mathbb{R}.
\end{tikzcd}
\end{center}
And this is (allegedly) how old calculators did multiplication: through sums and tables of logarithms and exponentials. Indeed, the above commutative diagram transfers a multiplication to doing an exponentiation of a sum of logarithms.

\section{Final commentary.}

Not only the fourth proof has the theoretical insight given in the last subsection, but it also provides an unified and simple proof for the case $f(x)=x^r$, $x>0$, since $x^r=\exp(r \log(x))$. Indeed, depending on the text, this is the very definition of $x^r$.

%\begin{acknowledgment}{Acknowledgment.}
%The authors wish to thank the Greek polymath Anonymous, whose prolific works are an endless source of inspiration.
%\end{acknowledgment}

\begin{thebibliography}{1}
\bibitem{pyth} http://www.cut-the-knot.org/pythagoras/

\end{thebibliography}

%\begin{biog}
%\item[Aloizio Macedo]
%\end{biog}

\makeatletter
\def\@EveryShipout@Org@Shipout{\pdfprimitive\shipout}
\makeatother
\end{document}


To be quite explicit, the error is as follows:

"! TeX capacity exceeded, sorry [input stack size=5000]. t l.57 \end{align*} If you really absolutely need more capacity,

you can ask a wizard to enlarge me.

Here is how much of TeX's memory you used:

13551 strings out of 493921

275897 string characters out of 3144867

359751 words of memory out of 3000000

16570 multiletter control sequences out of 15000+200000

23489 words of font info for 72 fonts, out of 3000000 for 9000

841 hyphenation exceptions out of 8191

5000i,10n,82p,457b,10290s stack positions out of 5000i,500n,10000p,200000b,50000s

! ==> Fatal error occurred, no output PDF file produced!"

• It would be better if you provided minimal examples (the smallest amount of code required to reproduce the error). That would help you and us identify what is causing your problems. From my own minimal examples the problem seems to come once the tikz-cd package is loaded in the main file. For me David Carlisle's suggestion of the modification to the end of paper1.tex fixes it. With such a lot of code problems may be coming from elsewhere. – Gareth Walker Nov 23 '16 at 9:49

You can end paper1.tex as follows
\makeatletter

• @AloizioMacedo Your code as posted worked for me with that change sorry about missing } assuming you are using pdflatex. – David Carlisle Nov 22 '16 at 22:01