| 1 |
% arara: pdflatex |
| 2 |
% arara: pdflatex |
| 3 |
\documentclass{memoir} |
| 4 |
|
| 5 |
\usepackage[en-GB,showdow]{datetime2} |
| 6 |
|
| 7 |
\usepackage{lipsum}% dummy text |
| 8 |
\usepackage[hidelinks]{hyperref} |
| 9 |
|
| 10 |
\newcommand*{\numdash}{\texorpdfstring{\,--\,}{--}} |
| 11 |
|
| 12 |
% \DTMmonthname is robust and can't be used in the bookmarks |
| 13 |
% or headings so use \DTMenglishmonthname since this |
| 14 |
% document is in English. |
| 15 |
\newcommand*{\entrymonth}[2]{\DTMenglishmonthname{#2} #1} |
| 16 |
|
| 17 |
% A range of dates. |
| 18 |
% Syntax: \daterange{yyyy1}{mm1}{dd1}{yyyy2}{mm2}{dd2} |
| 19 |
\newcommand*{\daterange}[6]{% |
| 20 |
\ifnum#1=#4 |
| 21 |
% Same year |
| 22 |
\ifnum#2=#5 |
| 23 |
% Same month |
| 24 |
\ifnum#3=#6 |
| 25 |
% Same day - not a range! |
| 26 |
\DTMdisplaydate{#1}{#2}{#3}% |
| 27 |
\else |
| 28 |
% Range within the same month. |
| 29 |
% This needs to be done explicitly but match the separators |
| 30 |
% with the en-GB style. |
| 31 |
\DTMenglishordinal{#3}\numdash\DTMenglishordinal{#6}% |
| 32 |
\DTMenGBdaymonthsep |
| 33 |
\DTMenglishmonthname{#2}% |
| 34 |
\DTMenGBmonthyearsep\number#1 |
| 35 |
\fi |
| 36 |
\else |
| 37 |
% Not the same month |
| 38 |
\DTMdisplaydate{#1}{#2}{#3}{-1}\numdash\DTMdisplaydate{#4}{#5}{#6}{-1}% |
| 39 |
\fi |
| 40 |
\else |
| 41 |
% Not same year |
| 42 |
\DTMdisplaydate{#1}{#2}{#3}{-1}\numdash\DTMdisplaydate{#4}{#5}{#6}{-1}% |
| 43 |
\fi |
| 44 |
} |
| 45 |
|
| 46 |
% range of months |
| 47 |
% Syntax: \monthspan{yyyy1}{mm1}{yyyy2}{mm2} |
| 48 |
\newcommand*{\monthspan}[4]{% |
| 49 |
\ifnum#1=#3 |
| 50 |
% Same year |
| 51 |
\DTMenglishmonthname{#2}\numdash\DTMenglishmonthname{#4}% |
| 52 |
\DTMenGBmonthyearsep\number#1 |
| 53 |
\else |
| 54 |
% Not the same year |
| 55 |
\DTMenglishmonthname{#2}% |
| 56 |
\DTMenGBmonthyearsep\number#1 |
| 57 |
\numdash\DTMenglishmonthname{#4}% |
| 58 |
\DTMenGBmonthyearsep\number#3 |
| 59 |
\fi |
| 60 |
} |
| 61 |
|
| 62 |
\newcommand*{\entrydate}[3]{\DTMdisplaydate{#1}{#2}{#3}{-1}} |
| 63 |
\newcommand*{\titleentrydate}[3]{\DTMdate{#1-#2-#3}} |
| 64 |
|
| 65 |
\renewcommand*{\printchaptertitle}[1]{% |
| 66 |
{% |
| 67 |
\let\entrydate\titleentrydate |
| 68 |
\chaptitlefont{#1}% |
| 69 |
}% |
| 70 |
} |
| 71 |
|
| 72 |
\setsecheadstyle{\let\entrydate\titleentrydate |
| 73 |
\Large\bfseries\memRTLraggedright} |
| 74 |
|
| 75 |
\begin{document} |
| 76 |
|
| 77 |
\frontmatter |
| 78 |
\tableofcontents |
| 79 |
|
| 80 |
\mainmatter |
| 81 |
\chapter{Introduction} |
| 82 |
|
| 83 |
This is a test document that illustrates the use of dates within |
| 84 |
chapter titles. |
| 85 |
|
| 86 |
\section{Sample} |
| 87 |
|
| 88 |
An example section. |
| 89 |
|
| 90 |
\chapter{\entrymonth{2016}{01}} |
| 91 |
|
| 92 |
\lipsum |
| 93 |
|
| 94 |
\section{\entrydate{2016}{01}{01}} |
| 95 |
|
| 96 |
\lipsum[1-10] |
| 97 |
|
| 98 |
\section{\entrydate{2016}{01}{02}} |
| 99 |
|
| 100 |
\lipsum |
| 101 |
|
| 102 |
\section{\daterange{2016}{01}{04}{2016}{01}{12}} |
| 103 |
|
| 104 |
\lipsum[1-3] |
| 105 |
|
| 106 |
\chapter{\entrydate{2016}{02}{03}} |
| 107 |
|
| 108 |
\lipsum |
| 109 |
|
| 110 |
\chapter{\monthspan{2016}{02}{2016}{03}} |
| 111 |
|
| 112 |
\lipsum |
| 113 |
|
| 114 |
\section{\daterange{2016}{02}{04}{2016}{03}{01}} |
| 115 |
|
| 116 |
\lipsum |
| 117 |
|
| 118 |
\chapter{\monthspan{2015}{12}{2016}{01}} |
| 119 |
|
| 120 |
\lipsum |
| 121 |
|
| 122 |
\section{\daterange{2015}{12}{20}{2016}{01}{01}} |
| 123 |
|
| 124 |
\lipsum |
| 125 |
|
| 126 |
|
| 127 |
\end{document} |