2010-01-22 33 views

回答

3

查看LaTeX ifplatform軟件包。關於各種平臺可靠方法的討論很多,目前的版本工作得很好。

+0

不錯。它使用'\ IfFileExists'作爲Unix系統的'/ dev/null'和Windows''nul:'。如果發生錯誤,還會出現一大堆古怪的回退。 +1 – 2010-01-23 01:39:31

+1

[link to package](https://www.ctan.org/tex-archive/macros/latex/contrib/ifplatform?lang=en) – 2015-08-07 02:11:53

1

不是很好,但它爲我工作

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

如果你可以標記一個文件,你的操作系統,你可以做

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

沒有什麼特別之處的路徑/etc/motd;它很可能在Unix系統上找到,而在Windows系統上則不太可能。如果你想確定某個特定的文件,你應該創建一個專門用來標記系統的文件,而不管你想識別它。

+0

這個想法與阿列克謝的相似,它很不錯。但我無法控制這個系統,是的,我寧願死心眼,因爲這將會公開發布。 ;-) – 2010-01-22 20:46:03

0

我的一位朋友有我正在使用的以下想法。我只在Windows XP和OS X上測試過,它工作正常。誠然,測試有點脆弱,但原則上它幾乎可以在任何其他地方正常工作。

\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} 

的關鍵在這裏的是,Windows將無法展開$SHELL環境變量(任何其他變量會做的,真的),所以這將字面上寫的字符串$SHELL到文件中。

相關問題