以自定义样式声明默认选项

以自定义样式声明默认选项

我想创建一个样式文件,让我可以在文档的两个版本之间进行选择,一个版本包含识别信息,另一个版本不包含识别信息——“适合盲审”。

我的想法是将识别信息包含在参数 \full{...} 中,将盲审的替代方案包含在 \blind{...} 中,然后通过样式文件中的选项选择要打印的内容。这是最小样式文件和相应 .tex 文件的 MWE。

样式文件:

\ProvidesPackage{blinding}

\DeclareOption{blind}{%
%%% Code to print blinded version
%
% This code and the next option ("Full") are designed so that the
% source code contains alternatives for identifying
% information. Identifying information is enclosed in \full{...},
% blinded alternative information is enclosed in \blind{...}.
 \newcommand{\blind}[1]{#1}
 \newcommand{\full}[1]{}
}

\DeclareOption{full}{%
%%% Code to print the full version, including identifying information
\newcommand{\blind}[1]{}
\newcommand{\full}[1]{#1}
}

% Sets the default option to "full". (????)
\ExecuteOptions{full}

\ProcessOptions \relax

这个想法是,当调用“完整”选项时,所有内容 \blind{...}都会被跳过,并且予以适当修改为“盲”选项。简单的 MWE 如下。

\documentclass{article}

\usepackage{blinding}

\begin{document}
Some regular materials

\full{something in the full version}

\blind{something blinded}
\end{document}

.tex当我从文档中明确调用这些选项时,如果.sty文件没有该命令,它们就会按照我的要求工作\ExecuteOptions。唯一的问题是,我不知道如何将“full”设置为默认值,以便我可以覆盖

我追求的最终结果是这种行为:

  • 作者未声明选项:打印完整版本
  • 作者声明的“完整”选项:打印完整版本
  • 作者声明的“盲”选项:打印盲版本

答案1

您的问题是,full示例中的选项先执行,然后评估选项。因此,\newcommand{...}[1]{...}在盲选项中不起作用。相反,您应该使用\renewcommand

\ProvidesPackage{blinding}

\DeclareOption{blind}{%
%%% Code to print blinded version
%
% This code and the next option ("Full") are designed so that the
% source code contains alternatives for identifying
% information. Identifying information is enclosed in \full{...},
% blinded alternative information is enclosed in \blind{...}.
 \renewcommand{\blind}[1]{#1}
 \renewcommand{\full}[1]{}
}

\DeclareOption{full}{%
%%% Code to print the full version, including identifying information
\newcommand{\blind}[1]{}
\newcommand{\full}[1]{#1}
}

% Sets the default option to "full". (????)
\ExecuteOptions{full}

\ProcessOptions \relax

当您使用blind-package 选项时这应该可以工作blinding

编辑:但该选项full仍然不起作用,因为\newcommands 将被调用两次。您可以进一步将其更改为:

\ProvidesPackage{blinding}

\newcommand{\blind}[1]{}
\newcommand{\full}[1]{#1}

\DeclareOption{blind}{%
%%% Code to print blinded version
%
% This code and the next option ("Full") are designed so that the
% source code contains alternatives for identifying
% information. Identifying information is enclosed in \full{...},
% blinded alternative information is enclosed in \blind{...}.
 \renewcommand{\blind}[1]{#1}
 \renewcommand{\full}[1]{}
}

\DeclareOption{full}{%
%%% Code to print the full version, including identifying information
\renewcommand{\blind}[1]{}
\renewcommand{\full}[1]{#1}
}

\ProcessOptions \relax

这样该full选项就可以起作用(但是已经完全过时,因为它没有改变任何东西)。

相关内容