Consider the following statement:
Suppose $f: S_1\to S_2$ and $g: S_2\to S_3$ are nonconstant maps. Suppose that both $h = g\circ f: S_1\to S_3$ and $f: S_1\to S_2$ are analytic. Then $g$ is analytic as well.
I know this is true when $S_1,S_2,S_3$ are planar regions. For example, see the answer here: If composition of one function and the other holomorphic function is holomorphic, then the other should be holomorphic?
The argument is basically just finding a locally-defined branch of $f^{-1}$ and observing $g = h\circ f^{-1}$ on this local neighborhood (though one needs to do extra work at critical points of $f$). I believe the statement also generalizes to the case where $S_1,S_2,S_3$ are Riemann surfaces by working in local coordinates. Does anyone know a reference discussing this situation? I want to use this for an unrelated problem, so I am hoping there is a book or paper I can cite instead of writing out all the details myself.