因此,我找到了一个用于创建希腊字母枚举环境的代码,它在普通 LaTeX 文件中完全可以正常工作,但在我的 .cls 文件中却不行。当我尝试导入我的类(为了简单起见,我们将其称为 myclass)时,我在 pdf 文件中收到很多错误和 **。这是代码:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2019 myclass]
\LoadClass[twocolumn]{article}
\RequirePackage{chemgreek,textgreek}
\renewcommand*\alphgreek[1]{\expandafter\@alphgreek\csname c@#1\endcsname}
\renewcommand*\@alphgreek[1]{\csname chemgreek_int_to_greek:n\endcsname{#1}}
\renewcommand*\Alphgreek[1]{\expandafter\@Alphgreek\csname c@#1\endcsname}
\renewcommand*\@Alphgreek[1]{\csname chemgreek_int_to_Greek:n\endcsname{#1}}
\AddEnumerateCounter*{\alphgreek}{\@alphgreek}{\chemalpha}
\AddEnumerateCounter*{\Alphgreek}{\@Alphgreek}{\chemAlpha}
\newenvironment{greeklist}{\begin{enumerate}[label=(\alphgreek*)]}{\end{enumerate}}
\newenvironment{Greeklist}{\begin{enumerate}[label=(\Alphgreek*)]}{\end{enumerate}}
\endinput
当我加载 myclass 时,出现错误,并且 PDF 文件中只有符号 ** 垂直对齐:
\documentclass{myclass}
\usepackage[utf8]{inputenc}
\begin{document}
hello this is not working
\end{document}
在我发现的版本中,它有\makeatletter
第一\makeatother
部分(围绕 \renew 命令和 \AddEnumerateCounter)。我是否需要重新措辞才能将其用于 myclass.cls?
我找到了代码这里。
答案1
\renewcommand*
将您的s替换为\newcommand*
并加载 enumitem 后,
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2019 myclass]
\LoadClass[twocolumn]{article}
\RequirePackage{chemgreek,textgreek,enumitem}
\newcommand*\alphgreek[1]{\expandafter\@alphgreek\csname c@#1\endcsname}
\newcommand*\@alphgreek[1]{\csname chemgreek_int_to_greek:n\endcsname{#1}}
\newcommand*\Alphgreek[1]{\expandafter\@Alphgreek\csname c@#1\endcsname}
\newcommand*\@Alphgreek[1]{\csname chemgreek_int_to_Greek:n\endcsname{#1}}
\AddEnumerateCounter*{\alphgreek}{\@alphgreek}{\chemalpha}
\AddEnumerateCounter*{\Alphgreek}{\@Alphgreek}{\chemAlpha}
\newenvironment{greeklist}{\begin{enumerate}[label=(\alphgreek*)]}{\end{enumerate}}
\newenvironment{Greeklist}{\begin{enumerate}[label=(\Alphgreek*)]}{\end{enumerate}}
\endinput
它在我的 TeXLive2019 安装上运行良好
\documentclass{myclass}
\usepackage[utf8]{inputenc}
\begin{document}
hello this is now working
\begin{greeklist}
\item anteater
\item bear
\item cow
\end{greeklist}
\begin{Greeklist}
\item Anteater
\item Bear
\item Cow
\end{Greeklist}
\end{document}