取决于编译器的包选项

取决于编译器的包选项

我正在尝试使用自定义包,并尝试创建用于记笔记的“终极”包。现在我知道它不是很好,但它有效。现在 - 因为我犹豫不决 - 我希望能够声明两个选项:一个在使用 pdfLaTex 编译时使用相应的命令,另一个在使用 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$}

当我尝试main.tex使用该选项编译时pdftex出现此错误:

! 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

那么我做错了什么?我还能做我想做的事吗?提前非常感谢。

好的,我明白了,@moewe 的建议非常有效。

答案1

您的错误是调用\ProcessOptions两次,但这里您不需要选项:

\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

相关内容