请考虑下面这段我复制并修改过的代码cas-common.sty
:
\tl_new:N \g_stm_mydate_day_tl
\tl_new:N \g_stm_mydate_year_tl
\cs_new:Npn \date_parse:n #1 { \date_parse_aux:w #1 \q_stop }
\cs_new:Npn \date_parse_aux:w #1 / #2 / #3 \q_stop
{ <do something with the date> } %<------ What does this? It is a warning or it is ready to write a command instead of text?
\NewDocumentCommand \storemydate { O{} m }
{
\tl_if_eq:nnTF { #1 } { day }
{ \tl_if_gput_right:Nn \g_stm_mydate_day_tl { #2 } }
{ \tl_if_gput_right:Nn \g_stm_mydate_year_tl { #2 } }
}
首先,第三和第四个代码是起什么作用的?
其次,我知道最后一段代码是一个命令,我可以使用它,\storemydate[optional]{argument}
而且似乎第一个返回 true 比较,第二个返回 false 结果。但是当我使用\storemydate[day]{02 September}
它时会返回Undefined control sequence. \storemydate[day]{02 Sep}
错误。(Pdflatex
TexLive 2021)
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \g_stm_mydate_day_tl
\tl_new:N \g_stm_mydate_year_tl
\cs_new:Npn \date_parse:n #1 { \date_parse_aux:w #1 \q_stop }
\cs_new:Npn \date_parse_aux:w #1 / #2 / #3 \q_stop
{ <do something with the date> } %<------ What does this? It is a warning or it is ready to write a command instead of text?
\NewDocumentCommand \storemydate { O{} m }
{
\tl_if_eq:nnTF { #1 } { day }
{ \tl_if_gput_right:Nn \g_stm_mydate_day_tl { #2 } }
{ \tl_if_gput_right:Nn \g_stm_mydate_year_tl { #2 } }
}
\ExplSyntaxOff
\begin{document}
\section{Test}
\storemydate[day]{02 Sep}
\end{document}
答案1
您没有显示错误消息,即
! Undefined control sequence.
<argument> \tl_if_gput_right:Nn
\g_stm_mydate_day_tl {02 Sep}
l.24 \storemydate[day]{02 Sep}
?
显示\tl_if_gput_right:Nn
未定义,可能是拼写错误\tl_gput_right:Nn
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \g_stm_mydate_day_tl
\tl_new:N \g_stm_mydate_year_tl
\cs_new:Npn \date_parse:n #1 { \date_parse_aux:w #1 \q_stop }
\cs_new:Npn \date_parse_aux:w #1 / #2 / #3 \q_stop
{ <do something with the date> } %<------ What does this? It is a warning or it is ready to write a command instead of text?
\NewDocumentCommand \storemydate { O{} m }
{
\tl_if_eq:nnTF { #1 } { day }
{ \tl_gput_right:Nn \g_stm_mydate_day_tl { #2 } }
{ \tl_gput_right:Nn \g_stm_mydate_year_tl { #2 } }
}
\ExplSyntaxOff
\begin{document}
\section{Test}
\storemydate[day]{02 Sep}
\end{document}
运行无错误,并将主要参数存储在\g_stm_mydate_year_tl
除非[day]
使用。
\usepackage{xparse}
仅在旧版本中才需要定义\NewDocumentCommand
\cs_new:Npn \date_parse:n #1 { \date_parse_aux:w #1 \q_stop }
\cs_new:Npn \date_parse_aux:w #1 / #2 / #3 \q_stop
{ <do something with the date> } %<------ What does this? It is a warning or it is ready to write a command instead of text?
这里未使用草图来拆分 yyyy/mm/dd 格式的日期,以便未编写的代码<do something with the date>
可以用作#1
年份、#2
月份和#3
日期