
다음과 같이 (현재 달을 기준으로) 다음 달을 삽입하는 명령을 만들고 싶습니다.
\command
-> 11월
와 유사하게 \today
.
- 문서가 언어 간에 전환되므로( 에서 작동하는 것과 동일한 방식
\today
) 명령을 하드코딩할 수 없습니다. - 프리앰블 내에서 이 명령을 사용하고 싶습니다.
- 출력은 현지화되어야 합니다. 즉, 다른 곳에서는
\today
평소대로 작동해야 합니다.
이를 수행하는 가장 좋은 방법은 무엇입니까?
답변1
작동하려면 다음과 같은 것이 필요합니다.
\usepackage{datetime}
\usepackage{advdate}
\newdateformat{mydate}{\monthname[\THEMONTH]}
(...)
{\AdvMonth{1} \mydate \today}
답변2
datetime2
여기에 약간의 모듈식 산술을 사용하는 솔루션이 있습니다 .
\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[calc]{datetime2}
\ExplSyntaxOn
\NewDocumentCommand{\nextmonth} {} {
\int_eval:n {12 - \int_mod:nn {\month}{12}}{=}{0}}
\DTMmonthname{\nxtmnth:n}}
\ExplSyntaxOff
\begin{document}
Today is: \today
Next month is \nextmonth
\selectlanguage{french}
En français: \nextmonth
\end{document}
답변3
\int_mod:nn
대수 모듈로 12를 수행하려면 결과의 절대값이 모듈의 절대값보다 작고 결과의 부호가 정수 나머지를 계산해야 하는 표현식과 동일한 expl3을 사용할 수 있습니다 .
아마도 계산 결과를 제공할 것입니다.
12 - (
(
% With \int_mod:nn for doing the mod-12-calculation this
% expression yields a non-negative number...
12 - (
% ... because this is in range -11..+11 :
( ⟨number of current month⟩
+ ⟨amount of months to add or subtract⟩
) mod 12
)
) mod 12
% With \int_mod:nn the result of mod-12-calculation of a
% non-negative number is in range 0..11.
)
에게날짜/시간2'의 \DTMmonthname
트릭은 다음과 같습니다
\documentclass{article}
\usepackage[french,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[calc]{datetime2}
\ExplSyntaxOn
\NewDocumentCommand{\MonthInRelationToCurrentMonth} {m} {
\exp_args:Nf \DTMmonthname
{\int_eval:n {12-\int_mod:nn {12-(\int_mod:nn{\month+(#1)}{12})}{12}}}
}
\ExplSyntaxOff
\newcommand\NextMonth{\MonthInRelationToCurrentMonth{1}}%
\newcommand\PreviousMonth{\MonthInRelationToCurrentMonth{-1}}%
\newcommand\ThisMonth{\MonthInRelationToCurrentMonth{0}}%
\begin{document}
\bigskip\hrule\bigskip
\noindent In English
\bigskip\hrule\bigskip
\noindent
Today is \today.\\
Previous month was \PreviousMonth.\\
This month is \ThisMonth.\\
Next month will be \NextMonth.
\bigskip\hrule\bigskip
\noindent
This month is \MonthInRelationToCurrentMonth{0}.\\
This month is \MonthInRelationToCurrentMonth{+0}.\\
One month later will be \MonthInRelationToCurrentMonth{+1}.\\
Two months later will be \MonthInRelationToCurrentMonth{2}.\\
Three months later will be \MonthInRelationToCurrentMonth{3}.\\
Four months later will be \MonthInRelationToCurrentMonth{4}.\\
Five months later will be \MonthInRelationToCurrentMonth{+5}.\\
Six months later will be \MonthInRelationToCurrentMonth{+6}.\\
Seven months later will be \MonthInRelationToCurrentMonth{7}.\\
Eight months later will be \MonthInRelationToCurrentMonth{8}.\\
Nine months later will be \MonthInRelationToCurrentMonth{9}.\\
Ten months later will be \MonthInRelationToCurrentMonth{10}.\\
Eleven months later will be \MonthInRelationToCurrentMonth{11}.\\
Twelve months later will be \MonthInRelationToCurrentMonth{12}.\\
Thirteen months later will be \MonthInRelationToCurrentMonth{13}.\\
Twenty months later will be \MonthInRelationToCurrentMonth{+20}.
\bigskip\hrule\bigskip
\noindent
This month is \MonthInRelationToCurrentMonth{0}.\\
This month is \MonthInRelationToCurrentMonth{-0}.\\
One month earlier was \MonthInRelationToCurrentMonth{-1}.\\
Two months earlier was \MonthInRelationToCurrentMonth{-2}.\\
Three months earlier was \MonthInRelationToCurrentMonth{-3}.\\
Four months earlier was \MonthInRelationToCurrentMonth{-4}.\\
Five months earlier was \MonthInRelationToCurrentMonth{-5}.\\
Six months earlier was \MonthInRelationToCurrentMonth{-6}.\\
Seven months earlier was \MonthInRelationToCurrentMonth{-7}.\\
Eight months earlier was \MonthInRelationToCurrentMonth{-8}.\\
Nine months earlier was \MonthInRelationToCurrentMonth{-9}.\\
Ten months earlier was \MonthInRelationToCurrentMonth{-10}.\\
Eleven months earlier was \MonthInRelationToCurrentMonth{-11}.\\
Twelve months earlier was \MonthInRelationToCurrentMonth{-12}.\\
Thirteen months earlier was \MonthInRelationToCurrentMonth{-13}.\\
Twenty months earlier was \MonthInRelationToCurrentMonth{-20}.
\newpage
\selectlanguage{french}
\bigskip\hrule\bigskip
\noindent En français:
\bigskip\hrule\bigskip
\noindent
Aujourd'hui, c'est \today.\\
Le mois précédent était \PreviousMonth.\\
Ce mois-ci est \ThisMonth.\\
Le mois prochain sera \NextMonth.
\bigskip\hrule\bigskip
\noindent
Ce mois-ci, c'est \MonthInRelationToCurrentMonth{0}.\\
Ce mois-ci, c'est \MonthInRelationToCurrentMonth{+0}.\\
Un mois plus tard sera \MonthInRelationToCurrentMonth{+1}.\\
Deux mois plus tard sera \MonthInRelationToCurrentMonth{2}.\\
Trois mois plus tard sera \MonthInRelationToCurrentMonth{3}.\\
Quatre mois plus tard sera \MonthInRelationToCurrentMonth{4}.\\
Cinq mois plus tard sera \MonthInRelationToCurrentMonth{+5}.\\
Six mois plus tard sera \MonthInRelationToCurrentMonth{+6}.\\
Sept mois plus tard sera \MonthInRelationToCurrentMonth{7}.\\
Huit mois plus tard sera \MonthInRelationToCurrentMonth{8}.\\
Neuf mois plus tard sera \MonthInRelationToCurrentMonth{9}.\\
Dix mois plus tard plus tard sera \MonthInRelationToCurrentMonth{10}.\\
Onze mois plus tard plus tard sera \MonthInRelationToCurrentMonth{11}.\\
Douze mois plus tard plus tard sera \MonthInRelationToCurrentMonth{12}.\\
Treize mois plus tard plus tard sera \MonthInRelationToCurrentMonth{13}.\\
Vingte mois plus tard plus tard sera \MonthInRelationToCurrentMonth{+20}.
\bigskip\hrule\bigskip
\noindent
Ce mois-ci, c'est \MonthInRelationToCurrentMonth{0}.\\
Ce mois-ci, c'est \MonthInRelationToCurrentMonth{+0}.\\
Un mois plus tôt, c'était \MonthInRelationToCurrentMonth{-1}.\\
Deux mois plus tôt, c'était \MonthInRelationToCurrentMonth{-2}.\\
Trois mois plus tôt, c'était \MonthInRelationToCurrentMonth{-3}.\\
Quatre mois plus tôt, c'était \MonthInRelationToCurrentMonth{-4}.\\
Cinq mois plus tôt, c'était \MonthInRelationToCurrentMonth{-5}.\\
Six mois plus tôt, c'était \MonthInRelationToCurrentMonth{-6}.\\
Sept mois plus tôt, c'était \MonthInRelationToCurrentMonth{-7}.\\
Huit mois plus tôt, c'était \MonthInRelationToCurrentMonth{-8}.\\
Neuf mois plus tôt, c'était \MonthInRelationToCurrentMonth{-9}.\\
Dix mois plus tôt, c'était \MonthInRelationToCurrentMonth{-10}.\\
Onze mois plus tôt, c'était \MonthInRelationToCurrentMonth{-11}.\\
Douze mois plus tôt, c'était \MonthInRelationToCurrentMonth{-12}.\\
Teize mois plus tôt, c'était \MonthInRelationToCurrentMonth{-13}.\\
Vingte mois plus tôt, c'était \MonthInRelationToCurrentMonth{-20}.
\end{document}