From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/ifplatform/README | 27 ++ macros/latex/contrib/ifplatform/ifplatform.dtx | 447 +++++++++++++++++++++++++ macros/latex/contrib/ifplatform/ifplatform.ins | 48 +++ macros/latex/contrib/ifplatform/ifplatform.pdf | Bin 0 -> 151398 bytes 4 files changed, 522 insertions(+) create mode 100644 macros/latex/contrib/ifplatform/README create mode 100644 macros/latex/contrib/ifplatform/ifplatform.dtx create mode 100644 macros/latex/contrib/ifplatform/ifplatform.ins create mode 100644 macros/latex/contrib/ifplatform/ifplatform.pdf (limited to 'macros/latex/contrib/ifplatform') diff --git a/macros/latex/contrib/ifplatform/README b/macros/latex/contrib/ifplatform/README new file mode 100644 index 0000000000..6bd210e8a3 --- /dev/null +++ b/macros/latex/contrib/ifplatform/README @@ -0,0 +1,27 @@ +______________________ +The IFPLATFORM package +v0.4a 2017/10/13 + +This package uses heuristics to establish whether +the document is being processed on Windows or a *NIX +platform (Mac OS X, Linux, etc.). + +Except if you're using LuaTeX where this information +is already known. Otherwise, shell escape is required +to differentiate different *NIX platforms. + +Booleans provided are: + - ifwindows + - iflinux + - ifmacosx + - ifcygwin + +Finally, the \platformname macro is also provided that +expands to a string of the platform name. + +Will Robertson wspr 81 at gmail dot com +Johannes Große + +Copyright 2007-2017 Will Robertson +Copyright 2007 Johannes Große +Distributed under the LaTeX Project Public License diff --git a/macros/latex/contrib/ifplatform/ifplatform.dtx b/macros/latex/contrib/ifplatform/ifplatform.dtx new file mode 100644 index 0000000000..0fe2dd70b5 --- /dev/null +++ b/macros/latex/contrib/ifplatform/ifplatform.dtx @@ -0,0 +1,447 @@ +%\iffalse +%<*internal> +\iffalse +% +%<*internal> +\fi +\begingroup +% +%<*batchfile> +\input docstrip.tex +\keepsilent +\preamble + ________________________________________________________ + Copyright (C) 2007-2017 Will Robertson & Johannes Große + License information appended. +\endpreamble +\postamble +Copyright (C) 2007-2017 by Will Robertson & Johannes Große + +Distributable under the LaTeX Project Public License, +version 1.3c or higher (your choice). The latest version of +this license is at: http://www.latex-project.org/lppl.txt + +This work is "author-maintained" by Will Robertson. + +This work consists of the file ifplatform.dtx + and the derived files ifplatform.pdf, + ifplatform.sty, and + ifplatform.ins. +\endpostamble +\askforoverwritefalse +\generate{\file{ifplatform.sty}{\from{ifplatform.dtx}{package}}} +% +%\endbatchfile +%<*internal> +\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}} +\nopreamble\nopostamble +\endgroup +\immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx} +\immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo} +% +%<*driver> +\documentclass{ltxdoc} +\errorcontextlines=999 +\EnableCrossrefs +\CodelineIndex +\RecordChanges +%\OnlyDescription +\usepackage{array,booktabs,color,enumitem,geometry,hologo,microtype} +\usepackage[sc,osf]{mathpazo} +\usepackage[colorlinks]{hyperref} +\geometry{b5paper} +\linespread{1.1} % A bit more space between lines +\frenchspacing % Remove ugly extra space after punctuation +\definecolor{niceblue}{rgb}{0.2,0.4,0.8} +\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}} +\newcommand*\pkg[1]{\textsf{#1}} +\hfuzz2pt +\usepackage{ifplatform}% for version info +\ifwindows + \typeout{ifplatform debug: using Windows.} +\fi\iflinux + \typeout{ifplatform debug: using Linux.} +\fi\ifmacosx + \typeout{ifplatform debug: using Mac OS X.} +\fi\ifcygwin + \typeout{ifplatform debug: using Cygwin.} +\fi +\begin{document} +\DocInput{ifplatform.dtx} +\end{document} +% +%\fi +% +% \GetFileInfo{\jobname.sty} +% \CheckSum{0} +% \makeatletter +% +% \title{The \pkg{\jobname} package} +% \author{Original code by Johannes Gro\ss{}e\\ +% Package by Will Robertson\\ +% \color[gray]{0.5} +% \texttt{http://github.com/wspr/ifplatform}} +% \date{\fileversion\thanks{Thanks to Ken Brown, Joseph Wright, Zebb Prime, and others for testing this package.}\qquad \filedate} +% +% \maketitle +% +% \section{Main features and usage} +% +% This package provides the three following conditionals to test +% which operating system is being used to run \TeX: +% \begin{itemize}[nolistsep,label={}] +% \item \cs{ifwindows} +% \item \cs{iflinux} +% \item \cs{ifmacosx} +% \item \cs{ifcygwin} +% \end{itemize} +% If you only wish to detect \cs{ifwindows}, then it does not matter how you +% load this package. Note then that use of (Linux \emph{or} \macosxname\ \emph{or} Cygwin) can +% then be detected with \cs{ifwindows}\cs{else}. +% +% If you also wish to determine the difference between which Unix-variant +% you are using (i.e., also detect \cs{iflinux}, \cs{ifmacosx}, and \cs{ifcygwin}) then shell +% escape must be enabled. +% This is achieved by using the |-shell-escape| command line option when +% executing \LaTeX. +% +% If shell escape is not enabled, \cs{iflinux}, \cs{ifmacosx}, and \cs{ifcygwin} will all return \emph{false}. A warning will be printed in the console output to remind you in this case. +% +% \section{Auxiliary features} +% +% \cs{ifshellescape} is provided as a conditional to test whether +% shell escape is active or not. (Note: new versions of pdf\/\TeX\ +% allow you to query shell escape with \verb|\ifnum\pdfshellescape>0|\,, +% and the \pkg{pdftexcmds} package provides the wrapper \cs{pdf@shellescape} +% which works with \hologo{XeTeX}, \hologo{pdfTeX}, and \hologo{LuaTeX}.) +% +% Also, the \cmd\platformname\ command is defined to expand to a +% macro that represents the operating system. Default definitions are +% (respectively): +% \begin{quote} +% \begin{tabular}{@{}l@{\quad$\to$\quad}l} +% \cmd\windowsname & `\windowsname' \\ +% \cmd\notwindowsname & `\notwindowsname' (when shell escape is disabled) \\ +% \cmd\linuxname & `\linuxname' \\ +% \cmd\macosxname & `\macosxname' \\ +% \cmd\cygwinname & `\cygwinname' \\ +% \cmd\unknownplatform & \emph{whatever is returned by} |uname| \\ +% \end{tabular} +% \end{quote} +% E.g., if \cs{ifwindows} is \emph{true} then \cs{platformname} +% expands to \cs{windowsname}, which expands to `\windowsname'. +% Redefine the macros above to customise +% the output of \cmd\platformname. +% +% \begin{center}\itshape +% This documentation was compiled on \platformname. +% \end{center} +% +% \section{Other platforms} +% +% If greater granularity is required to differentiate between various \textsc{unix}-like operating systems, then \cmd\unknownplatform\ can be interrogated for the platform based on the output of |uname|. Table~\ref{table} lists possible outputs for a range of operating systems. +% +% For example, to test whether the AIX operating system is being used, you could use the following code: +% \begin{quote} +% \begin{verbatim} +%\def\myplatform{aix6} +%\ifx\myplatform\unknownplatform +% ... AIX is being used ... +%\else +% ... or not ... +%\fi +% \end{verbatim} +% \end{quote} +% The \pkg{ifthen} and \pkg{xifthen} packages might be of interest to those who prefer more \LaTeX-like methods of conditional testing. +% +% \begin{table}[hp] +% \centering +% \begin{tabular}{@{}l>{\ttfamily}c@{}} +% \toprule +% Platform & uname \textrm{string} \\ +% \midrule +% FreeBSD & {FreeBSD} \\ +% OpenBSD & {OpenBSD} \\ +% Solaris & {SunOS} \\ +% HPUX & {HP-UX} \\ +% IRIX & {IRIX64} \\ +% AIX & {aix6} \\ +% Cray UNICOS & {sn5176} \\ +% \bottomrule +% \end{tabular} +% \caption{List of operating systems and their \texttt{uname} strings. Adapted from % \url{http://en.wikipedia.org/wiki/Uname}.} +% \label{table} +% \end{table} +% +% \section{Limitations} +% +% Some technical information in case things go wrong. +% \begin{itemize} +% \item \pkg{ifplatform} checks for Windows by the presence or absence of the file `|nul:|'. If you have a file in your search path in *nix called `|nul:.tex|' (or without the |.tex|) then things may become confused. +% +% \item \pkg{ifplatform} checks for *nix by the presence or absence of the file `|/dev/null|'. If you have the file in Windows called |/dev/null.tex| (or without the extension) then things might similarly get mixed up. +% +% \item When both null files are detected (i.e., things aren't right with one of the two tests above), \pkg{ifplatform} uses another test to try and sort itself out. For interest, the test is: `|echo # > \jobname.w18|'. Under Windows you should end up with a text file containing an octothorpe. On *nix, the |#| will be seen as a comment char and the test will be ignored and the file will not be written. +% +% This `last resort' test will fail if shell escape is not enabled, or if the file |\jobname.w18| +% somehow already exists, or if the behaviour of |#| isn't as reliable as I think. +% +% \item Note that if you're running \TeX\ binaries from Cygwin on Windows, then your platform will \emph{not} be Windows. It will appear to be a *nix system, with platform name `Cygwin'. +% +% \item If you ever see the error +% \begin{quote}\ttfamily I can't tell if this is Windows or *nix; you +% appear to be neither.\end{quote} +% then I'd dearly like to know how it happened. It should +% never occur, as far as I know. +% (Update: in previous versions of this package, this message appeared when running under \hologo{LuaTeX}.) +% \end{itemize} +% Keep these points in mind and you'll never run into trouble. +% I hope you won't run into trouble in any case. +% +% \clearpage +% \StopEventually{\PrintIndex} +% \section{Implementation} +%\iffalse +%<*package> +%\fi +% \begin{macrocode} +\ProvidesPackage{ifplatform} + [2017/10/13 v0.4a Testing for the operating system] +% \end{macrocode} +% Packages required: (thanks Heiko) +% \begin{macrocode} +\RequirePackage{shellesc,pdftexcmds,catchfile,ifluatex} +% \end{macrocode} +% Conditionals we provide: +% \begin{macrocode} +\newif\ifshellescape +\newif\ifwindows +\newif\ifmacosx +\newif\iflinux +\newif\ifcygwin +% \end{macrocode} +% \begin{macro}{\windowsname} +% \begin{macro}{\notwindowsname} +% \begin{macro}{\linuxname} +% \begin{macro}{\macosxname} +% \begin{macro}{\cygwinname} +% \begin{macro}{\unknownplatform} +% Names of operating systems: +% \begin{macrocode} +\newcommand\windowsname{Windows} +\newcommand\notwindowsname{*NIX} +\newcommand\linuxname{Linux} +\newcommand\macosxname{Mac\,OS\,X} +\newcommand\cygwinname{Cygwin} +\newcommand\unknownplatform{[Unknown]} +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% For internal stuff later: +% \begin{macrocode} +\edef\ip@file{\jobname.w18} +\newif\if@ip@nix@ +% \end{macrocode} +% \begin{macro}{\ifshellescape} +% Determine if shell escape is enabled: +% \begin{macrocode} +\ifnum\pdf@shellescape=1\relax + \shellescapetrue +\else + \ifluatex\else + \PackageWarningNoLine{ifplatform}{^^J \space\space\space + shell escape is disabled, + so I can only detect \@backslashchar ifwindows% + } + \fi +\fi +% \end{macrocode} +% \end{macro} +% An error message for when things go wrong: +% \begin{macrocode} +\def\ip@cantdecide{% + \PackageWarningNoLine{ifplatform}{^^J \space\space\space + I can't tell if this is Windows or *nix; + you appear to be both% + }% +} +% \end{macrocode} +% Now the platform test. In Lua\TeX\ this is straightforward: +% \begin{macrocode} +\ifluatex + \csname\directlua{ + if os.type == "unix" then + tex.sprint("@ip@nix@true") + elseif os.type == "windows" then + tex.sprint("windowstrue") + end + }\endcsname +\else +% \end{macrocode} +% Otherwise we need to +% test for the null files of Windows and *nix. +% (This doesn't work at all in LuaTeX. Not sure why; haven't looked.) +% In a normal situation, this is all we need to do: +% \begin{macrocode} + \IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true} + \IfFileExists{/dev/null}{\windowsfalse}{\windowstrue} +% \end{macrocode} +% \begin{table} +% \centering +% \begin{tabular}{@{}llll@{}} +% \toprule +% File & Exists & Windows? & *nix? \\ +% \midrule +% \texttt{nul:} & true & Probably & Maybe \\ +% & false & Definitely not & Definitely \\ +% \texttt{/dev/null} & true & Maybe & Probably \\ +% & false & Definitely & Definitely not \\ +% \bottomrule +% \end{tabular} +% \caption{Possibilities for testing null files and their prospects for determining the platform.} +% \label{tbl} +% \end{table} +% However, sometimes that's not good enough. +% If things go wrong above, we still don't know which platform. Can only proceed if shell escape is on; fallback heuristic: +% \begin{itemize}[nolistsep] +% \item If the tmp file exists +% \begin{itemize}[nolistsep] +% \item Tell them to delete it and abort. +% \item Otherwise: +% \end{itemize} +% \item Write to it with |echo| that only works on Windows +% \item Then see again if it exists +% \begin{itemize}[nolistsep] +% \item If the tmp file exists: Windows (and delete the file) +% \item Otherwise: *nix +% \end{itemize} +% \end{itemize} +% Here's the code for the above `last resort' test: +% \begin{macrocode} + \edef\ip@windows@echo@test{echo \string# > "\ip@file"} + \def\ip@backupplan{% + \IfFileExists{\ip@file}{% + \PackageWarningNoLine{ifplatform}{^^J \space\space\space + Please delete the file "\ip@file" and try again% + }% + \ip@cantdecide + }{% + \ShellEscape{\ip@windows@echo@test}% + \IfFileExists{\ip@file}{% + \ShellEscape{del "\ip@file"}% + \windowstrue + }{% + \@ip@nix@true + }% + }% + } +% \end{macrocode} +% Now we use some odd logic to deduce what's happening in the edge cases when things go wrong: (see table~\ref{tbl}) +% \begin{macrocode} + \ifwindows + \if@ip@nix@ + \PackageWarningNoLine{ifplatform}{^^J \space\space\space + I can't tell if this is Windows or *nix; + you appear to be neither% + } + \fi + \else + \if@ip@nix@\else + \ifshellescape + \ip@backupplan + \else + \ip@cantdecide + \fi + \fi + \fi +\fi +% \end{macrocode} +% Needed below: +% \begin{macrocode} +\def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6} +% \end{macrocode} +% +% \begin{macro}{\iflinux} +% \begin{macro}{\ifmacosx} +% \begin{macro}{\ifcygwin} +% Now test for the others; directly test for Linux and Mac\,OS\,X; but what about Solaris or FreeBSD or \dots\ ? +% Define \cmd\unknownplatform\ as the output of |uname| rather than enumerate the possibilities. +% \begin{macrocode} +\if@ip@nix@\ifshellescape + \ifwindows\else + \ShellEscape{uname -s > "\ip@file"} + \CatchFileDef\@tempa{\ip@file}{} + \ShellEscape{rm -- "\ip@file"} +% \end{macrocode} +% Kill a trailing space: +% \begin{macrocode} + \edef\@tempa{\expandafter\zap@space\@tempa\@empty} + \def\@tempb{Linux} + \ifx\@tempa\@tempb + \linuxtrue + \else + \def\@tempb{Darwin} + \ifx\@tempa\@tempb + \macosxtrue + \else + \def\@tempb{CYGWIN} + \edef\@tempc{\expandafter\ip@only@six\@tempa------\@nil} + \ifx\@tempb\@tempc + \cygwintrue + \else + \edef\unknownplatform{\@tempa} + \fi + \fi + \fi + \fi +\fi\fi +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\platformname} +% Defined in terms of macros so the output is user-customisable. +% \begin{macrocode} +\edef\platformname{% + \ifwindows + \noexpand\windowsname + \else + \ifshellescape + \iflinux + \noexpand\linuxname + \else + \ifmacosx + \noexpand\macosxname + \else + \ifcygwin + \noexpand\cygwinname + \else + \noexpand\unknownplatform + \fi + \fi + \fi + \else + \noexpand\notwindowsname + \fi + \fi +} +% \end{macrocode} +% \end{macro} +%\iffalse +% +%\fi +% +% \Finale +% +% \typeout{------------------------------------------------------} +% \typeout{ To finish the installation please move the following} +% \typeout{ file into a directory searched by LaTeX:} +% \typeout{ \space- ifplatform.sty} +% \typeout{------------------------------------------------------} +% +\endinput diff --git a/macros/latex/contrib/ifplatform/ifplatform.ins b/macros/latex/contrib/ifplatform/ifplatform.ins new file mode 100644 index 0000000000..d1a940ed53 --- /dev/null +++ b/macros/latex/contrib/ifplatform/ifplatform.ins @@ -0,0 +1,48 @@ +%% +%% This is file `ifplatform.ins', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% ifplatform.dtx (with options: `batchfile') +%% ________________________________________________________ +%% Copyright (C) 2007-2017 Will Robertson & Johannes Große +%% License information appended. +\input docstrip.tex +\keepsilent +\preamble + ________________________________________________________ + Copyright (C) 2007-2017 Will Robertson & Johannes Große + License information appended. +\endpreamble +\postamble +Copyright (C) 2007-2017 by Will Robertson & Johannes Große + +Distributable under the LaTeX Project Public License, +version 1.3c or higher (your choice). The latest version of +this license is at: http://www.latex-project.org/lppl.txt + +This work is "author-maintained" by Will Robertson. + +This work consists of the file ifplatform.dtx + and the derived files ifplatform.pdf, + ifplatform.sty, and + ifplatform.ins. +\endpostamble +\askforoverwritefalse +\generate{\file{ifplatform.sty}{\from{ifplatform.dtx}{package}}} +\endbatchfile +%% Copyright (C) 2007-2017 by Will Robertson & Johannes Große +%% +%% Distributable under the LaTeX Project Public License, +%% version 1.3c or higher (your choice). The latest version of +%% this license is at: http://www.latex-project.org/lppl.txt +%% +%% This work is "author-maintained" by Will Robertson. +%% +%% This work consists of the file ifplatform.dtx +%% and the derived files ifplatform.pdf, +%% ifplatform.sty, and +%% ifplatform.ins. +%% +%% End of file `ifplatform.ins'. diff --git a/macros/latex/contrib/ifplatform/ifplatform.pdf b/macros/latex/contrib/ifplatform/ifplatform.pdf new file mode 100644 index 0000000000..a3548e28cb Binary files /dev/null and b/macros/latex/contrib/ifplatform/ifplatform.pdf differ -- cgit v1.2.3