How to write G2V correctly (I mean space)? I saw in articles $ G\,2\,V$ and $G2\,V$, on the internet webside it is usually $ G2V$.
One reason to prefer the space between the temperature and luminosity classes is that the hypergiant luminosity class is "0", which could be confused with a subtype. Usually this appears as part of a range with luminosity class "Ia" as opposed to on its own, but this range is often written as "0-Ia". Something like "G5 0-Ia" is more comprehensible than "G50-Ia".
If you're writing a parser, be prepared to handle both. In general, parsing spectral types is a bit tricky (I have written spectral type parsers before, it's "fun") and there are a surprising number of annoying edge cases. It would be nice if astronomical catalogues also included something like the IVOA spectral type encoding, but usually the furthest you get is some bespoke system that only encodes standard OBAFGKM types and provides no way to encode, say, carbon stars or Wolf-Rayet types, even though the catalogue contains examples of these.
Some other issues you may run into:
- The ambiguity between "-" as a minus sign and "-" as a range symbol. Uusually the machine-readable files will be ASCII so none of the other dashes in Unicode are available, and given the general state of things I wouldn't trust them to be used reliably anyway!
- The previously-mentioned "0-Ia" luminosity class range means that a parser will run into an ambiguous interpretation of "G0-Ia": either an open ended range "G0 or earlier" of luminosity class "Ia", or a "G" type star with no subtype and luminosity class range "0-Ia".
- The fact that "+" may be an open-ended range symbol or a multi-spectrum separator "M5+" (star of type M5 or later) vs "M5+..." and "M5+K2" (M5 star with companion).
- The peculiar A-type stars, e.g. "kA5hF0mA5 V".
- The various two-parameter systems for carbon and S-type stars.
- The fact that the entire spectral type or various subcomponents may be bracketed to indicate uncertainties...
- ...which must be distinguished from the use of square brackets to indicate that the star is the central star of a planetary nebula
- If you're really lucky, your source will render the spectral types in ALL UPPERCASE (so that peculiar A-star spectrum from a few bullet points up becomes "KA5HF0MA5") because it's been compiled using some Fortran code that hasn't been updated since the 1960s or something...