isodate:\date 位于 \daterange 内

isodate:\date 位于 \daterange 内

我目前正在使用该isodate包执行定位特定的日期格式。我将某些日期存储在变量中,因为我在整个文档中都会使用它们。不幸的是,这些存储的日期不能在内部使用\daterange。可以使用以下代码演示这一点:

\documentclass{scrreport}
\usepackage[german]{babel}
\usepackage[german]{isodate}

\newcommand{\mydate}{\date{2022-10-10}}

\begin{document}
This works: \daterange{2022-10-10}{2022-10-20}\par
%This does not \daterange{\mydate}{2022-10-20}\par
\end{document}

删除注释会导致编译时出现以下错误消息:

This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2022-06-01> patch level 5
L3 programming layer <2022-08-30>
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrreport.cls
Document Class: scrreport 2022/07/04 v3.37 KOMA-Script document class (report)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrreprt.cls
Document Class: scrreprt 2022/07/04 v3.37 KOMA-Script document class (report)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile-hook.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlogo.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/typearea.sty)))
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
(/usr/share/texlive/texmf-dist/tex/generic/babel/txtbabel.def)
(/usr/share/texlive/texmf-dist/tex/generic/babel-german/german.ldf
(/usr/share/texlive/texmf-dist/tex/generic/babel-german/germanb.ldf)))
(/usr/share/texlive/texmf-dist/tex/generic/babel/locale/de/babel-german.tex)
(/usr/share/texlive/texmf-dist/tex/latex/isodate/isodate.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/substr/substr.sty)
(/usr/share/texlive/texmf-dist/tex/latex/isodate/german.idf
Define commands for German date format (german)
)) (/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./mwe.aux)
isodate: babel.sty has been loaded
! Undefined control sequence.
<argument> \equal
                  {\iso@dateformat }{iso}\OR \equal {\iso@dateformat }{TeX}
l.9 This does not \daterange{\mydate}{2022-10-20}
                                                 \par

我可以重新定义\mydate为,\newcommand{\mydate}{2022-10-10}但这样我就需要\date在我想要使用的地方使用\mydate。是否可以放在\date里面\daterange?只要可以进行特定于语言环境的格式化,我也愿意使用其他包。

提前致谢!

答案1

您可以\mydate通过更简单的方式定义\def\mydate{2022-10-10},并且可以定义一个“前缀宏” \paramXX,它在给定宏读取两个参数之前扩展它们。

\def\paramXX#1#2#3{\expandafter#1\expanded{{#2}{#3}}}
\def\mydate{2022-10-10}

现在

This works: \paramXX\daterange{\mydate}{2022-10-20}

相关内容