Skip to content

Commit d4c0a4e

Browse files
committed
use \DeclareCiteCommand in kaobiblio
reference #68
1 parent 611d4c0 commit d4c0a4e

File tree

2 files changed

+60
-37
lines changed

2 files changed

+60
-37
lines changed

Diff for: CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog for package kaobook
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
Next release
6+
------------
7+
* Use \DeclareCiteCommand in kaobiblio.sty (fixes #68)
8+
59
0.9 (2020/12/02)
610
----------------
711
* First official release on GitHub

Diff for: styles/kaobiblio.sty

+56-37
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
% CITATION COMMANDS
9393
%----------------------------------------------------------------------------------------
9494

95+
% Command to format the marginnote created for cited items
96+
\NewDocumentCommand{\formatmargincitation}{m}{% The parameter is a single citation key
97+
\parencite{#1}: \citeauthor*{#1} (\citeyear{#1}), \citetitle{#1}%
98+
}
99+
100+
% The following command needs to be redefined every time \sidecite is called in order for \DeclareCiteCommand's wrapper to work correctly
101+
\NewDocumentCommand{\kaobiblio@marginnote}{m}{%
102+
\marginnote{#1}%
103+
}
104+
95105
% biblatex-like commands that also print a citation in the margin
96106
% Usage:
97107
% First optional argument is always vertical shift and must be given as an (empty) argument when using following a postnote and/or prenote
@@ -105,18 +115,26 @@
105115
% Third optional argument: postnote
106116
% Mandatory argument: citation key
107117
\NewDocumentCommand{\sidecite}{o o o m}{%
118+
\RenewDocumentCommand{\kaobiblio@marginnote}{m}{%
119+
\marginnote[#1]{##1}%
120+
}%
121+
\DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{%
122+
}{%
123+
\formatmargincitation{\thefield{entrykey}}%
124+
}{%
125+
\\% separator between multiple citations
126+
}{%
127+
}%
108128
% With this we print the marker in the text and add the item to the bibliography at the end
109-
\IfNoValueOrEmptyTF{#2}
110-
{\cite{#4}}
111-
{\IfNoValueOrEmptyTF{#3}
112-
{\IfNoValueTF{#3}
113-
{\cite[#2]{#4}}
114-
{\cite[#2][]{#4}}% postnote is empty, so pass empty postnote
115-
}
116-
{\cite[#2][#3]{#4}}%
129+
\IfNoValueOrEmptyTF{#2}%
130+
{\cite{#4}\kaobiblio@sidecite{#4}}%
131+
{\IfNoValueOrEmptyTF{#3}%
132+
{\IfNoValueTF{#3}%
133+
{\cite[#2]{#4}\kaobiblio@sidecite{#4}}%
134+
{\cite[#2][]{#4}\kaobook@sidecite{#4}}% postnote is empty, so pass empty postnote
135+
}%
136+
{\cite[#2][#3]{#4}\kaobiblio@sidecite{#4}}%
117137
}%
118-
\def\itemdelim{---}%
119-
\margincitation[#1]{#4}% We then pass the cited items to this command, \margincitation
120138
}
121139

122140
% Command to \textcite and print a citation in the margin
@@ -125,18 +143,26 @@
125143
% Third optional argument: postnote
126144
% Mandatory argument: citation key
127145
\NewDocumentCommand{\sidetextcite}{o o o m}{%
146+
\RenewDocumentCommand{\kaobiblio@marginnote}{m}{%
147+
\marginnote[#1]{##1}%
148+
}%
149+
\DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{%
150+
}{%
151+
\formatmargincitation{\thefield{entrykey}}%
152+
}{%
153+
\\% separator between multiple citations
154+
}{%
155+
}%
128156
% With this we print the marker in the text and add the item to the bibliography at the end
129-
\IfNoValueOrEmptyTF{#2}
130-
{\textcite{#4}}
131-
{\IfNoValueOrEmptyTF{#3}
132-
{\IfNoValueTF{#3}
133-
{\textcite[#2]{#4}}
134-
{\textcite[#2][]{#4}}% postnote is empty, so pass empty postnote
135-
}
136-
{\textcite[#2][#3]{#4}}%
157+
\IfNoValueOrEmptyTF{#2}%
158+
{\textcite{#4}\kaobiblio@sidecite{#4}}%
159+
{\IfNoValueOrEmptyTF{#3}%
160+
{\IfNoValueTF{#3}%
161+
{\textcite[#2]{#4}\kaobiblio@sidecite{#4}}%
162+
{\textcite[#2][]{#4}\kaobook@sidecite{#4}}% postnote is empty, so pass empty postnote
163+
}%
164+
{\textcite[#2][#3]{#4}\kaobiblio@sidecite{#4}}%
137165
}%
138-
\def\itemdelim{---}%
139-
\margincitation[#1]{#4}% We then pass the cited items to this command, \margincitation
140166
}
141167

142168
% Command to \parencite or \parencite* and print a citation in the margin
@@ -146,6 +172,16 @@
146172
% Fourth optional argument: postnote
147173
% Mandatory argument: citation key
148174
\NewDocumentCommand{\sideparencite}{s o o o m}{%
175+
\RenewDocumentCommand{\kaobiblio@marginnote}{m}{%
176+
\marginnote[#2]{##1}%
177+
}%
178+
\DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{%
179+
}{%
180+
\formatmargincitation{\thefield{entrykey}}%
181+
}{%
182+
\\% separator between multiple citations
183+
}{%
184+
}%
149185
% With this we print the marker in the text and add the item to the bibliography at the end
150186
\IfBooleanTF#1
151187
{\IfNoValueOrEmptyTF{#3}
@@ -168,25 +204,8 @@
168204
{\parencite[#3][#4]{#5}}%
169205
}%
170206
}%
171-
\def\itemdelim{---}%
172-
\margincitation[#2]{#5}% We then pass the cited items to this command, \margincitation
173-
}
174-
175-
176-
% Command to split the cited items and execute an action for each of them
177-
\newcommand\margincitedelim{\\} % Choose the default separator for multiple citations
178-
\NewDocumentCommand{\margincitation}{o >{\SplitList{,}}m}{% The mandatory parameter is a comma-separated list of citation keys, which is splitted into single items
179-
% Redefine the \margincitedelim with a delay (https://tex.stackexchange.com/questions/110898/package-xparse-splitlist-last-token). Users can 'renew' the \margincitedelim command in their main.tex.
180-
\let\origmargincitedelim\margincitedelim%
181-
\renewcommand\margincitedelim{\renewcommand\margincitedelim{\origmargincitedelim}}%
182-
\marginnote[#1]{\ProcessList{#2}{\formatmargincitation}}% Create a marginnote for each item
183-
\let\margincitedelim\origmargincitedelim% Reset
184207
}
185208

186-
% Command to format the marginnote created for cited items
187-
\NewDocumentCommand{\formatmargincitation}{m}{% The parameter is a single citation key
188-
\margincitedelim\parencite{#1}: \citeauthor*{#1} (\citeyear{#1}), \citetitle{#1}%
189-
}
190209

191210
%----------------------------------------------------------------------------------------
192211
% CITATION ENVIRONMENTS

0 commit comments

Comments
 (0)