Latex3: Feature request: detect os/platform name

Created on 9 Jan 2019  ·  25Comments  ·  Source: latex3/latex3

Please consider to add an interface to detect the os/platform name, e.g. windows or linux.

ctex package, for example, has implemented \ctex_detected_platform:

https://github.com/CTeX-org/ctex-kit/blob/22cb36acfed66dab0fb35994bf18dd4bb5eb384e/ctex/ctex.dtx#L5947-L6026

expl3 feature-request

Most helpful comment

I think the request is for \sys_if_platform_macos:pTF (or similar) as well. It can be done by checking for (say) the existence of a file of a mac-specific font or system file.

All 25 comments

We have \sys_if_platform_(unix|windows):(pTF) and \c_sys_platform_str in l3candidates: do they work for you?

Hope to test macos as well, since fontspec etc may have different behavior.

I see this is done simply by looking for a “standard” file in macOS, so doesn’t need write18 and should be quite fast. No objections from me. What do you think Joseph?

Sent with GitHawk

Just for your information:

  • /Library/Fonts/Songti.ttc (Chinese font) exists since macOS 10.9 (Mavericks).

    • The "darwin" binaries support only macOS with official support by Apple (10.10 Yosemite or later when TL2018 started), so that might be fine.

    • However, TL still contains "darwinlegacy" binaries which support 10.6 Snow Leopard -- 10.9 Mavericks. So, the existence test for /Library/Fonts/Songti.ttc will fail for macOS 10.6 -- 10.8.

  • A slightly safer test for macOS would be looking for a proprietary Latin font (e.g. /System/Library/Fonts/Palatino.ttc /System/Library/Fonts/Menlo.ttc).

    • Note that CTeX's code is still reasonable, because the purpose of detecting OS for CTeX is to determine which Chinese font can be embedded for the environment.

Thanks for the extra details! Testing for Palatino sounds like a pretty safe bet.

Is this covered by the existing code? Are you asking us to consider moving to stable?

I think the request is for \sys_if_platform_macos:pTF (or similar) as well. It can be done by checking for (say) the existence of a file of a mac-specific font or system file.

Just for your information:

Sorry, /System/Library/Fonts/Palatino.ttc exists since 10.9 Mavericks (for 10.8 Mountain Lion or earlier, it was /Library/Fonts/Palatino.ttc instead),

Starting from 10.6 Snow Leopard until 10.14 Mojave, /System/Library/Fonts/Menlo.ttc always exists. This can be a safer test.

Would my 'TeX banner' plan work? We'd have to work a little bit to get the primitives sorted ((u)pTeX/XeTeX), but that's an obvious place to find explicit OS details.

Current TeX banner does not always contain platform name.

With pdfTeX I've seen that Debian build provides (TeX Live 2018/debian) and Win32 build provides (TeX Live 2018/W32TeX), but others do not contain any string.

For e-(u)pTeX, we already have a candidate implementation for the banner primitive: https://github.com/texjporg/tex-jp-build/compare/banner

The remaining issues are its name (\epTeXbanner, \eptexbanner, vs. more generic one like \enginebanner?) and the necessity.

@aminophen Well it sounds like that approach won't do the job: I couldn't remember what MacOS TeX systems have in the banner. So it's not worth worrying about, I suspect. Probably looking for a marker file is the best we can do

something like a base system font might be a good enough indicator for something like OSX, on the other hand tht always has a danger that future versions or regional variant don't have it. Somehow it seems to me that it shouldn't be too difficult if the engines are providing that info instead (provided one gets an agreement what they provide)

@FrankMittelbach You are thinking of something like \platformname as a primitive? One to raise on the TL list perhaps?

@josephwright yes something like that with defined results across the engines, so that all report the same value of on the same platform (and maybe "unknown" for uncommon/not standardized platforms).

@FrankMittelbach Would definitely be better than trying to guess with system dependent quirks. The relevant C system calls should be quite easy to use.

Just googling, I found this: https://stackoverflow.com/questions/3596310

I'm not sure whether that function is actually available on all platform. Also, I don't know about the complete list of returned "sysname".

-- Anyway, if you choose to propose an engine-level addition, I hope this is the last proposal regarding architecture info. I mean, if there is a possibility of future proposal (e.g. detecting 32/64bit, or detecting OS revision), they should be raised here as well. I'm not very comfortable about adding new primitives like that from time to time, because testing on various platforms is usually difficult.

I think at present we've likely covered as much as we reasonably can here in expl3: the font business likely has to be handled by dedicated code.

@josephwright Sorry I'd meant to come back to this. IMO it would be very safe to test for /System/Library/Fonts/Menlo.ttc as a fast and robust method to query whether we are running in mac OS. It's been there for a long time so will work on older platforms; it's a core part of the OS so extremely unlikely to disappear and should be robust across region installations; it's in a path that is unlikely to be replicated on other platforms; the font file Menlo.ttc itself AFAIK is not available in any 3rd party way.

I'd propose adding this test, and the worst that can happen is if it does get some use, and is found to have some edge cases, we can explore more robust OS detection via primitives or similar. I can add a branch for this if you like?

@wspr Is the plan just to split the current \sys_if_platform_unix:(TF) such that it's not true for MacOS? Or do you want a separate \sys_if_platform_macos:(TF) test? I can see the logic in both approaches.

@josephwright I would think "if unix" would return true for mac OS. And probably also for the Windows Subsystem for Linux?? I can't test that.

@wspr I checked the WSL: it reports 'unix'.

At present we have \c_sys_platform_str whic will be windows or unix: do we change that on MacOS?

On 5/6/19 10:37, Joseph Wright wrote:

@wspr https://github.com/wspr I checked the WSL: it reports '|unix|'.

At present we have |\c_sys_platform_str| whic will be |windows| or
|unix|: do we change that on MacOS?

This is basically the same question as the \sys_if_engine_luatex:TF and
\c_sys_engine_str we had in some other issue.

I suggest making \c_sys_engine_str and \c_sys_platform_str as specific
as can be (within reason, so not including versions and what not), but
allowing several \sys_if_engine_... and \sys_if_platform_... to be true.
My opinion is not strongly held.

I concur with Bruno...

Need to mention that, in macOS Catalina (10.15), Songti.ttc and a lot of other fonts are moved to /System/Library/Fonts/Supplemental/.

Was this page helpful?
0 / 5 - 0 ratings