3

Let's say I want to create a document class. Is there a way to make LaTex choose between packages (or package options) depending on the OS I'm working on?

More precisely, I want LaTeX to switch automatically between \RequirePackage[utf8]{inputenc} on Linux derivatives and \RequirePackage[latin1]{inputenc} on Windows.

makreto
  • 31
  • Package ifplatform should help –  Dec 03 '14 at 21:53
  • Why is your file in different encodings on the two platforms? – Joseph Wright Dec 03 '14 at 22:00
  • 3
    It is possible but a bad idea, the file encoding is independent of the operating system. windows is just as likely and capable of using utf8 as linux, and many older linux installations will default to latin1. The class should never default the encoding, which is a property of the individual document. – David Carlisle Dec 03 '14 at 22:06

1 Answers1

3

Quick and dirty solution

The package ifplatform provides four \if.... commands to check which system is underlying:

  • \ifwindows
  • \iflinux
  • \ifmacosx
  • \ifcygwin

Please note, that shell-escape must be enabled, otherwise all \if... macros by the package return false!

The basic question is, why one would use such a switch for encodings at all, as this is basically an editor setting, not an OS configuration issue.


\documentclass{article}
\usepackage{ifplatform}

% Possible, but not recommended!!!!!!!!
\iflinux
\usepackage[utf8]{inputenc}
\else
\ifwindows
\usepackage[latin1]{inputenc}
\fi
\fi


\begin{document}

\iflinux
\Huge Yes, this is the most beautiful system in the world
\else
\small Poor boy
\fi

\end{document}

enter image description here