I'm experimenting with custom packages, and I try to create the "ultimate" package for keeping notes. Now I know it isn't great but it works. Now -because I'm indecisive- I want to be able to declare two options: one to use the corresponding commands when compiling with pdfLaTex, and one to use the corresponding when compiling with XeLaTeX.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notetaking}[2020/07/19 Necessary Packages for Note Keeping in LaTeX]
\newif\if@xetex
\DeclareOption{xetex}{\@xetextrue\@pdftexfalse}
\ProcessOptions\relax
\if@xetex
\RequirePackage{fontspec}
\RequirePackage{polyglossia}
%%Language related settings.
\setmainlanguage{greek}
\setmainfont[
Mapping = tex-text,
Script = Greek,
Extension = .ttf,
BoldFont = timesbd,
ItalicFont = timesi,
BoldItalicFont = timesbi
]{times}
\fi
\newif\if@pdftex
\DeclareOption{pdftex}{\@pdftextrue\@xetexfalse}
\ProcessOptions\relax
\if@pdftex
\RequirePackage[utf8]{inputenc}
\RequirePackage[english, greek]{babel}
%%Language related settings.
\newcommand{\en}[1]{\selectlanguage{english}#1\selectlanguage{greek}}
\fi
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{makeidx}
\RequirePackage{graphicx}
\RequirePackage{fancyhdr}
\RequirePackage{import}
\RequirePackage{lipsum}
\RequirePackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
\RequirePackage{titling}
\RequirePackage{etoolbox}
\RequirePackage{enumitem}
%%Title elated settings.
\newcommand{\subtitle}[1]{
\posttitle{
\par\end{center}
\begin{center}\large#1\end{center}
\vskip0.5em}
}
%%Page related settings
\appto\frontmatter{\pagestyle{empty}}
\appto\mainmatter{\pagestyle{fancy}}
\fancyhf{}
\fancyhead[LE,RO]{\leftmark}
\fancyhead[RE,LO]{\rightmark}
\fancyfoot[CE,CO]{Σελίδα \thepage}
%%Math related macros.
\newcommand{\R}{\mathbb{R}}
\newcommand{\br}[1]{\left\{ #1 \right\}}
\newcommand{\pr}[1]{\left( #1 \right)}
\newcommand{\nm}[1]{\left\lVert #1 \right\rVert}
\renewcommand{\vec}{\mathbf}
%% Title related macros.
\newcommand{\nd}[1]{\def\@notedt{#1}}
%%Theorem related settings.
\theoremstyle{plain}
\newtheorem*{theorem}{Θεώρημα}
\newtheorem*{lemma}{Λήμμα}
\newtheorem*{corollary}{Πόρισμα}
\newtheorem*{conjecture}{Υπόθεση}
\newtheorem*{proposition}{Πρόταση}
\newtheorem*{exercise}{Άσκηση}
\theoremstyle{definition}
\newtheorem*{definition}{Ορισμός}
\newtheorem*{problem}{Πρόβλημα}
\newtheorem*{example}{Παράδειγμα}
\newtheorem*{axiom}{Αξίωμα}
\theoremstyle{remark}
\newtheorem*{remark}{Παρατήρηση}
\newtheorem*{note}{Σημείωση}
\renewcommand\qedsymbol{$\blacksquare$}
When I try to compile my main.tex
with the option pdftex
I get this error:
! LaTeX Error: Unknown option `pdftex' for package `notetaking'.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \ProcessOptions\relax
So what am I doing wrong? Is it even possible to do what I want? Thank you very much in advance.
Okay I got it, what @moewe suggested worked like a charm.
iftex
and use it to detect the engine automatically. The current version of that package provides tests like\ifpdftex
,\ifxetex
,\ifluatex
etc. So you could simply replace your\if@pdftex
withiftex
's\ifpdftex
etc. etc.\ProcessOptions\relax
once and only after all options have been defined with\DeclareOption
.\if...
will be set automatically, you do not need a user option to set them.