将两个不同的 .sty 文件合并为一个

将两个不同的 .sty 文件合并为一个

我很确定我犯了一个非常简单的错误,但我却为此困扰了好几个小时。

因此,情况如下:我经常使用 chet.sty 来编写我的 pdf。但是,我更愿意只将 jheppub.sty 的格式用于作者、所属机构和电子邮件,仅此而已。因此,理想情况下,我只想将 jheppub.sty 的相关部分复制并替换为 chet.sty,然后创建我的文档。

我从 jheppub.sty 中分离出与隶属关系、作者和电子邮件相关的部分,并将其复制到 chet.sty 中,但遇到了一些问题。

有人有什么想法吗?

我理想中希望实现的目标如下:

\documentclass[12pt]{article}
%%%%%
\usepackage{chet}
%%%%%
\title{Take no prisoners}
%%%%%
\author[a]{Megadeth}
%%%%%
\affiliation[a]{Rust In Peace...Polaris}
%%%%%
\emailAdd{[email protected]}
%%%%%
\abstract{ 
A true masterpiece
}
%%%%%
\date{\today}
%%%%%
\begin{document}
No one knew what would happen there
No one spoke no one even dared
Don't ask what you can do for your country
Ask what your country can do for you
\end{document}

运行无任何问题。

我提供了相关 .sty 文件的链接,因为它们太长,无法在此明确提供。

  1. 切特·斯蒂文件
  2. 韋普出版社文件

我尝试了以下操作:我从第二个 .sty 中取出以下部分

%authors and affiliations
\newtoks\auth@toks
\renewcommand{\author}[2][]{%
  \if!#1!%
    \auth@toks=\expandafter{\the\auth@toks#2\ }%
  \else
    \auth@toks=\expandafter{\the\auth@toks#2$^{#1}$\ }%
  \fi
}

\newtoks\affil@toks\newif\ifaffil\affilfalse
\newcommand{\affiliation}[2][]{%
\affiltrue
  \if!#1!%
    \affil@toks=\expandafter{\the\affil@toks{\item[]#2}}%
  \else
    \affil@toks=\expandafter{\the\affil@toks{\item[$^{#1}$]#2}}%
  \fi
}

%emails
%automatically put a comma between emails
\newtoks\email@toks\newcounter{email@counter}%
\setcounter{email@counter}{0}%
\newcommand{\emailAdd}[1]{%
\emailaddtrue%
\ifnum\theemail@counter>0\email@toks=\expandafter{\the\email@toks, \@email{#1}}%
\else\email@toks=\expandafter{\the\email@toks\@email{#1}}%
\fi\stepcounter{email@counter}}
\newcommand{\@email}[1]{\href{mailto:#1}{\tt #1}}

并将其粘贴到下面的 chet.sty 中

%Titlepage
\renewcommand{\abstract}[1]{\def\@abstract {\begin{center}\textbf{Abstract} \\\end{center}#1}}
\newcommand{\affiliation}[1]{\def\@affiliation {#1}}
\newcommand{\preprint}[1]{\def\@preprint {#1}}
\abstract{}
\affiliation{}
\preprint{}

编辑:我尝试实施@DavidCarlisle 评论中的建议,但尚未成功。

答案1

将文章末尾的代码复制到名为的文件中myheader.sty,然后在之后加载它chet

  \usepackage{chet,myheader}

在此处输入图片描述


上述示例文档的 TeX 源代码:

\documentclass[12pt]{article}
\usepackage{chet,myheader}
\title{Take no prisoners}
\author[a]{First Author}
\author[b]{Second Author}
\affiliation[a]{First Affiliation}
\affiliation[b]{Second Affiliation}
\emailAdd{[email protected]}
\emailAdd{[email protected]}
\abstract{A true masterpiece}
\date{\today}
\begin{document}
\maketitle
No one knew what would happen there
No one spoke no one even dared
Don't ask what you can do for your country
Ask what your country can do for you
\end{document}

我的标题.sty

\newtoks\auth@toks
\renewcommand{\author}[2][]{%
  \if!#1!%
    \auth@toks=\expandafter{\the\auth@toks#2\ }%
  \else
    \auth@toks=\expandafter{\the\auth@toks#2$^{#1}$\ }%
  \fi
}
\renewcommand\@author{\the\auth@toks}

\newtoks\affil@toks\newif\ifaffil\affilfalse
\def\affiliation{}
\renewcommand\affiliation[2][]{%
\affiltrue
  \if!#1!%
    \affil@toks=\expandafter{\the\affil@toks&#2\\}%
  \else
    \affil@toks=\expandafter{\the\affil@toks$^{#1}$&#2\\}%
  \fi
}

\def\@affiliation{}
\renewcommand\@affiliation{%
  \ifaffil
  {\small
  \begin{tabular}{@{}r@{\,}l@{}}
    \the\affil@toks
  \end{tabular}}%
  \fi
  \ifaffil\ifemailadd\\[2ex]\fi\fi
  \ifemailadd
    \textit{E-mail:} \the\email@toks
  \fi
}

\newif\ifemailadd\emailaddfalse
\newtoks\email@toks\newcounter{email@counter}%
\setcounter{email@counter}{0}%
\newcommand{\emailAdd}[1]{%
\emailaddtrue%
\ifnum\theemail@counter>0\email@toks=\expandafter{\the\email@toks, \@email{#1}}%
\else\email@toks=\expandafter{\the\email@toks\@email{#1}}%
\fi\stepcounter{email@counter}}
\newcommand{\@email}[1]{\href{mailto:#1}{\tt #1}}

相关内容