A3试卷模板的宏包GEEexam文件中如何添加自定义命令?

发布于 2024-09-26 18:00:07

这是.sty文件:

GEEexam.sty

这是要粘贴的内容:

%A3试卷模板的宏包GEEexam文件中如何添加自定义命令?将自定义命令剪切粘贴至宏包尾部,运行出错!


\documentclass[11pt,space]{ctexart} 

\usepackage{GEEexam}%需安装宏包GEEexam %安装路径E:\texlive\2023\texmf-dist\tex\latex\GEEexam

%以下自定义命令已经粘贴在宏包GEEexam的最后,如果此处删除以下命令,则运行出错
%==============================自定义命令=======================================================
%====填空题横线
\ExplSyntaxOn
\NewDocumentCommand \sh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 0.8cm{}}\,}{\,\underline{\hbox to 0.8cm{\hfill#1\hfill}}\,}}%-------更短横线
\ExplSyntaxOff 

\ExplSyntaxOn
\NewDocumentCommand \hh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------短横线
\ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand \hhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 2.5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}
\ExplSyntaxOff
%  用法:\hhh输出_______ ;\hhh{增}输出______增_______;\hhh{\raisebox{.8ex}{$[\frac{\pi}{12},\frac{5\pi}{12}]$}}

\ExplSyntaxOn
\NewDocumentCommand \hhhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------加长横线
\ExplSyntaxOff 

%====阿拉伯数字转罗马数字\rmnum{ }\Rmnum{ }
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

%====带圈数字2 \circnum{1} 项目编号:[\label=\circnum{\arabic*}]
\newcommand{\circled}[2][]{\tikz[baseline=(char.base)]
    {\node[shape = circle, draw, inner sep = -1pt]%圈大小
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\newcommand{\circnum}[1]{\circled[00]{\footnotesize#1}}%数大小

%====正体数学符号
\newcommand{\R}{\mathrm{\mathbf{R}}}
\newcommand{\N}{\mathrm{\mathbf{N}}}
\newcommand{\Q}{\mathrm{\mathbf{Q}}}
\newcommand{\Z}{\mathrm{\mathbf{Z}}}
\newcommand{\dt}{\,\symup{d} t}
\newcommand{\dx}{\,\symup{d} x}
\newcommand{\dy}{\,\symup{d} y}

%====圆弧\wideparen{ }
\DeclareSymbolFont{ugmL}{OMX}{mdugm}{m}{n}
\SetSymbolFont{ugmL}{bold}{OMX}{mdugm}{b}{n}
\DeclareMathAccent{\wideparen}{\mathord}{ugmL}{"F3}

%====平行四边形\parallelogram
\newcommand*\parallelogram{%
  \mathord{\text{%
    \tikz[baseline]
      \draw (0,.1ex) -- (.8em,.1ex) -- (1em,1.4ex) -- (.2em,1.4ex) -- cycle;}}}

%====平行且相等\paralleleq
\usepackage{pict2e}
\newcommand\paralleleq{%
  \begingroup
  \setlength\unitlength{0.1em}%
  \linethickness{0.5\unitlength}%
  \roundcap
  \mathrel{\begin{picture}(6,7)
    \Line(0,-1)(6,-1)
    \Line(0,0.5)(6,0.5)
    \Line(1.5,1.5)(3.5,7)
    \Line(3.5,1.5)(5.5,7)
  \end{picture}}
  \endgroup}

%====全等\congruent
\newcommand*\congruent{%
    \mathrel{\text{%
    \tikz \draw[baseline] (-.22em,-.4ex) arc (-90:-285:0.4ex) (-.22em,-.4ex) .. controls (0,-.4ex) and (0,.4ex) .. (.22em,.4ex) arc (90:-105:0.4ex) (-.4em,-.75ex) -- (.4em,-.75ex) (-.4em,-1.1ex) -- (.4em,-1.1ex);%
}}}

%====绝对值\abs{ }
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%====列举法表示集合\set
\newcommand\set[1]{\left\{\rule{0cm}{1.7ex} {#1} \right\}}

%====描述法表示集合\Set
\newcommand\Set[2]{\left\{\rule{0cm}{1.7ex}\, {#1} \, \middle\vert \, {#2} \,\right\}}
%=====================================自定义命令结束========================================================

\begin{document}
        
    填空题横线\hhh
    
    阿拉伯数字转罗马数字~$\Rmnum{3}$
    
    带圈数字~$\circnum{1}$
    
    正体符号~$\R$
    
    圆弧~$\wideparen{AB}$
    
    平行四边形~$\parallelogram$
    
    平行且相等~$\paralleleq$
    
    全等~$\congruent$
    
    绝对值~$\abs{x}$
    
    列举法~$\set{1,2,3}$
    
    描述法~$\Set{x}{1<x<2}$

\end{document}

将自定义命令剪切粘贴至宏包尾部,运行出错!

查看更多

关注者
0
被浏览
611
2 个回答
Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

提问要让别人能很容易弄懂你的具体问题。

很难搞懂你的问题是这个问题没人回答的一个重要原因。

首先,你的GEEexam.sty已经和零蛋大的官方.sty不一致,属于你的私有模板。而且把哪些部分放到你所说的\endinput之前,也是令人很费解的...

其次,你在本页面提供的GEEexam.sty文件在\endinput之后还加了很多命令,input都结束了你为什么还要加这些命令?是哪里学到的???

我猜你的意思是说,把下面这部分命令:

%以下自定义命令已经粘贴在宏包GEEexam的最后,如果此处删除以下命令,则运行出错
%==============================自定义命令=======================================================
%====填空题横线
\ExplSyntaxOn
\NewDocumentCommand \sh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 0.8cm{}}\,}{\,\underline{\hbox to 0.8cm{\hfill#1\hfill}}\,}}%-------更短横线
\ExplSyntaxOff 

\ExplSyntaxOn
\NewDocumentCommand \hh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------短横线
\ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand \hhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 2.5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}
\ExplSyntaxOff
%  用法:\hhh输出_______ ;\hhh{增}输出______增_______;\hhh{\raisebox{.8ex}{$[\frac{\pi}{12},\frac{5\pi}{12}]$}}

\ExplSyntaxOn
\NewDocumentCommand \hhhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------加长横线
\ExplSyntaxOff 

%====阿拉伯数字转罗马数字\rmnum{ }\Rmnum{ }
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

%====带圈数字2 \circnum{1} 项目编号:[\label=\circnum{\arabic*}]
\newcommand{\circled}[2][]{\tikz[baseline=(char.base)]
    {\node[shape = circle, draw, inner sep = -1pt]%圈大小
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\newcommand{\circnum}[1]{\circled[00]{\footnotesize#1}}%数大小

%====正体数学符号
\newcommand{\R}{\mathrm{\mathbf{R}}}
\newcommand{\N}{\mathrm{\mathbf{N}}}
\newcommand{\Q}{\mathrm{\mathbf{Q}}}
\newcommand{\Z}{\mathrm{\mathbf{Z}}}
\newcommand{\dt}{\,\symup{d} t}
\newcommand{\dx}{\,\symup{d} x}
\newcommand{\dy}{\,\symup{d} y}

%====圆弧\wideparen{ }
\DeclareSymbolFont{ugmL}{OMX}{mdugm}{m}{n}
\SetSymbolFont{ugmL}{bold}{OMX}{mdugm}{b}{n}
\DeclareMathAccent{\wideparen}{\mathord}{ugmL}{"F3}

%====平行四边形\parallelogram
\newcommand*\parallelogram{%
  \mathord{\text{%
    \tikz[baseline]
      \draw (0,.1ex) -- (.8em,.1ex) -- (1em,1.4ex) -- (.2em,1.4ex) -- cycle;}}}

%====平行且相等\paralleleq
\usepackage{pict2e}
\newcommand\paralleleq{%
  \begingroup
  \setlength\unitlength{0.1em}%
  \linethickness{0.5\unitlength}%
  \roundcap
  \mathrel{\begin{picture}(6,7)
    \Line(0,-1)(6,-1)
    \Line(0,0.5)(6,0.5)
    \Line(1.5,1.5)(3.5,7)
    \Line(3.5,1.5)(5.5,7)
  \end{picture}}
  \endgroup}

%====全等\congruent
\newcommand*\congruent{%
    \mathrel{\text{%
    \tikz \draw[baseline] (-.22em,-.4ex) arc (-90:-285:0.4ex) (-.22em,-.4ex) .. controls (0,-.4ex) and (0,.4ex) .. (.22em,.4ex) arc (90:-105:0.4ex) (-.4em,-.75ex) -- (.4em,-.75ex) (-.4em,-1.1ex) -- (.4em,-1.1ex);%
}}}

%====绝对值\abs{ }
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%====列举法表示集合\set
\newcommand\set[1]{\left\{\rule{0cm}{1.7ex} {#1} \right\}}

%====描述法表示集合\Set
\newcommand\Set[2]{\left\{\rule{0cm}{1.7ex}\, {#1} \, \middle\vert \, {#2} \,\right\}}
%=====================================自定义命令结束========================================================

放在main.tex就可行,放在GEEexam.cls内就会报错...

既然你说报错,为什么不提供最短的工作示例,同时提供错误信息呢???

编译你的.sty和删除你所谓“自定义命令”遇到的第一个问题是:

Undefined control sequence.
\@currentHref ->page.\theHpage

我猜这与这个问题有关。

经过测试验证,将

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\thepage  页 \refstepcounter{page}\quad (共~\pageref{LastPage}~页)\hspace*{13cm} 理科数学试题\quad 第\thepage  页 \quad (共~\pageref{LastPage}~页)}

还原为

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

这一关于唯一计数器名称的报错即消失。

我不确定是不是鱼老师修改可能有问题,但还有一个更简单修复办法,在GEEexam.sty官方版本中,有如下被注释的代码:

% Line 22~26
%% =====页眉页脚设置===========================================
%\def\lastfox@putlabel{%
%    \immediate\write\@auxout{%
%        \string\newlabel{LastFox}{{\@arabic\c@foo}{}{}{}{}}}}
%\AtEndDocument{\lastfox@putlabel}

只要同时取消这一段注释,并且使用原来的页码引用方式:

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

若如此做,则一切正常

如果看不懂模板,务必不要修改模板的任何设置。

另外,提问务必自己提取MWE(上来就是几百行然后描述也不清晰,这是正确的提问方式吗???),不然没人会看(除非闲的...)。

以下是一个完整的例子:

  • 首先是GEEexam.sty
\ProvidesPackage{GEEexam}[2017/09/27 v1.0 Non-standard LaTeX package]

%% =====添加一些数学环境的宏包==================================
\RequirePackage{amsmath,amssymb}%
\def\dif{\mathop{}\!\mathrm{d}}
\DeclareMathOperator{\rank}{rank}
\RequirePackage{bm}
\RequirePackage{pifont}
\RequirePackage{extarrows} %长等号
\RequirePackage{scalerel}%缩放公式大小
\RequirePackage{array}%m{3em}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
%% ===========================================================

%% =====设置A3试卷纸张的页边距==================================
\RequirePackage{geometry,calc}
\geometry{a3paper,twocolumn,landscape,hmargin={3.5cm,1.3cm},
vmargin={1.5cm,1.5cm},footskip=0.75cm,headsep=0.25cm}
%% ===========================================================

%% =====页眉页脚设置===========================================
\def\lastfox@putlabel{%
    \immediate\write\@auxout{%
        \string\newlabel{LastFox}{{\@arabic\c@foo}{}{}{}{}}}}
\AtEndDocument{\lastfox@putlabel}

\newcounter{foo}
\newcounter{fox}
\addtocounter{foo}{1}
\RequirePackage{tikz}
\RequirePackage{lastpage}
\newcommand{\defen}[2][1cm]{\hspace*{\fill}\raisebox{-1.1ex}{\tikz\draw[line width=1pt,dash pattern=on 1pt off 2.5pt on 1pt off 2.5pt] (0pt,0pt)--(#1 ,0pt)node[right=-1mm]{(#2~分)};}\newline}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\setlength{\columnseprule}{0.4pt}
\setlength{\columnsep}{1.8cm}
\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

% \fancyfoot[C]{\kaishu{}理科数学试题\quad 第\thepage  页 \refstepcounter{page}\quad (共~\pageref{LastPage}~页)\hspace*{13cm} 理科数学试题\quad 第\thepage  页 \quad (共~\pageref{LastPage}~页)}
\renewcommand{\headrulewidth}{0pt}
%% ===========================================================

%% =====页眉【绝密*启用前】================================
\RequirePackage{color,xcolor}
\RequirePackage{enumitem}
\def\juemi{\noindent{\heiti\zihao{-4} 绝密$\bigstar$启用前}}
\def\biaoti#1{\begin{center}{\zihao{3} #1}\end{center}}
\def\fubiaoti#1{\begin{center}{\zihao{2}\heiti #1}\end{center}}
%% ===========================================================

%% =====设置数学字体为新罗马字体================================
\RequirePackage[T1]{fontenc}
\RequirePackage{mathptmx}
\newfontfamily\TNRBI{Times New Roman Bold Italic} 
\newcommand{\bfit}[1]{\text{\TNRBI #1}} 
%% ===========================================================

%% =====设置大题标题格式=======================================
\ctexset{section = {name = {,、\hspace*{-5mm}},
number = \chinese{section},
format = {\zihao{5}\heiti\raggedright}}}
\ctexset{subsection = {name = {\hspace{5mm},\hspace*{-1mm}},
number = (\chinese{subsection}),
format = {\zihao{5}\heiti\raggedright}}}
\RequirePackage{titlesec}
\titlespacing*{\section}{0pt}{9pt}{4pt}

%% =====选择题选项格式设置====================================
\usepackage{tasks}%选择题宏包,tasks环境
% \settasks{counter-format={tsk[A].},
%               label-offset={0.4em},
%                 label-align=left,
%                 column-sep={2pt},
%                 item-indent={1pt},
%                 before-skip={-0.7em},
%                 after-skip={-0.7em}}
%                 \usepackage{tasks}%选择题宏包,tasks环境
% texlive 2021 用以下设置
%=====================================
\settasks{                           %
    label=\Alph*.,                   %
    label-offset={0.4em},            %
    label-align=left,                %
    column-sep={10pt},               %
    label-width=2ex,                 %
    item-indent={40pt},              %
    before-skip={-0.7em},            %
    after-skip={-0.7em}              %
    }                                %
%=====================================
% 选择题示例 
%\begin{tasks}(4)
%    \task 
%    \task 
%    \task 
%    \task 
%\end{tasks}
%------------------------------ 选择题 ----------------------------------%
%\setcounter{enumi}{12}

\def\tiankongdaan#1{\makebox[3em][c]{#1}}
\newcommand{\blank}[1]{\underline{\tiankongdaan{\qquad~}}}
\DeclareOption{ans}{\renewcommand{\blank}[1]{\,\underline{#1}\,
}}
\ProcessOptions

%------------------------------ 填空题 ----------------------------------%
\ExplSyntaxOn
\NewDocumentCommand \sh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 0.8cm{}}\,}{\,\underline{\hbox to 0.8cm{\hfill#1\hfill}}\,}}%-------加短横线
\ExplSyntaxOff 

\ExplSyntaxOn
\NewDocumentCommand \hh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------短横线
\ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand \hhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 2.5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}
\ExplSyntaxOff
%  用法:\hhh输出_______ ;\hhh{增}输出______增_______;\hhh{\raisebox{.8ex}{$[\frac{\pi}{12},\frac{5\pi}{12}]$}}

\ExplSyntaxOn
\NewDocumentCommand \hhhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------加长横线
\ExplSyntaxOff 
%% =====自定义数学命令=========================================
% 阿拉伯数字转罗马数字\rmnum{ }\Rmnum{ }
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

% 带圈数字2 \circnum{1} 项目编号:[\label=\circnum{\arabic*}]
\newcommand{\circled}[2][]{\tikz[baseline=(char.base)]
    {\node[shape = circle, draw, inner sep = -1pt]%圈大小
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\newcommand{\circnum}[1]{\circled[00]{\footnotesize#1}}%数大小

% 正体数学符号
\newcommand{\R}{\mathrm{\mathbf{R}}}
\newcommand{\N}{\mathrm{\mathbf{N}}}
\newcommand{\Q}{\mathrm{\mathbf{Q}}}
\newcommand{\Z}{\mathrm{\mathbf{Z}}}
\newcommand{\dt}{\,\symup{d} t}
\newcommand{\dx}{\,\symup{d} x}
\newcommand{\dy}{\,\symup{d} y}

%圆弧\wideparen{ }
\DeclareSymbolFont{ugmL}{OMX}{mdugm}{m}{n}
\SetSymbolFont{ugmL}{bold}{OMX}{mdugm}{b}{n}
\DeclareMathAccent{\wideparen}{\mathord}{ugmL}{"F3}

%平行四边形\parallelogram
\newcommand*\parallelogram{%
  \mathord{\text{%
    \tikz[baseline]
      \draw (0,.1ex) -- (.8em,.1ex) -- (1em,1.4ex) -- (.2em,1.4ex) -- cycle;}}}

%平行且相等\paralleleq
\usepackage{pict2e}
\newcommand\paralleleq{%
  \begingroup
  \setlength\unitlength{0.1em}%
  \linethickness{0.5\unitlength}%
  \roundcap
  \mathrel{\begin{picture}(6,7)
    \Line(0,-1)(6,-1)
    \Line(0,0.5)(6,0.5)
    \Line(1.5,1.5)(3.5,7)
    \Line(3.5,1.5)(5.5,7)
  \end{picture}}
  \endgroup}

%全等\congruent
\newcommand*\congruent{%
    \mathrel{\text{%
    \tikz \draw[baseline] (-.22em,-.4ex) arc (-90:-285:0.4ex) (-.22em,-.4ex) .. controls (0,-.4ex) and (0,.4ex) .. (.22em,.4ex) arc (90:-105:0.4ex) (-.4em,-.75ex) -- (.4em,-.75ex) (-.4em,-1.1ex) -- (.4em,-1.1ex);%
}}}

%绝对值\abs{ }
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%列举法表示集合\set
\newcommand\set[1]{\left\{\rule{0cm}{1.7ex} {#1} \right\}}

%描述法表示集合\Set
\newcommand\Set[2]{\left\{\rule{0cm}{1.7ex}\, {#1} \, \middle\vert \, {#2} \,\right\}}

\endinput%%%放最后
  • 用于测试的mwe.tex
\documentclass[11pt,space]{ctexart} 
\usepackage{GEEexam}
\usepackage{zhlipsum}
\begin{document}
        
    填空题横线\hhh
    
    阿拉伯数字转罗马数字~$\Rmnum{3}$
    
    带圈数字~$\circnum{1}$
    
    正体符号~$\R$
    
    圆弧~$\wideparen{AB}$
    
    平行四边形~$\parallelogram$
    
    平行且相等~$\paralleleq$
    
    全等~$\congruent$
    
    绝对值~$\abs{x}$
    
    列举法~$\set{1,2,3}$
    
    描述法~$\Set{x}{1<x<2}$

    \zhlipsum[1-10]

\end{document}

image.png

D
D 2024-09-26
这家伙很懒,什么也没写!

应该粘贴在endinput前面

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览