How does Spotlight determine which category a file belongs to? In Spotlight you can enable and disable file categories that will appear in search results.  
How does Spotlight determine that a certain file belongs to a certain category?
The following specific event triggered this curiosity:

For some time .tex files would come up under the Documents category. Spotlight would handle the search filename.tex just fine. Then suddenly I could not find .tex files anymore in Spotlight. Finder searches were OK though. 
Turns out that I had the Developer category disabled in the Spotlight preferences, and Spotlight now thought that .tex files belonged in that category. After enabling the Developer category everything went back to normal.

What made Spotlight decide to switch categories for the .tex files?
I think it depends on the parent UTIs defined in an application's Info.plist or in /System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist. .tex is not included in the CoreTypes Info.plist, so the UTI depends on which application's UTI declaration was registered first. For example on my installation the UTI was com.barebones.bbedit.tex-source and the first parent UTI was public.source-code:

$ touch a.tex; mdls -n kMDItemContentTypeTree a.tex
kMDItemContentTypeTree = (
    "com.barebones.bbedit.tex-source",
    "public.source-code",
    "public.plain-text",
    "public.text",
    "public.data",
    "public.item",
    "public.content"
)


When I deleted BBEdit and rebuilt the Launch Services database, the UTI became org.tug.tex and the first parent UTI became public.text:

$ touch b.tex; mdls -n kMDItemContentTypeTree b.tex
kMDItemContentTypeTree = (
    "org.tug.tex",
    "public.text",
    "public.data",
    "public.item",
    "public.content",
    "public.plain-text"
)