Is it legal to upload preprint on ResearchGate?
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.