0

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.

3
  • 1
    It might be a nicer idea to load the package 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 with iftex's \ifpdftex etc. etc.
    – moewe
    Jul 19, 2020 at 13:52
  • But to address the trouble with your MWE: I think you only want to call \ProcessOptions\relax once and only after all options have been defined with \DeclareOption.
    – moewe
    Jul 19, 2020 at 13:58
  • 1
    you should not need pdftex and xetex options the system already knows whether it is running on xetex or pdftex, if you use iftex package as moewe suggests the \if... will be set automatically, you do not need a user option to set them. Jul 19, 2020 at 17:40

1 Answer 1

0

Your error is calling \ProcessOptions twice but you do not need an option here:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notetaking}[2020/07/19 Necessary Packages for Note Keeping in LaTeX]

\RequirePackage{iftex}


\iftutex % xetex or luatex
    \RequirePackage{fontspec}
    \RequirePackage{polyglossia}
    
    %%Language related settings.
    \setmainlanguage{greek}
    \setmainfont[
        Mapping = tex-text,
        Script = Greek,
        Extension = .ttf,
        BoldFont = timesbd,
        ItalicFont = timesi,
        BoldItalicFont = timesbi
    ]{times}
\else
% classic 8bit tex (latex or pdftex)
    \RequirePackage[utf8]{inputenc}
    \RequirePackage[english, greek]{babel}
    
    %%Language related settings.
    \newcommand{\en}[1]{\selectlanguage{english}#1\selectlanguage{greek}}
\fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .