標記兩者的問題

標記兩者的問題

isodate從那時起就使用包

  1. 使用者應按照範例中的格式插入日期作為章節標題:31/12/1987
  2. 該章應該有標題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命令,因此文檔只有一頁,一切正常,在添加文字時,我會收到錯誤,標題中的章節名稱一團糟。我想完全作為標題31st Dec 1987

新增註釋

我正在使用,isodate因為在同一個文件中我需要相同的日期但採用其他格式,並且作為用戶我只想插入一次。

答案1

您的命令必須強大才能進行移動參數。

訣竅是替換newcommandDeclareRobustCommand

這是代碼:

\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

如果您只需要一章使用

\chapter*{\printshortdate{31/12/1987}}

如果它不應該出現在目錄中,或者

\chapter{\protect\printshortdate{31/12/1987}}  

當然,這與另一個答案的解決方案相同。

相關內容