LaTeX: What OS do I work on?

Im writing a LaTeX package that should use \write18 . Some of the shell commands that I issue are system commands (e.g. rm vs. del ). Is there any way to determine which system Im is running on?

It would be enough to eliminate the ambiguity between Windows and other (Unix-like) systems.

+4
source share
4 answers

Take a look at the LaTeX ifplatform package. There has been a lot of discussion about robust methods across platforms, and the current release works very well.

+3
source

Not very good, but it works for me

 \newread\checkf \immediate\openin\checkf = C:/WINDOWS/win.ini \ifeof\checkf not windows \else windows\fi \closein\checkf 
+1
source

If you can mark your OS with a file you can make

 \IfFileExists{/etc/motd}{unix code here}{windows code here} 

There is nothing special about /etc/motd ; it can most likely be found on a Unix system and hardly on a Windows system. If you want to be sure of incorrectness, you must create a file specifically to mark the system, no matter how you identify it.

+1
source

My friend had the following idea that I am now using. Ive tested it only on Windows XP and OS X, where it works fine. Admittedly, a little contrived, but in principle it should work well almost anywhere.

 \newif\ifwindows \immediate\write18{echo $SHELL > \jobname.os} \newread\@whichos \immediate\openin\@whichos\jobname.os \read\@whichos to \@whichosshell \ifthenelse{\equal{\@whichosshell}{$SHELL }} {\windowstrue} {\windowsfalse} \closein\@whichos \ifwindows \typeout{System detected: Windows} \newcommand\DeleteFile[1]{\immediate\write18{del #1}} \else \typeout{System detected: Unix-like} \newcommand\DeleteFile[1]{\immediate\write18{rm #1}} \fi % Cleanup. \DeleteFile{\jobname.os} 

The key point here is that Windows will not expand the $SHELL environment variable (any other variable is done, really), so it will literally write the $SHELL line to the file.

0
source

Source: https://habr.com/ru/post/1299127/


All Articles