In the script of our Quantum Mechanics class the position operator in momentum space ($\rvert p\rangle, \rvert q\rangle$ are momentum states) is derived:
$\langle p \rvert \widehat{x}\lvert q\rangle = \int y \ \langle p \rvert y\rangle\langle y \rvert q\rangle\, \mathrm{d}y $
$\hspace{1.4cm} = \int \langle p \rvert y\rangle (-i\hbar \frac{\partial}{\partial q})\frac{1}{\sqrt{2\pi\hbar}}e^{i\frac{qy}{\hbar}} \, \mathrm{d}y $
$\hspace{1.4cm} = (-i\hbar \frac{\partial}{\partial q}) \int \langle p \rvert y\rangle\langle y \rvert q\rangle\, \mathrm{d}y $
$\hspace{1.4cm} = (-i\hbar \frac{\partial}{\partial q})\langle p \rvert q\rangle = (-i\hbar \frac{\partial}{\partial q})\delta(p - q)$
Where we have used the 1D wavefunction $\langle x\rvert p\rangle = \frac{1}{\sqrt{2\pi\hbar}}e^{i\frac{px}{\hbar}}$.
This result is then used to calculate $\langle p\rvert \widehat{x}\rvert\psi\rangle$:
$ \ $
$\langle p\rvert \widehat{x}\rvert\psi\rangle = \int \langle p \rvert \widehat{x} \rvert q\rangle\langle q \rvert \psi\rangle\, \mathrm{d}q $
$\hspace{1.5cm} = -i\hbar \frac{\partial}{\partial q} \int \delta(p-q) \langle q \rvert \psi\rangle \mathrm{d}q $
$\rightarrow \langle p\rvert \widehat{x}\rvert\psi\rangle = -i\hbar \frac{\partial}{\partial p}\langle p \rvert \psi \rangle$
$ \ $
However in books and online I found the relation with the sign reversed:
$ \langle p\rvert \widehat{x}\rvert\psi\rangle = i\hbar \frac{\partial}{\partial p}\langle p \rvert \psi \rangle$
This seems odd and when I calculate
$\langle p \rvert \widehat{x}\lvert q\rangle$ with the same procedure but plugging in the wavefunction on the first bracket I get the right sign:
$\langle p \rvert \widehat{x}\lvert q\rangle = \int y \ \langle p \rvert y\rangle\langle y \rvert q\rangle\, \mathrm{d}y $
$\hspace{1.4cm} = \int (i\hbar \frac{\partial}{\partial p})\frac{1}{\sqrt{2\pi\hbar}}e^{-i\frac{py}{\hbar}} \langle y \rvert q\rangle \, \mathrm{d}y $
$\hspace{1.4cm} = (i\hbar \frac{\partial}{\partial p}) \int \langle p \rvert y\rangle\langle y \rvert q\rangle\, \mathrm{d}y $
$\hspace{1.4cm} = (i\hbar \frac{\partial}{\partial p})\langle p \rvert q\rangle = (i\hbar \frac{\partial}{\partial p})\delta(p - q)$
Which then gives me $ \langle p\rvert \widehat{x}\rvert\psi\rangle = i\hbar \frac{\partial}{\partial p}\langle p \rvert \psi \rangle$ as expected.
I cannot find the error in the calculation from the script, but I don't think that my calculation and the one from the script can both be correct. I suspect that at some point we would need to do a conjugation, maybe when the derivative is pulled out of the integral.
Any help would be greatly appreciated.
Edit: Corrected typos in my calculation.