I have few papers already published in certain journals which cannot be uploaded on ResearchGate due to copyright issues, now is it legal to upload my own version of the paper formatted in LaTeX or in other words the manuscript I sent for publication that was not typeset for journal publication?
As one of the other answers says, typesetting is completely irrelevant--the question is whether or not you are authorized to upload the content.
The RoMEO website has documentation on the precise legal authorizations of every major journal publisher, and of an extensive list of journals. You can consult it to quickly confirm what exactly the journals you've published in authorize you to do.
Their information is not always 100% accurate, but it's above 95% accurate. I've sent them corrections and they are quite conscientious to update their information, and they usually have direct links to the publishers' copyright statements so that you can verify what they say.
I will note though, that a very large amount of the time, it is not authorized to upload to general repositories like ResearchGate, Academia.edu, SSRN or arXiv (depending on the journal). If you want a safe place to load your articles, the most commonly authorized places are your personal website or your institution's open access repository.
In general, the typesetting is irrelevant, as far as copyright law is concerned; the law protects the content, not just the specific file. If posting an exact copy would infringe copyright, then posting a re-typeset copy would also. If the publisher owns the copyright, then you need their permission to upload anything that contains any significant amount of the paper's content (barring fair use exceptions, etc).
Some copyright agreements contain terms saying that they only cover the journal's typeset version, giving the author permission to self-archive their own version. But if yours said that, you would know.
For a more certain answer, consult an intellectual property lawyer in your jurisdiction.