Convergence of series related to partial fraction expansion of cotangent function I am looking at the convergence of the series
$$ \cos(t\theta) = \frac{\sin(\pi t)}{\pi} \cdot \Bigg[\frac{1}{t} + 2t \sum_{k=1}^\infty (-1)^k \frac{\cos(k\theta)}{t^2 - k^2}\Bigg].$$
Here $t\in\mathbb{R}$. The above equality is rather trivial, but the convergence of the right side towards the left side is not straightforward to me. Based on empirical observations, we have convergence to the target function if $|\theta| <\pi$, regardless of $t$ (even if $t\in\mathbb{Z}$, by taking the limit). If $|\theta|>\pi$, we still have convergence, but towards a different function rather than $\cos(t\theta)$.
Is that correct? How to prove it or find the conditions on $\theta,t$ for the convergence to $\cos(t \theta)$?
Purpose
This was part of a bigger project to find an analytic continuation of $\zeta^*(s)$ where $\zeta^*(s) = \zeta(s)$ if $\Re(s)$ is an integer. The hope was that the analytic continuation would coincide with $\zeta(s)$. You may replace $\zeta,\zeta^*$ by the Dirichlet eta function or related functions. You could do the same using $\Im(s)$ instead of $\Re(s)$.
The first step is establish the following and check when it is valid, for an arbitrary even function $f(t)$:
$$ f(t) = \frac{\sin(\pi t)}{\pi} \cdot \Bigg[\frac{f(0)}{t} + \phi'(t)\sum_{k=1}^\infty (-1)^k \frac{f(k)}{\phi(t) - \phi(k)}\Bigg].$$
Here I used $\phi(t)=t^2$. Then have a similar formula for odd functions, and by combining both, a formula for any function regardless of parity.
I  did get some pretty decent approximation (analytic extension) when working with $\Re(s)$ fixed and $t$ is the variable. But not an exact continuation. However, it does not lead to anything interesting, even if the approximation  was exact. It's less accurate anyway as $t$ increases.
What I really wanted is the same thing but with $\Im(s)$ fixed instead, and $\sigma$ playing the role of $t$. There I failed; it would have been an exciting development otherwise. I am not finished yet, as there are plenty of options for $\phi(t)$, not just $\phi(t)=t^2$. I tried many low-hanging fruits; all failed. There has to be some $\phi$ that will work, I guess, though it won't be a simple function. You could choose $\phi$ by solving an integral equation in $\phi$ so that the RHS matches the LHS. Anyway, that's where I am now. Not sure if I will pursue the idea.
 A: Kostya_I's complex analytic answer and Conrad's Fourier analytic proof in the comments complement each other nicely. The purpose of the present answer is to relate your question to the literature.
As pointed out already, the RHS is periodic in $\theta$ so we may restrict to $|\theta| \le \pi$.
For $\theta=\pi$, $\cos(k \theta)=(-1)^k$ and the identity in question is
$$\pi \cot(\pi t) = \frac{1}{t}+\lim_{N\to \infty}\sum_{|n| \le N}\frac{1}{t+n}=\frac{1}{t}+2t\sum_{n =1}^{\infty}\frac{1}{t^2-n^2},\label{1}\tag{$\star$}$$
$t$ non-integer. This identity also holds for complex $t$. It is due to Euler and can be obtained by carefully differentiating the product formula for $\sin(\pi z)$,
$$\sin(\pi z)= \pi z\prod_{n \ge 1}(1-z^2/n^2)..\label{2}\tag{$\star\star$}$$
One can also derive \eqref{2} from \eqref{1}.
For $\theta=0$, your identity is
$$\frac{\pi}{\sin(\pi t)} = \frac{1}{z}+2t\sum_{n =1}^{\infty}\frac{(-1)^n}{z^2-n^2}.\label{3}\tag{$\star\star\star$}$$
It again holds for $t$ non-integer, and extends to complex $t$.
There are many proofs of \eqref{1}, \eqref{2} and \eqref{3} in the literature (as well as of variations of these identities) and some of them, possibly all of them, extend to prove your identity when $|\theta|\le \pi$. I am going to give a partial review of these proofs.
From "Fourier analysis. An Introduction" by Elias Stein and Rami Shakarchi (Princeton Lectures in Analysis. 1, Princeton University Press, 2003):

*

*Page 90, exercise 9: For fixed non-integer $\alpha$, the Fourier expansion of $\frac{\pi}{\sin(\pi \alpha)} e^{i(\pi-x)\alpha}$ for $x \in [0,2\pi]$ is worked out to be
$$\sum_{n \in \mathbb{Z}} \frac{e^{inx}}{n+\alpha}.$$
This relates to Conrad's answer in the comments -- taking real parts gives your identity. Applying Parseval gives the identity
$$\sum_{n\in \mathbb{Z}}\frac{1}{(n+\alpha)^2}=\frac{\pi^2}{\sin^2(\pi \alpha)}.\label{4}\tag{${\star\star\star\star}$}$$

*Page 97, exercise 97(c): A proof of \eqref{3}, the $\theta=0$ case of your identity, is given. It is proved as a consequence of Euler's identity $\sum_{n\ge 1}\frac{1}{n^2 - \alpha^2} = \frac{1}{2\alpha^2} - \frac{\pi}{2\alpha\tan(\alpha \pi)}$ (whose proof is given and follows from a suitable Fourier expansion). Indeed, applying Euler's identity with $\alpha$ and $\alpha/2$ and taking a linear combination gives \eqref{3}.

*Page 165, exercise 15: Poisson summation applied to a (shift of) $g(t)=(1-|t|)\mathbf{1}_{|t|\le 1}$ gives \eqref{4}. A consequence which follows by integration is also given:
$$\lim_{N \to \infty}\sum_{|n| \le N}\frac{1}{n+\alpha} = \frac{\pi}{\tan(\pi \alpha)}.$$
From the book  "Complex analysis" by the same authors:


*Page 105, exercise 12: A proof of \eqref{4} is given as a consequence of integrating $f(z)=\pi \cot(\pi \alpha)/(\alpha+z)^2$ over a circle of growing radius and using Cauchy's residue theorem.

*Page 129, exercise 7(b,c): A proof of \eqref{4} is given, by applying Poisson summation to $f(z) = (\tau+z)^{-2}$ ($\Im \tau>0$).

*Page 142: A proof of \eqref{1} is given by proving that both sides, as functions of complex variable, satisfy 3 properties which determine a function uniquely. Kostya_I's answer can be seen as an extension of it.

Bonus:


*There is a real-analytic variant of the last proof of \eqref{1}, attributed to Gustav Herglotz, which can be found in Chapter 26 of M. Aigner and G. Ziegler's "Proofs from THE BOOK", 6th edition. In the complex analytic proof, 3 properties are established for each side of the identity: i) Each side is a meromorphic function with simple poles at the integers, and no other singularities. ii) Each side is periodic with period $1$. iii) The residue of each side at $z=0$ is $1$. In the real-analytic proof, the following properties are established instead: i) Each side is defined for $t \in \mathbb{R}\setminus \mathbb{Z}$ and is continuous there. ii)  Each side is periodic with period $1$. iii) Each side is an odd function. iv) Both sides satisfy the functional equation $f(x/2)+f((x+1)/2) = 2f(x)$.

A: Here's a complex analysis proof. For $|\theta|\leq\pi,$ we have that
$$
F(t)=\frac{\cos(\theta t)\pi}{\sin (\pi t)}
$$
is an odd meromorphic function for $t\in\mathbb{C}$ with simple poles at $k\in\mathbb{Z}$, which moreover is bounded as $|\Im t|\to\infty$.
We claim that the series in brackets
$$
G(t)=\frac{1}{t} + 2t \sum_{k=1}^\infty (-1)^k \frac{\cos(k\theta)}{t^2 - k^2}
$$
has all the same properties. Indeed, we have
$$
\left|(-1)^k\frac{\cos (k\theta)}{t^2-k^2}\right|\leq 
\frac{1}{|(\Re t)^2-(\Im t)^2-k^2|}\leq \frac{2}{(\Im t)^2+k^2},
$$
if either $(\Im t)^2\geq 2(\Re t)^2$, or $k^2\geq 2(\Re t)^2$. From the latter case, the series converges absolutely  and uniformly on compact subsets of $\mathbb{C}\setminus \mathbb{Z}$, and the former case can be used to show, e.g., by comparing with the integral, that $|G(t)|$ is bounded over $|\Im t|\geq 10$, say. The poles at $\pm k$ only come from $k$-th term.
Now we simply note that $F$ and $G$ have the same residues at the poles, so $F-G$ is a holomophic function in the whole plane $\mathbb{C}.$ It is enough to show that $F-G$ is bounded, then it is constant by Liouville's theorem, and since it is odd, the constant is zero.
To check boundedness, by maximum principle, it suffices to upper-bound $|F|$ and $|G|$ separately on the boundary of each box $$R_m=\left\{m-\frac12<\Re t<m+\frac12,|\Im t|\leq 10\right\},$$
by a constant independent of $m$. For $F$, we just upper-bound $|\cos t\theta|\leq e^{10|\theta|}$ and lower-bound $\sin(\pi t)$ by its minimum (which is independent of $m$ by periodicity). For $G$, we notice that we can actually write, for any $m$,
\begin{multline}
G(t)=\lim_{N\to\infty}\sum_{k=-N}^N(-1)^k\cos(k\theta)\frac{1}{t-k}=\lim_{N\to\infty}\sum_{k=-N+m}^{N+m}(-1)^k\cos(k\theta)\frac{1}{t-k}\\=\frac{(-1)^m}{t-m}+2(t-m)\sum_{k=1}^\infty(-1)^{k-m}\frac{\cos((k-m)\theta)}{(t-m)^2-k^2},
\end{multline}
and bounding the absolute value term by term, as above, on the boundary of $R_m$, yields an estimate independent of $m$.
If $\theta>\pi$, then $F(t)$ is no longer bounded as $t\to\infty$, while the RHS still is, so the equality cannot hold. As noted by Conrad in the comments, the RHS does not change under replacing $\theta\mapsto \theta+2\pi m$, so by choosing an appropriate $m$ we can reduce this to the previous case.
