Every notable passenger train route I could verify, drawn on one map with no basemap under it, so the rail lines themselves trace the coastlines. 1,166 routes across 119 countries, about 309,000 km of line once shared corridors are counted once.
Coloured by what kind of journey it is: 459 classic intercity, 246 scenic, 138 heritage, 135 high-speed, 108 night trains, 48 funiculars, 32 luxury cruise trains.
The geometry is the part I have spent the most time on. Route shapes are traced from OpenStreetMap railway relations and ways rather than drawn by hand, so the lines sit on real track. This week I finished a pass that put the last stragglers on their actual alignment, including a Saudi line that turned out to be running 200 km up a branch and back down again.
It is a free hobby project, no ads and no signup, and the route data is open. Corrections are genuinely welcome and get credited; forum readers have already fixed a number of errors in it.
Caveat worth stating plainly: it is a curated atlas of notable routes, not a complete inventory of the world's railways. Somewhere like China or Germany has far more track than the routes shown here.
https://trainrouter.com/
Yes, different projects for different goals. OpenRailwayMap even displays the reference numbers of switches, and goes into displaying micromapped details of train stations.
For TrainRouter you could read the actual routes from GTFS. Most European transport companies publish their schedules in this format, and it contains the geometry of the routes, not just a list of stops. You can browse some GTFS feeds here: https://www.transit.land/map Another nice, free api is here: https://transitous.org/
The "shapes" file should contain the data you are looking for: https://en.wikipedia.org/wiki/GTFS#shapes