Debian Codegraph @

texmf-dist/source/latex/scrjrnl/scrjrnl.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2012-2025 by Raphaël Pinson <[email protected]>
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained'.
14 %
15 % The Current Maintainer of this work is Raphaël Pinson.
16 %
17 % This work consists of the files scrjrnl.dtx and scrjrnl.ins
18 % and the derived filebase scrjrnl.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{scrjrnl.dtx}
25 %</driver>
26 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
27 %<package>\ProvidesClass{scrjrnl}
28 %<*package>
29 [2025/04/21 0.2 A class to typeset diaries or journals]
30 %</package>
31 %
32 %<*driver>
33 \documentclass{ltxdoc}
34 \usepackage[english]{babel}
35 \usepackage{fontspec}
36 \setmainfont{Linux Libertine O}
37 \usepackage{metalogo}
38 \usepackage[all]{nowidow}
39 \EnableCrossrefs
40 \CodelineIndex
41 \RecordChanges
42 \begin{document}
43 \DocInput{scrjrnl.dtx}
44 \PrintChanges
45 \PrintIndex
46 \end{document}
47 %</driver>
48 % \fi
49 %
50 % \CheckSum{361}
51 %
52 % \CharacterTable
53 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
54 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
55 % Digits \0\1\2\3\4\5\6\7\8\9
56 % Exclamation \! Double quote \" Hash (number) \#
57 % Dollar \$ Percent \% Ampersand \&
58 % Acute accent \' Left paren \( Right paren \)
59 % Asterisk \* Plus \+ Comma \,
60 % Minus \- Point \. Solidus \/
61 % Colon \: Semicolon \; Less than \<
62 % Equals \= Greater than \> Question mark \?
63 % Commercial at \@ Left bracket \[ Backslash \\
64 % Right bracket \] Circumflex \^ Underscore \_
65 % Grave accent \` Left brace \{ Vertical bar \|
66 % Right brace \} Tilde \~}
67 %
68 %
69 % \changes{0.2}{2025/04/21}{Fixes}
70 % \changes{0.1}{2012/09/16}{First version}
71 %
72 % \DoNotIndex{\newcommand,\newenvironment}
73 %
74 % \providecommand*{\url}{\texttt}
75 % \GetFileInfo{scrjrnl.dtx}
76 % \title{The \textsf{scrjrnl} class}
77 % \author{Raphaël Pinson \\ \url{[email protected]}}
78 % \date{\fileversion~from \filedate}
79 %
80 % \maketitle
81 %
82 % \section{Introduction}
83 %
84 % The \textsf{scrjrnl} class is based of the \textsf{scrbook} class,
85 % and inherits all of its commands and settings.
86 % Please refer to the Koma-Script documentation for the detail of
87 % all of these. Note that the \textsf{scrjrnl} class is not an
88 % official Koma-Script class.
89 %
90 % \section{Usage}
91 %
92 % \begin{verbatim}
93 % \documentclass[<options>]{scrjrnl}
94 % \end{verbatim}
95 %
96 % \subsection{Options}
97 %
98 % The class options are described below.
99 %
100 % \DescribeMacro{monthpages}
101 %
102 % By default, the month pages are skiped and only the days are typeset.
103 % If you wish to display a page for each starting month, use this setting.
104 %
105 % \DescribeMacro{fancytabs}
106 %
107 % This class can automatically make use of the \textsf{fancytabs} package
108 % to typeset tabs on the side of every odd page, with the name of the current month.
109 %
110 % \subsection{The \texttt{journal} environment}
111 %
112 % The \texttt{journal} environment is the main addition of this class.
113 % It provides an environment in which to typeset journal entries.
114 %
115 % The \texttt{journal} environment takes the following options:
116 %
117 % \DescribeMacro{startmonth}
118 %
119 % The month in which to start the journal. Defaults to 1.
120 %
121 % \DescribeMacro{startday}
122 %
123 % The day in which to start the journal. Defaults to 1.
124 %
125 % \subsection{Typesetting months}
126 %
127 % Once the \texttt{journal} environment in initiated, you can use
128 % the \texttt{jrnlmonth} and \texttt{jrnlday} commands
129 % to typeset journal entries.
130 %
131 % \DescribeMacro{\jrnlmonth}
132 %
133 % The \verb!\jrnlmonth! command starts a new month. It takes the following options:
134 %
135 % \DescribeMacro{month}
136 %
137 % Forces the current month instead of simply incrementing from the previous one. This parameter is an integer between 1 and 12.
138 %
139 % \DescribeMacro{startday}
140 %
141 % Start month at a given day, instead of 1.
142 %
143 % \subsection{Typesetting a journal entry}
144 %
145 % \DescribeMacro{\jrnlday}
146 %
147 % In order to typeset a single journal entry, use the \verb!\jrnlday! command. This command takes a mandatory argument which is the journal entry's title, as well as the following options:
148 %
149 % \DescribeMacro{day}
150 %
151 % Forces the current day instead of simply incrementing from the preivous one. This parameter is an integer.
152 %
153 % \DescribeMacro{ante}
154 %
155 % Add a text before the date.
156 %
157 % \DescribeMacro{post}
158 %
159 % Add a text after the date.
160 %
161 % \subsection{Index}
162 %
163 % When typesetting a journal, you might want to rely only on day entries
164 % to relate to pages and turn off completely page numbers by using
165 % an \texttt{empty} page style.
166 %
167 % In this situation, if you have to create an index, you might want index entries
168 % to link to dates in the journal rather than page numbers.
169 %
170 % The \textsf{scrjrnl} class records each typeset day in macros so they can be used to generate an index. The macros are named \verb!jrnldaydate\thejrnlday!, with the page day corresponding to the entry, numbered from the first typeset day in the journal.
171 %
172 % Below is an example of an index generated using the \textsf{bibleref} package, and linking to journal entries instead of pages:
173 %
174 % \begin{verbatim}
175 %% Index by day
176 %\renewcommand*{\bvidxpgformat}{transform}
177 %
178 %% Get the date for the recorded day
179 %\newcommand\getdaydate[1]{\csname jrnldaydate#1\endcsname}
180 %
181 %% Go through index items
182 %\newcommand{\transform}[1]{%
183 % \def\secondparam{0}%
184 % \forcsvlist\decodesec{#1}}
185 %\newcommand{\decodesec}[1]{%
186 % \ifthenelse{\secondparam=1}{, }{}%
187 % \mbox{\textsc{\getdaydate{#1}}}
188 % \def\secondparam{1}}
189 %
190 %% Patch imakeidx to map journal entry instead of page
191 %\makeatletter
192 %\patchcmd{\@index}{\@wrindex}{\@Wrindex}{}{}
193 %\let\@Wrindex\@wrindex
194 %\patchcmd{\@Wrindex}{\thepage}{\thejrnltotalday}{}{}
195 %\let\protected@iwrite\protected@write
196 %\patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
197 %\patchcmd{\@Wrindex}{\protected@write}{\protected@iwrite}{}{}
198 %\makeatother
199 % \end{verbatim}
200 %
201 % \StopEventually{}
202 %
203 % \section{Implementation}
204 %
205 % \iffalse
206 %<*package>
207 % \fi
208 %
209 % \begin{macrocode}
210 \ProvidesClass{scrjrnl}
211 \DeclareOption{scrartcl}{\def\jrnl@class{scrartcl}}
212 \DeclareOption{scrreprt}{\def\jrnl@class{scrreprt}}
213 \DeclareOption{scrbook}{\def\jrnl@class{scrbook}}
214 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\jrnl@class}}
215 \ExecuteOptions{scrbook}
216 \newif\if@jrnl@monthpages
217 \DeclareOption{monthpages}{\@jrnl@monthpagestrue}
218 \newif\if@jrnl@fancytabs
219 \DeclareOption{fancytabs}{\@jrnl@fancytabstrue}
220 \newif\if@jrnl@cleardaypages
221 \DeclareOption{cleardaypages}{\@jrnl@cleardaypagestrue}
222 \ProcessOptions\relax
223 \LoadClass{\jrnl@class}
224 \RequirePackage{titlesec}
225 % \end{macrocode}
226 %
227 % \marginpar{Load datetime after babel}
228 %
229 % \begin{macrocode}
230 \AfterPackage{babel}{\RequirePackage{datetime}}
231 \newcommand\jrnlformatdate\formatdateny
232 \newcommand\jrnlformatindexdate\formatdateny
233 % \end{macrocode}
234 %
235 % \marginpar{More datetime}
236 %
237 % \begin{macrocode}
238 % formatdate without year
239 \def\formatdateny{\csname noyear\languagename\expandafter\endcsname\formatdate}
240
241 \def\noyearenglish#1, \the\@year{#1}
242 \let\noyearamerican\noyearenglish
243 \let\noyearbritish\noyearenglish
244 \def\noyearfrench#1\space\number\@year{#1}
245 \let\noyeargerman\noyearfrench
246 \let\noyearaustrian\noyeargerman
247 \let\noyearswedish\noyearfrench
248 \let\noyearbreton\noyearfrench
249 \def\noyearrussian#1\ \number\@year~\cyrg.{#1}
250 \def\noyearspanish#1\ de~\number\@year{#1}
251 \let\noyearcatalan\noyearspanish
252 \def\noyearbasque#1\number\@year.eko\space{#1}
253 % \end{macrocode}
254 %
255 % \marginpar{Set default lengths}
256 %
257 % \begin{macrocode}
258 \newlength{\jrnldaysepskip}
259 \setlength{\jrnldaysepskip}{0pt}
260 \newlength{\jrnldayafterskip}
261 \setlength{\jrnldayafterskip}{2\baselineskip}
262 % \end{macrocode}
263 %
264 % \marginpar{Load fancytabs}
265 %
266 % \begin{macrocode}
267 %%\if@jrnl@fancytabs
268 \RequirePackage{fancytabs}[2012/09/24]
269 %%\fi
270 % \end{macrocode}
271 %
272 % \marginpar{Month names}
273 %
274 % \begin{macrocode}
275 \newcommand{\jrnl@monthname}[1]{\monthname[#1]}
276 \newcommand{\jrnl@curmonth}{\jrnl@monthname{\thejrnlmonth}}
277 % \end{macrocode}
278 %
279 % \marginpar{Setup counters}
280 %
281 % \begin{macrocode}
282 \newcounter{jrnlstartchapter}
283 \newcounter{jrnlday}
284 \newcounter{jrnlmonth}
285 \newcounter{jrnlyear}
286 \newcounter{jrnltotalday}
287 % \end{macrocode}
288 %
289 % \marginpar{HTML hooks for TeX4HT}
290 %
291 % \begin{macrocode}
292 \newcommand{\HTMLchapHook}[1]{}
293 \newcommand{\HTMLsecHook}[2]{}
294 % \end{macrocode}
295 %
296 % \marginpar{Define jrnlmonth}
297 %
298 % \begin{macrocode}
299 \newcounter{jrnlmonthstartday}
300 \define@key{jrnlmonth}{month}{\setcounter{jrnlmonth}{#1}\addtocounter{jrnlmonth}{-1}}
301 \define@key{jrnlmonth}{startday}{\setcounter{jrnlmonthstartday}{#1}\addtocounter{jrnlmonthstartday}{-1}}
302
303 \newcommand{\jrnlmonth}[1][]{%
304 % Use \thejrnlstatday if first month of journal
305 \setcounter{jrnlmonthstartday}{\thejrnlstartday}%
306 \setcounter{jrnlstartday}{0}%
307 \setkeys{jrnlmonth}{#1}%
308 \stepcounter{jrnlmonth}%
309 \HTMLchapHook{\jrnl@curmonth}%
310 \if@jrnl@monthpages
311 \chapter{\jrnl@curmonth}%
312 \cleardoublepage%
313 \else
314 \refstepcounter{chapter}%
315 \@maybeautodot\thechapter
316 \addchaptertocentry{\thechapter}{\jrnl@curmonth}%
317 \fi
318 \setcounter{jrnlday}{\thejrnlmonthstartday}%
319 }
320 % \end{macrocode}
321 %
322 %
323 % \marginpar{Define jrnlday}
324 %
325 % \begin{macrocode}
326 \newcommand{\jrnl@pagedate}{%
327 \jrnlformatdate{\thejrnlday}{\thejrnlmonth}{\thejrnlyear}%
328 }
329 \define@key{jrnlday}{day}{\setcounter{jrnlday}{#1}\addtocounter{jrnlday}{-1}}
330 \define@key{jrnlday}{ante}{\def\jrnlday@ante{#1}}
331 \define@key{jrnlday}{post}{\def\jrnlday@post{#1}}
332
333 \newcommand{\jrnlday}[2][]{%
334 \def\jrnlday@ante{}%
335 \def\jrnlday@post{}%
336 \setkeys{jrnlday}{#1}%
337 \stepcounter{jrnlday}%
338 \stepcounter{jrnltotalday}%
339 \if@jrnl@cleardaypages
340 \if@openright\cleardoublepage\else\clearpage\fi
341 \fi
342 \newpage\section{#2}%
343 % TODO: provide index macros to be used with jrnlpagedate\thepage
344 \expandafter\xdef\csname jrnldaydate\thejrnltotalday\endcsname{%
345 \jrnlday@ante\noexpand\jrnlformatindexdate{\thejrnlday}{\thejrnlmonth}{\thejrnlyear}\jrnlday@post%
346 }%
347 \HTMLsecHook{\jrnlday@ante\jrnlformatdate{\thejrnlday}{\thejrnlmonth}{\thejrnlyear}\jrnlday@post}{#2}%
348 }
349 % \end{macrocode}
350 %
351 %
352 % \marginpar{Define fonts}
353 %
354 % \begin{macrocode}
355 \newcommand\dayheadfont{}
356 \newcommand\monthheadfont{}
357 % \end{macrocode}
358 %
359 %
360 % \marginpar{Chapter/section styles}
361 %
362 % \begin{macrocode}
363 \newcommand\jrnl@titlestrut{\vrule height 25pt width0pt\relax}
364 \newcommand{\jrnl@secstyle}{\filcenter\dayheadfont\huge}
365 \newcommand{\jrnl@seclblstyle}{\raggedright\normalfont\scshape\Large}
366 \newcommand{\jrnl@seclbl}{\jrnl@seclblstyle\jrnlday@ante\jrnl@pagedate\jrnlday@post\\}
367
368 \newcommand{\jrnl@chapstyle}{\filcenter\monthheadfont\Huge\textsc}
369 % \end{macrocode}
370 %
371 %
372 % \marginpar{Define journal environment}
373 %
374 % \begin{macrocode}
375 \newcounter{jrnlstartmonth}
376 \newcounter{jrnlstartday}
377 \define@key{jrnl}{startmonth}{\setcounter{jrnlstartmonth}{#1}\addtocounter{jrnlstartmonth}{-1}}
378 \define@key{jrnl}{startday}{\setcounter{jrnlstartday}{#1}\addtocounter{jrnlstartday}{-1}}
379 \newlength{\jrnl@bleed}
380 \define@key{jrnl}{bleed}{\setlength{\jrnl@bleed}{#1}}
381
382 \newenvironment{journal}[1][]%
383 {%
384 \setcounter{jrnlstartmonth}{0}%
385 \setcounter{jrnlstartday}{0}%
386 \setkeys{jrnl}{#1}%
387 \setcounter{jrnlstartchapter}{\thechapter}
388 \addtocounter{jrnlmonth}{\thejrnlstartmonth}
389
390 \titleformat{\chapter}[block]
391 {\vfill}
392 {}{0pt}
393 {\jrnl@chapstyle}
394 [\vfill\vfill]
395
396 \if@jrnl@fancytabs
397 % We know \paperheight and bleed
398 % Calculation base:
399 % 6*fancytabsHeight+2*fancytabsTop+5*fancytabsGap = paperheight
400 % fancytabsHeight = 10*fancytabsGap
401 % fancytabsTop = 5*fancytabsGap + 2*bleed
402
403 % Calculate \calcfancytabsGap as (\the\paperheight-2*bleed)/75
404 \newlength{\calcfancytabsGap}
405 \pgfmathsetlength{\calcfancytabsGap}{\the\paperheight-2*\the\jrnl@bleed)/75}
406 \fancytabsGap{\the\calcfancytabsGap}
407
408 % Calculate \calcfancytabsHeight as 10*\calcfancytabsGap
409 \newlength{\calcfancytabsHeight}
410 \pgfmathsetlength{\calcfancytabsHeight}{10*\calcfancytabsGap}
411 \fancytabsHeight{\the\calcfancytabsHeight}
412
413 % Calculate \calcfancytabsTop as (5*\calcfancytabsGap+2\jrnl@bleed)
414 \newlength{\calcfancytabsTop}
415 \pgfmathsetlength{\calcfancytabsTop}{5*\calcfancytabsGap+2*\the\jrnl@bleed}
416 \fancytabsTop{\the\calcfancytabsTop}
417
418 % Calculate \fancytabsWidth, without bleed
419 \newlength{\calcfancytabsWidth}
420 \pgfmathsetlength{\calcfancytabsWidth}{\the\paperwidth/12}
421
422 % Calculate \fancytabsWidthBleed, with bleed
423 \newlength{\calcfancytabsWidthBleed}
424 \pgfmathsetlength{\calcfancytabsWidthBleed}{\the\calcfancytabsWidth+\the\jrnl@bleed}
425 \fancytabsWidth{\the\calcfancytabsWidthBleed}
426
427 \fancytabsTextVPos{0.5}
428 % Put text more inside
429 % \fancytabsTextHPos = (\fancytabsWidth/2)/\fancytabsWidthBleed
430 \pgfmathsetmacro{\calcfancytabsTextHPos}{(\the\calcfancytabsWidth/2)/(\the\calcfancytabsWidthBleed)}
431 \fancytabsTextHPos{\calcfancytabsTextHPos}
432
433 \newcommand{\jrnl@fancytab}{%
434 \ifthenelse{\isodd{\thepage}}%
435 {\fancytab{\jrnl@curmonth}{\thejrnlmonth}}%
436 {}%
437 }
438 \else
439 \newcommand{\jrnl@fancytab}{}%
440 \fi
441
442 \titleformat{\section}[display]
443 {\jrnl@secstyle} % format
444 {\jrnl@seclbl} % label
445 {\jrnldaysepskip} %sep
446 {\jrnl@fancytab%
447 \jrnl@titlestrut\filcenter} %before
448 [\vspace{\jrnldayafterskip}] %after
449
450 \titlespacing{\section}{0pt}{*}{-3pt}
451
452 } % end of \begin{devotional}
453 {} % end of \end{devotional}
454 % \end{macrocode}
455 %
456 % \iffalse
457 %</package>
458 % \fi
459 %
460 % \Finale
461 \endinput