Let $B$ be an indefinite quaternion algebra over the rationals, let $G$ be the reductive algebraic group defined by $G(A) = (B\otimes A)^\*$ for ${\bf Q}$-algebras $A$; hence $G({\bf R}) = GL\_2({\bf R})$ in particular. Then $(G, {\bf H}^{\pm})$ is a Shimura datum (${\bf H}^{\pm}$ is a the union of lower and 
upper half planes) and it embeds into $(GSp\_4, {\bf H\_2}^{\pm})$ (Shimura datum defining $A\_2$, the moduli space of principally polarized abelian varieties of dimension 2). This induces an embedding of the Shimura curve defined by $(G, {\bf H}^{\pm})$ into $A\_2$. On the modular level, this map is just forgetting quaternioninc multiplication. I am aware that there is a slight issue of connected components but this seems irrelevant for what I am going to ask... 


My question is what the centralizer of $G$ in $GSp\_{2g}$ would be. This is what I am confused about... Logically, this should be $B^\*$ because this centralizer represents endomorphisms of the corresponding abelian surface, which in this case case is $B$. However, this is not possible since this centralizer must be compact over ${\rm R}$ (modulo centre) which of course $B^\*$ is not... 


This is really confsing, I am clearly missing something.... can anyone help? Many thanks in advance!



Centralizer of Shimura datum defining a Shimura curve in $A_2$
There is a piece of data missing from the question. As explained in [this question](https://mathoverflow.net/questions/45704/shimura-datum-of-family-of-fake-elliptic-curves?rq=1), in order to get the embedding of Shimura data, you have to choose an element $\gamma \in B^\times$ such that $\gamma^\* = -\gamma$ and $\gamma^2$ is a negative rational number. Then there is a $\mathbf{Q}$-bilinear form on $B$ preserved by left multiplication up to scaling, which gives an embedding $B^\times \hookrightarrow GSp\_4$.


It's now an easy exercise to work out the endomorphisms. The endomorphisms of $B$ as a $Q$-vector space commuting with the left $B$-action are just $B$, acting on the right via the involution; but the requirement to preserve the symplectic form restricts you to things which commute with $\gamma$, so you just get the imaginary quadratic field $K$ inside $B$ generated by $\gamma$. Hence the centralizer of $B^\times$ in $GSp\_4$ is $K^\times$.


