私はisodate
パッケージを使用しています
- ユーザーは、次の例のような形式で、章のタイトルとして日付を挿入する必要があります。
31/12/1987
- この章のタイトルは
31st Dec 1987
、
ここでのいくつかの投稿に従って、私は次のことにたどり着きました:
\documentclass{book}
\usepackage[orig,british]{isodate}
\usepackage{blindtext}
\makeatletter
\def\short@month@english{\ifcase\month\or
Jan\or Feb\or Mar\or Apr\or May\or Jun\or
Jul\or Aug\or Sep\or Oct\or Nov\or Dec\fi}
\newcommand{\printshortdate}[1]{{%
\let\month@english\short@month@english% Update English month lookup (locally)
\printdate{#1}}}% Call traditional \printdate
\newcommand{\printsupdate}[1]{{
\let\day@english\supday@english
\printdate{#1}
}}
\makeatother
\newcommand{\chaplab}[1]{\label{chap:#1}}
\begin{document}
\chapter{\printshortdate{31/12/1987}}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\end{document}
しかし\markboth
、コマンドを削除して\blindtext
文書が1ページだけになると、すべて正常になりますが、テキストを追加するとエラーが発生し、ヘッダーの章名が混乱します。ヘッダーとして正確に表示したいのですが31st Dec 1987
メモを追加しました
isodate
同じ文書で同じ日付を別の形式で必要とし、ユーザーとしてはそれを一度だけ挿入したいので、これを使用しています。
答え1
モバイル引数を実行するには、コマンドが堅牢である必要があります。
コツはnewcommand
、DeclareRobustCommand
コードは次のとおりです:
\documentclass{book}
\usepackage[orig,british]{isodate}
\usepackage{lipsum}
\makeatletter
\def\short@month@english{\ifcase\month\or
Jan\or Feb\or Mar\or Apr\or May\or Jun\or
Jul\or Aug\or Sep\or Oct\or Nov\or Dec\fi}
\DeclareRobustCommand{\printshortdate}[1]{%
\let\month@english\short@month@english% Update English month lookup (locally)
\printdate{#1}%
}% Call traditional \printdate
\makeatother
\begin{document}
\chapter{\printshortdate{31/12/1987}}
\lipsum[4-12]
\end{document}
出力あり(2ページ目):
定義{
内の余分なsを削除したことに注意してください。newcommand
答え2
1章のみ使用する場合
\chapter*{\printshortdate{31/12/1987}}
目次に表示すべきでない場合、または
\chapter{\protect\printshortdate{31/12/1987}}
もちろん、これは他の答えの解決策と同じです。