ifplatform
Provides conditional commands to detect and respond to different operating system environments during document compilation.
Overview
Enables platform-specific customization in LaTeX documents by offering boolean tests to identify the underlying operating system. The package leverages shell escape functionality to determine whether compilation occurs on Windows, Unix-like systems (including Linux and macOS), or Cygwin environments.
- Offers straightforward boolean commands (\ifwindows, \iflinux, \ifmacosx, \ifcygwin) for platform detection
- Particularly useful for documents that need different configurations or behaviors across multiple operating systems
- Preserves Unix system information through uname output for more detailed system identification
- Commonly used in complex document templates, installation scripts, and cross-platform documentation projects
Getting Started
To use ifplatform
, include it in your document preamble:
\documentclass{article}
\usepackage{ifplatform}
This package requires shell escape to be enabled for proper functionality. Compile your document with:
pdflatex -shell-escape document.tex
After loading the package, you can use the provided conditionals to detect the operating system:
\ifwindows
% Windows-specific code
\else
% Non-Windows code
\fi
\iflinux
% Linux-specific code
\fi
\ifmacosx
% macOS-specific code
\fi
\ifcygwin
% Cygwin-specific code
\fi
Examples
Using ifplatform to display different messages based on the operating system.
\noindent
This document was compiled on:
\ifwindows
Windows operating system
\fi
\iflinux
Linux operating system
\fi
\ifmacosx
macOS operating system
\fi
\ifcygwin
Cygwin environment
\fi
Creating platform-specific file paths in LaTeX documents.
\documentclass{article}
\usepackage{ifplatform}
\usepackage{graphicx}
% Define platform-specific paths
\newcommand{\imagepath}{}
\ifwindows
\renewcommand{\imagepath}{C:/Images/}
\else
\renewcommand{\imagepath}{/home/user/images/}
\fi
\begin{document}
\noindent
The image path for this system is: \texttt{\imagepath}
% Example of how you might use this with graphics
% \includegraphics{\imagepath example.png}
\end{document}
Using ifplatform with the uname output to detect specific Unix variants.
\noindent
Operating system information:
\ifwindows
Running on Windows
\else
\ifcygwin
Running on Cygwin
\else
Running on a Unix-like system
\ifmacosx
Specifically on macOS
\fi
\iflinux
Specifically on Linux
\fi
% The uname output is available in \platformname
\ifx\platformname\empty
(uname information not available)
\else
System identification (from uname): \texttt{\platformname}
\fi
\fi
\fi